API Reference¶
API reference for world:
- class world.database.Database¶
Database of country codes to top-level domain names.
- find_matches(text: str) list[tuple[str, str]]¶
Find all reverse matches of a given text.
textcan be any Python regular expression. This is matched against every value (i.e. country name, not code) in the database. Every match is returned as a list of 2-tuples where the first element is the country code and the second element is the country name.- Parameters:
text – Regular expression to match against.
- Returns:
The list of matching 2-tuples, of the form (code, name).
- lookup_code(domain: str) str | None¶
Given a top-level country code, return the country if possible.
- Parameters:
domain – The country code to look up. The code is case insensitive.
- Returns:
The country name matching the given code. If the given code does not match any entries in the database, None is returned.