Name parser based on Public Suffix List
Project description
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()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pslextract-2.0.0-py3-none-any.whl.
File metadata
- Download URL: pslextract-2.0.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6b49985a2598c2875c7d859cbcaf13698b365663a94c00578288c8f784b5c36
|
|
| MD5 |
e12cbb38611aecd9dd6b664ea64ac9aa
|
|
| BLAKE2b-256 |
b7703aa9e250402db46134664e9552fa7e1509b815164b93bfd83be378615636
|