PyFunceble has an internal API that can be used for you own logic. Before PyFunceble
v4.0.0, the internal API was extremely tight to the CLI. Therefore it has
been hard for developers to reuse PyFunceble as part of their program because
there was a lot to activate or deactivate to get things started.
Since PyFunceble v4.0.0, it is possible to use the internel checkers without
any initial configuration or initialization of any sort.
In other words: Simply choose your checker, interact with it and get what you are looking for!
The Basics
Before starting to play with any checkers,
let me explain some basics.
To get started, you mostly need to understand the following classes:
The first one is the base class of all checkers, and the second one is the base of
all status you get from any checker when you call the .get_status() method.
Interacting with checkers
Note
The method described below is the same for all available checkers.
Let's say we want to test the availability of the domaingithub.com.
fromPyFuncebleimportfromPyFuncebleimportDomainchecker=DomainAvailabilityChecker()checker.set_subject("github.com")# This is the same.checker.subject="github.com"
fromPyFuncebleimportfromPyFuncebleimportDomainchecker=DomainAvailabilityChecker()checker.set_subject("github.com")# This is the same.checker.subject="github.com"status=checker.get_status()
Once we have the status, we can print the dict() or JSON representation.
fromPyFuncebleimportfromPyFuncebleimportDomainchecker=DomainAvailabilityChecker()checker.set_subject("github.com")# This is the same.checker.subject="github.com"status=checker.get_status()print("DICT REPRESENTATION")print(status.to_dict())print("-"*80)print("JSON REPRESENTATION")print(status.to_json())print("-"*80)
We can also interact with any of the attributes of the status object:
fromPyFuncebleimportfromPyFuncebleimportDomainchecker=DomainAvailabilityChecker()checker.set_subject("github.com")# This is the same.checker.subject="github.com"status=checker.get_status()print("DICT REPRESENTATION")print(status.to_dict())print("-"*80)print("JSON REPRESENTATION")print(status.to_json())print("-"*80)print(f"{status.idna_subject} is {status.status}")
Finally, and probably most importantly, we can ask questions.
Note
Each checker has its own set of method. Be sure the read them or follow the
autocomplete of your favorite editor.
fromPyFuncebleimportfromPyFuncebleimportDomainchecker=DomainAvailabilityChecker()checker.set_subject("github.com")# This is the same.checker.subject="github.com"status=checker.get_status()print("DICT REPRESENTATION")print(status.to_dict())print("-"*80)print("JSON REPRESENTATION")print(status.to_json())print("-"*80)print(f"{status.idna_subject} is {status.status}")# Is it active ?print("Is GitHub active ?","yes"ifstatus.is_active()else"no")# Is it inactive ?print("Is GitHub inactive ?","yes"ifstatus.is_inactive()else"no")# Is it invalid ?print("Is github.com invalid ?","yes"ifstatus.is_invalid()else"no")
That's it, you went through the basic. Feel free to discover other checkers or
ask questions if something is not clear.