Skip to main content

PSLExtract

Name parser based on Public Suffix List (a.k.a. PSL).

This package is an alternative to publicsuffixlist.

Setup

Use Python virtual environements for the best experience.

# in a venv
pip install pslextract

CLI Usage

# Fetch latest Public Suffix List version, use -h for help
pslfetch
# Parse latest Public Suffix List (after pslfetch), use -h for help
pslparse
# Process FQDNs
names=(
    raw.githubusercontent.com
    koromodako.github.io
    github.com
)
pslextract ${names[@]} | jq
{
  "name": "raw.githubusercontent.com",
  "prefix": "",
  "public_suffix": "githubusercontent.com",
  "private_suffix": "raw.githubusercontent.com"
}
{
  "name": "koromodako.github.io",
  "prefix": "",
  "public_suffix": "github.io",
  "private_suffix": "koromodako.github.io"
}
{
  "name": "github.com",
  "prefix": "",
  "public_suffix": "com",
  "private_suffix": "github.com"
}

API Usage

from dataclasses import asdict
from json import dumps

from pslextract import (
    DEFAULT_JSON_FILE,
    DEFAULT_RAW_FILE,
    PSLIndex,
    json_dumps,
    psl_create_index,
    psl_extract,
    psl_fetch,
)

NAMES = (
    'example.com',                # a valid Name
    'sub.example.com',            # a valid Name
    'sub.api.gov.uk',             # a valid Name
    ''                            # an invalid Name (empty string)
    '127.0.0.1',                  # an invalid Name (IPv4 address)
    'fe80::1010:1e8f:3f57:fe54',  # an invalid Name (IPv6 address)
    'subexamplecom',              # an invalid Name (missing dots)
    'sub....example.com',         # an invalid Name (empty components)
    'co.uk',                      # an invalid Name (suffix only)
    'sub.sld.notavalidtld',       # an invalid Name (unknown tld)
)


def main():
    if not DEFAULT_JSON_FILE.is_file():
        if not DEFAULT_RAW_FILE.is_file():
            psl_fetch()
        index = psl_create_index()
        index.to_json_file()
    index = PSLIndex.from_json_file()
    for name in NAMES:
        name = psl_extract(index, name)
        if not name:
            continue
        dct = {'name': name.value}
        dct.update(asdict(name))
        print(json_dumps(dct))


if __name__ == '__main__':
    main()

Metadata

Release files for pslextract 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for pslextract 2.1.0
File Interpreter ABI Platform Actions
pslextract-2.1.0-py3-none-any.whl Python 3 none any Details for pslextract-2.1.0-py3-none-any.whl

Release files / pslextract-2.1.0-py3-none-any.whl

Download URL pslextract-2.1.0-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b768da8d740e1a36018a5aed491112b4d40eb33308b794fe3fb438204254ea2
BLAKE2b-256 checksum
How to use checksums
7915a8b231e04a92878ef0e2ea343d547ae50b499a916bbe5e8591a58dcfe590
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for pslextract 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page