### Install PublicSuffix2 via pip Source: https://context7.com/aboutcode-org/python-publicsuffix2/llms.txt The standard command to install the publicsuffix2 package from the Python Package Index (PyPI). ```bash pip install publicsuffix2 ``` -------------------------------- ### Updating Suffix List via CLI Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Command to update the bundled public suffix list data file using the library's setup script. ```bash python setup.py update_psl ``` -------------------------------- ### Update Bundled Public Suffix List Data Source: https://context7.com/aboutcode-org/python-publicsuffix2/llms.txt Instructions on how to update the vendored Public Suffix List data file within the library using the provided setup script. This ensures that the library uses the most current list for accurate domain parsing. ```bash # Update the bundled PSL data file python setup.py update_psl # The updated list is saved to src/publicsuffix2/public_suffix_list.dat # Build a new wheel with updated data python setup.py bdist_wheel ``` -------------------------------- ### Get Registrable Domain using get_sld() Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Illustrates the use of the `get_sld` function, which is equivalent to `get_public_suffix` and returns the registrable domain (second-level domain) of a given domain name. It handles various domain structures and multi-part TLDs. ```python from publicsuffix2 import get_sld # Get the registrable domain (SLD) for a domain print(get_sld('www.example.com')) # Output: example.com # Get the registrable domain for a domain with a multi-part TLD print(get_sld('www.example.co.uk')) # Output: example.co.uk # Get the registrable domain for a deeply nested domain print(get_sld('www.super.example.co.uk')) # Output: example.co.uk ``` -------------------------------- ### Get Public Suffix using get_public_suffix() Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Demonstrates how to use the `get_public_suffix` function to retrieve the public suffix of a given domain name. This function caches the public suffix list for efficiency. It can also accept a custom PSL file path. ```python from publicsuffix2 import get_public_suffix # Get public suffix for a standard domain print(get_public_suffix('www.example.com')) # Output: example.com # Get public suffix for a domain with a multi-part TLD print(get_public_suffix('www.example.co.uk')) # Output: example.co.uk # Get public suffix for a subdomain of a multi-part TLD print(get_public_suffix('www.super.example.co.uk')) # Output: example.co.uk # Get the effective TLD (eTLD) itself if it's a public suffix print(get_sld("co.uk")) # Output: co.uk # Using a custom PSL file psl_file = 'path/to/your/custom/psl.dat' print(get_public_suffix('www.example.com', psl_file)) # Output: example.com ``` -------------------------------- ### Updating the Bundled Suffix List Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Provides instructions on how to update the bundled public suffix list using the `setup.py` command or the `fetch()` function. ```APIDOC ## Updating the Bundled Suffix List ### Description There are two primary methods to update the public suffix list data used by the library: using a `setup.py` command or by fetching the latest list directly. ### Method 1. `python setup.py update_psl` 2. `fetch()` function ### Endpoint N/A (Command line / Library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example **Using setup.py:** ```bash python setup.py update_psl ``` **Using fetch() function:** ```python from publicsuffix2 import get_public_suffix, fetch psl_file = fetch() print(get_public_suffix('www.example.com', psl_file)) ``` ### Response #### Success Response - **setup.py**: The bundled suffix list in `src/publicsuffix2/public_suffix_list.dat` is updated, and a new wheel can be built. - **fetch()**: Returns the content of the latest public suffix data file, which can be passed to `get_public_suffix()`. #### Response Example ``` 'example.com' ``` ``` -------------------------------- ### Configuring IDNA Encoding and Strict Validation Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Shows how to initialize the PublicSuffixList with specific parameters. Use idna=False for UTF-8 domains and strict=True to return None for invalid TLDs. ```python from publicsuffix2 import PublicSuffixList # UTF-8 mode psl = PublicSuffixList(idna=False) print(psl.get_public_suffix('食狮.com.cn')) # Strict mode print(psl.get_public_suffix('www.mine.local', strict=True)) ``` -------------------------------- ### Handle IDNA and UTF-8 Domain Names Source: https://context7.com/aboutcode-org/python-publicsuffix2/llms.txt Demonstrates how to process internationalized domain names using either IDNA (Punycode) or UTF-8 encoding modes. ```python from publicsuffix2 import PublicSuffixList # IDNA mode for Punycode psl_idna = PublicSuffixList(idna=True) result = psl_idna.get_sld('xn--85x722f.com.cn') # UTF-8 mode for international characters psl_utf8 = PublicSuffixList(idna=False) result = psl_utf8.get_sld('食狮.com.cn') ``` -------------------------------- ### Advanced Domain Parsing with PublicSuffixList Class Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Shows how to use the `PublicSuffixList` class for more granular control over public suffix operations. This class parses the PSL and allows querying individual domain names, offering the same functionality as the standalone functions. ```python from publicsuffix2 import PublicSuffixList # Instantiate the PublicSuffixList class psl = PublicSuffixList() # Get the public suffix using the class instance print(psl.get_public_suffix('www.example.com')) # Output: example.com # Get the public suffix for a domain with a multi-part TLD print(psl.get_public_suffix('www.example.co.uk')) # Output: example.co.uk # Get the public suffix for a deeply nested domain print(psl.get_public_suffix('www.super.example.co.uk')) # Output: example.co.uk # Get the registrable domain (SLD) using the class instance print(psl.get_sld('www.super.example.co.uk')) # Output: example.co.uk ``` -------------------------------- ### Managing Wildcards and Fetching External Lists Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Explains how to toggle wildcard processing for aggregation and how to fetch the latest suffix list from the official Mozilla source. ```python from publicsuffix2 import get_public_suffix, fetch # Ignore wildcards psl.get_public_suffix('telinet.com.pg', wildcard=False) # Fetch latest list psl_file = fetch() get_public_suffix('www.example.com', psl_file) ``` -------------------------------- ### Extracting Registrable Domains and eTLDs Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Demonstrates how to retrieve the base domain using get_public_suffix() and the effective Top-Level Domain (eTLD) using get_tld(). These methods help identify the registrable part of a domain string. ```python from publicsuffix2 import get_public_suffix, PublicSuffixList psl = PublicSuffixList() # Get registrable domain print(get_public_suffix('www.example.co.uk')) # Get eTLD only print(psl.get_tld('www.google.com')) ``` -------------------------------- ### Public Suffix List Module Usage Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Demonstrates basic usage of the publicsuffix2 module for obtaining public suffixes and second-level domains. ```APIDOC ## Basic Usage of publicsuffix2 ### Description This section covers the fundamental functions provided by the `publicsuffix2` module to extract public suffixes and second-level domains (SLDs) from fully qualified domain names (FQDNs). ### Method `get_public_suffix(domain, psl_file=None)` `get_sld(domain, psl_file=None)` ### Endpoint N/A (Python module functions) ### Parameters #### Query Parameters - **domain** (string) - Required - The fully qualified domain name to process. - **psl_file** (string, iterable, or file-like object) - Optional - Path to a custom Public Suffix List file, an iterable of lines, or a file-like object. ### Request Example ```python from publicsuffix2 import get_public_suffix, get_sld # Get the public suffix print(get_public_suffix('www.example.com')) # Expected output: 'example.com' print(get_public_suffix('www.example.co.uk')) # Expected output: 'example.co.uk' print(get_public_suffix('www.super.example.co.uk')) # Expected output: 'example.co.uk' # Get the second-level domain (SLD) print(get_sld('www.example.com')) # Expected output: 'example.com' # Handling TLDs that are also public suffixes print(get_sld("co.uk")) # Expected output: 'co.uk' ``` ### Response #### Success Response (string) - Returns the public suffix or SLD of the provided domain name. #### Response Example ``` example.com ``` ## PublicSuffixList Class Usage ### Description This section details the usage of the `PublicSuffixList` class, which offers more granular control over Public Suffix List parsing and querying. ### Method `PublicSuffixList(psl_file=None)` `psl.get_public_suffix(domain)` `psl.get_sld(domain)` ### Endpoint N/A (Python class methods) ### Parameters #### Initialization Parameters - **psl_file** (string, iterable, or file-like object) - Optional - Path to a custom Public Suffix List file, an iterable of lines, or a file-like object. #### Instance Methods Parameters - **domain** (string) - Required - The fully qualified domain name to process. ### Request Example ```python from publicsuffix2 import PublicSuffixList psl = PublicSuffixList() # Get the public suffix using the class instance print(psl.get_public_suffix('www.example.com')) # Expected output: 'example.com' print(psl.get_public_suffix('www.example.co.uk')) # Expected output: 'example.co.uk' print(psl.get_public_suffix('www.super.example.co.uk')) # Expected output: 'example.co.uk' # Get the second-level domain (SLD) using the class instance print(psl.get_sld('www.super.example.co.uk')) # Expected output: 'example.co.uk' ``` ### Response #### Success Response (string) - Returns the public suffix or SLD of the provided domain name. #### Response Example ``` example.com ``` ## Handling IDNA-encoded Domains ### Description Explains how to handle Internationalized Domain Names (IDNs) by managing the IDNA encoding flag, crucial for domains with Unicode characters. ### Method `PublicSuffixList(idna_encoding=True)` `get_public_suffix(domain, idna_encoding=True)` ### Endpoint N/A (Python module/class parameters) ### Parameters #### Initialization/Function Parameters - **idna_encoding** (boolean) - Optional (default: True) - Set to `False` to disable IDNA encoding for processing UTF-8 domains. Set to `True` to enable IDNA encoding. ### Request Example ```python from publicsuffix2 import PublicSuffixList # Example with IDNA encoding enabled (default) psl_default = PublicSuffixList() print(psl_default.get_public_suffix('www.食狮.com.cn')) # Example with IDNA encoding disabled for UTF-8 domains psl_utf8 = PublicSuffixList(idna_encoding=False) print(psl_utf8.get_public_suffix('www.食狮.com.cn')) # Expected output for UTF-8 processing: '食狮.com.cn' ``` ### Response #### Success Response (string) - Returns the processed public suffix, correctly handling IDNA encoding based on the flag. #### Response Example ``` 食狮.com.cn ``` ``` -------------------------------- ### Use PublicSuffixList Class for Advanced Parsing Source: https://context7.com/aboutcode-org/python-publicsuffix2/llms.txt Provides a class-based interface for efficient, reusable PSL parsing. Allows initialization from custom files or lists of rules. ```python from publicsuffix2 import PublicSuffixList # Initialize with default bundled PSL psl = PublicSuffixList() # Initialize from list of rules custom_rules = ['com', 'co.uk', '*.example.com', '!www.example.com'] psl_rules = PublicSuffixList(custom_rules) print(psl_rules.get_sld('test.foo.example.com')) ``` -------------------------------- ### IDNA Encoding Handling Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Explains how to handle IDNA-encoded domains by configuring the `idna` parameter during PublicSuffixList initialization. ```APIDOC ## IDNA Encoding Handling ### Description The public suffix list is in UTF-8 format. For IDNA-encoded domains, the list must be converted. The `publicsuffix2` library includes an `idna` parameter in the `PublicSuffixList` constructor, which is `True` by default. Set `idna=False` for UTF-8 use cases. ### Method `PublicSuffixList(idna=True/False)` ### Endpoint N/A (Library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from publicsuffix2 import PublicSuffixList # With IDNA encoding (default) psl_idna = PublicSuffixList(idna=True) print(psl_idna.get_public_suffix('www.google.com')) # Without IDNA encoding (UTF-8) psl_utf8 = PublicSuffixList(idna=False) print(psl_utf8.get_public_suffix('食狮.com.cn')) ``` ### Response #### Success Response (string) - **public_suffix** (string) - The extracted public suffix, respecting the IDNA setting. #### Response Example ``` 'google.com' '食狮.com.cn' ``` ``` -------------------------------- ### Fetch and Use Latest Public Suffix List Source: https://context7.com/aboutcode-org/python-publicsuffix2/llms.txt Shows how to download the most recent Public Suffix List from the official source and use it for domain parsing. The library caches the fetched list globally for subsequent uses, improving performance. ```python from publicsuffix2 import fetch, get_sld, PublicSuffixList # Fetch the latest PSL and use it psl_file = fetch() result = get_sld('www.example.com', psl_file) print(result) # Output: example.com # Use with PublicSuffixList class psl_file = fetch() psl = PublicSuffixList(psl_file) result = psl.get_sld('www.newdomain.io') print(result) # Output: newdomain.io # Note: The fetched file is cached globally after first load # Subsequent calls use the cached version ``` -------------------------------- ### Handle Exception Rules in PSL Parsing Source: https://context7.com/aboutcode-org/python-publicsuffix2/llms.txt Illustrates how to manage exception rules (prefixed with '!') within the Public Suffix List. These rules override wildcard matching, allowing specific subdomains to be treated as public suffixes when needed. ```python from publicsuffix2 import PublicSuffixList # Create PSL with wildcard and exception rules rules = [ 'com', '*.ck', # All subdomains of .ck are public suffixes '!www.ck' # Exception: www.ck is NOT a public suffix ] psl = PublicSuffixList(rules) # Regular wildcard applies result = psl.get_sld('test.foo.ck') print(result) # Output: foo.ck # Exception rule applies - www.ck is registrable result = psl.get_sld('test.www.ck') print(result) # Output: www.ck # Using the bundled PSL with real exception rules psl_default = PublicSuffixList() # www.ck is an exception in the real PSL result = psl_default.get_sld('www.www.ck') print(result) # Output: www.ck result = psl_default.get_sld('this.that.ck') print(result) # Output: that.ck ``` -------------------------------- ### Using in Large-Scale Processing (PySpark) Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Provides guidance on using the library efficiently in large-scale distributed processing environments like PySpark. ```APIDOC ## Using in Large-Scale Processing (PySpark) ### Description For large-scale processing, such as with PySpark, it is recommended to instantiate the `PublicSuffixList` class as a global variable rather than within a user function. This allows the class methods to be efficiently used across distributed tasks. ### Method Instantiate `PublicSuffixList` globally. ### Endpoint N/A (Usage pattern) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python # Global instantiation from publicsuffix2 import PublicSuffixList GLOBAL_PSL = PublicSuffixList() def process_domain(domain): # Use the globally instantiated object return GLOBAL_PSL.get_public_suffix(domain) # Example usage within a distributed context (conceptual) # rdd.map(process_domain) ``` ### Response N/A (This describes a usage pattern, not a direct API response.) ``` -------------------------------- ### Control Wildcard Handling in PSL Parsing Source: https://context7.com/aboutcode-org/python-publicsuffix2/llms.txt Demonstrates how to enable or disable wildcard rule processing when extracting the effective TLD or SLD from a domain. This is crucial for accurate domain aggregation, especially with complex domain structures like AWS ELB. ```python from publicsuffix2 import PublicSuffixList psl = PublicSuffixList() # With wildcards enabled (default) - follows PSL wildcard rules result = psl.get_sld('telinet.com.pg', wildcard=True) print(result) # Output: telinet.com.pg (*.pg rule applies) # With wildcards disabled - ignores wildcard rules for aggregation result = psl.get_sld('telinet.com.pg', wildcard=False) print(result) # Output: com.pg # AWS domains with wildcard handling result_wc = psl.get_sld('myapp.ap-southeast-1.elb.amazonaws.com', wildcard=True) print(result_wc) # Output: myapp.ap-southeast-1.elb.amazonaws.com result_no_wc = psl.get_sld('myapp.ap-southeast-1.elb.amazonaws.com', wildcard=False) print(result_no_wc) # Output: ap-southeast-1.elb.amazonaws.com # TLD lookup with wildcards tld_wc = psl.get_tld('test.com.pg', wildcard=True) print(tld_wc) # Output: com.pg tld_no_wc = psl.get_tld('test.com.pg', wildcard=False) print(tld_no_wc) # Output: pg ``` -------------------------------- ### Basic Usage: get_public_suffix() Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Demonstrates the basic usage of the get_public_suffix() function, which utilizes a global cache for the latest suffix list data. ```APIDOC ## Basic Usage: get_public_suffix() ### Description This function retrieves the public suffix for a given domain name. It uses a global cache to store the latest suffix list data, ensuring efficiency. ### Method `get_public_suffix(domain)` ### Endpoint N/A (Library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from publicsuffix2 import get_public_suffix get_public_suffix('www.example.co.uk') ``` ### Response #### Success Response (string) - **public_suffix** (string) - The extracted public suffix (e.g., 'example.co.uk'). #### Response Example ``` 'example.co.uk' ``` ``` -------------------------------- ### Large-Scale Domain Processing with PySpark Source: https://context7.com/aboutcode-org/python-publicsuffix2/llms.txt Provides guidance on efficiently processing large volumes of domain data using PySpark. It emphasizes instantiating the PublicSuffixList globally to avoid repeated initialization within UDFs, thus optimizing performance. ```python from publicsuffix2 import PublicSuffixList # Instantiate globally for PySpark - do NOT instantiate inside UDFs PSL = PublicSuffixList() # Example PySpark usage (conceptual) # from pyspark.sql import SparkSession # from pyspark.sql.functions import udf # from pyspark.sql.types import StringType # # spark = SparkSession.builder.appName("DomainProcessing").getOrCreate() # # # Define UDF using the global PSL instance # @udf(returnType=StringType()) # def extract_sld(domain): # return PSL.get_sld(domain) # # # Apply to DataFrame # df = spark.createDataFrame([("www.google.com",), ("mail.yahoo.co.uk",)], ["domain"]) # df_with_sld = df.withColumn("sld", extract_sld(df["domain"])) # df_with_sld.show() # # +------------------+--------------+ # # | domain| sld| # # +------------------+--------------+ # # | www.google.com| google.com| # # | mail.yahoo.co.uk| yahoo.co.uk| # # +------------------+--------------+ # Batch processing example domains = [ 'www.google.com', 'mail.yahoo.co.uk', 'app.mysite.co.jp', 'blog.example.org' ] results = [(d, PSL.get_sld(d), PSL.get_tld(d)) for d in domains] for domain, sld, tld in results: print(f"{domain} -> SLD: {sld}, TLD: {tld}") # Output: # www.google.com -> SLD: google.com, TLD: com # mail.yahoo.co.uk -> SLD: yahoo.co.uk, TLD: co.uk # app.mysite.co.jp -> SLD: mysite.co.jp, TLD: co.jp # blog.example.org -> SLD: example.org, TLD: org ``` -------------------------------- ### Return eTLD Only: get_tld() Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Explains the `get_tld()` method for retrieving only the effective Top-Level Domain (eTLD) of a given domain. ```APIDOC ## Return eTLD Only: get_tld() ### Description This method is used to retrieve only the effective Top-Level Domain (eTLD) of a given domain, as opposed to the full registrable domain. ### Method `get_tld(domain)` ### Endpoint N/A (Library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from publicsuffix2 import PublicSuffixList psl = PublicSuffixList() print(psl.get_tld('www.google.com')) print(psl.get_tld('www.google.co.uk')) ``` ### Response #### Success Response (string) - **eTLD** (string) - The extracted effective Top-Level Domain. #### Response Example ``` 'com' 'co.uk' ``` ``` -------------------------------- ### Strict TLD Validation Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Demonstrates how to enforce strict validation of TLDs using the `strict` parameter, returning `None` for invalid TLDs. ```APIDOC ## Strict TLD Validation ### Description By default, `publicsuffix2` returns a base domain even for invalid TLDs (e.g., 'www.mine.local' might return 'mine.local'). To ensure that the domain includes a valid TLD, set the `strict` parameter to `True`. An invalid TLD will then result in `None`. ### Method `get_public_suffix(domain, strict=True/False)` ### Endpoint N/A (Library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from publicsuffix2 import PublicSuffixList psl = PublicSuffixList() # Without strict validation print(psl.get_public_suffix('www.mine.local')) # With strict validation print(psl.get_public_suffix('www.mine.local', strict=True)) ``` ### Response #### Success Response (string or None) - **public_suffix** (string) - The extracted public suffix if the TLD is valid. - **None** - If `strict=True` and the TLD is invalid. #### Response Example ``` 'mine.local' None ``` ``` -------------------------------- ### Handling IDNA-Encoded Domains Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Explains how to handle Internationalized Domain Names (IDNs) which may be encoded. By default, the module converts the PSL to UTF-8. To process IDNA-encoded domains correctly, you might need to set the IDNA-encoding flag to False during instantiation if your input is not UTF-8. ```python from publicsuffix2 import PublicSuffixList # Example with a UTF-8 domain (default behavior should handle this) utf8_domain = '食狮.com.cn' psl_default = PublicSuffixList() print(f"Default handling for '{utf8_domain}': {psl_default.get_public_suffix(utf8_domain)}") # Example if you need to explicitly disable IDNA encoding for non-UTF-8 input # Note: This assumes your input is already IDNA encoded if you set this to False. # For most cases, the default behavior is recommended. psl_no_idna = PublicSuffixList(False) # print(f"Handling with IDNA disabled for '{utf8_domain}': {psl_no_idna.get_public_suffix(utf8_domain)}") # Example demonstrating potential issues if encoding is mismatched # If the input is IDNA encoded and you don't decode it first, or vice-versa. # The module expects UTF-8 input by default for domain names. # For Punycode (IDNA encoded) input, you would typically decode it first: # import idna # decoded_domain = idna.decode(punycode_domain) # print(psl.get_public_suffix(decoded_domain)) ``` -------------------------------- ### Ignoring Wildcards Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Shows how to ignore wildcards in the public suffix list by setting the `wildcard` parameter to `False`. ```APIDOC ## Ignoring Wildcards ### Description For large-scale domain processing, you might want to ignore wildcards to enable more aggregation. This can be achieved by setting the `wildcard` parameter to `False` when calling `get_public_suffix()`. ### Method `get_public_suffix(domain, wildcard=True/False)` ### Endpoint N/A (Library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from publicsuffix2 import PublicSuffixList psl = PublicSuffixList() # With wildcard (default) print(psl.get_public_suffix('telinet.com.pg', wildcard=True)) # Without wildcard print(psl.get_public_suffix('telinet.com.pg', wildcard=False)) ``` ### Response #### Success Response (string) - **public_suffix** (string) - The extracted public suffix, with or without considering wildcards. #### Response Example ``` 'telinet.com.pg' 'com.pg' ``` ``` -------------------------------- ### Accessing the TLDs Attribute Source: https://github.com/aboutcode-org/python-publicsuffix2/blob/develop/README.rst Shows how to access the `tlds` attribute of a `PublicSuffixList` instance to view the extracted TLDs and their modifiers. ```APIDOC ## Accessing the TLDs Attribute ### Description The `tlds` attribute of a `PublicSuffixList` instance provides direct access to the extracted list of TLDs and their associated rules (modifiers). ### Method `psl.tlds` ### Endpoint N/A (Library attribute) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from publicsuffix2 import PublicSuffixList psl = PublicSuffixList() # Print the first 5 entries of the TLD list print(psl.tlds[:5]) ``` ### Response #### Success Response (list) - **tlds** (list) - A list of strings, where each string is a TLD or a rule for a TLD. #### Response Example ``` ['ac', 'com.ac', 'edu.ac', 'gov.ac', 'net.ac'] ``` ``` -------------------------------- ### Extract Public Suffix (TLD) with get_tld Source: https://context7.com/aboutcode-org/python-publicsuffix2/llms.txt Retrieves the effective Top-Level Domain (eTLD) portion of a domain. Includes options for wildcard processing and strict TLD validation. ```python from publicsuffix2 import get_tld # Get the public suffix tld = get_tld('www.google.com') print(tld) # Output: com # With wildcards disabled tld = get_tld('telinet.com.pg', wildcard=False) print(tld) # Output: pg ``` -------------------------------- ### Extract Second-Level Domain (SLD) with get_sld Source: https://context7.com/aboutcode-org/python-publicsuffix2/llms.txt Extracts the registrable domain (SLD) from a fully qualified domain name. Supports strict validation and handles complex TLDs and subdomains. ```python from publicsuffix2 import get_sld # Basic usage domain = get_sld('www.example.com') print(domain) # Output: example.com # Strict mode - returns None for invalid TLDs domain = get_sld('www.example.local', strict=True) print(domain) # Output: None ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.