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 BasicsBefore 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.
Note
The method described below is the same for all available checkers.
Let's say we want to test the availability of the domain github.com
.
We first have to select and prepare the checker.
from PyFunceble import from PyFunceble import Domain
checker = DomainAvailabilityChecker()
We then declare the subject that we want to test:
from PyFunceble import from PyFunceble import Domain
checker = DomainAvailabilityChecker()
checker.set_subject("github.com")
# This is the same.
checker.subject = "github.com"
Now, we trigger the query of the status:
from PyFunceble import from PyFunceble import Domain
checker = 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.
from PyFunceble import from PyFunceble import Domain
checker = 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:
from PyFunceble import from PyFunceble import Domain
checker = 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.
from PyFunceble import from PyFunceble import Domain
checker = 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" if status.is_active() else "no")
# Is it inactive ?
print("Is GitHub inactive ?", "yes" if status.is_inactive() else "no")
# Is it invalid ?
print("Is github.com invalid ?", "yes" if status.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.
September 21, 2024 September 21, 2024RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4