API reference¶
Generated from the source, so it cannot drift from the code.
Every expression takes a string column of URLs or bare hostnames, plus the same two keywords:
include_private— whether the Public Suffix List's private section counts as suffixes, mirroringtldextract'sinclude_psl_private_domains. Off by default, as intldextract.parallel— whether the plugin may split large columns across rayon threads. Columns below 100k rows run single-threaded regardless.
Expressions¶
extract is the only one that reports an absent part as an empty string; the rest use null. See Usage for why.
extract ¶
extract(
expr: IntoExprColumn,
*,
include_private: bool = False,
parallel: bool = True,
) -> pl.Expr
Parse URLs into a struct, faithfully reproducing tldextract.
The output mirrors tldextract.ExtractResult: parts that do not exist are empty strings, not nulls. This is the one expression here that keeps that convention -- every single-field accessor uses nulls instead, which is what a DataFrame wants. Reach for this when porting tldextract code and wanting the behavior unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr | IntoExprColumn | String column of URLs (or bare hostnames). | required |
include_private | bool | Whether to treat the PSL's private section as suffixes, matching | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. Columns below 100k rows run single-threaded regardless. | True |
Returns:
| Type | Description |
|---|---|
Expr | Struct of |
Source code in python/polars_tldextract/_expr.py
fqdn ¶
Extract the whole hostname, e.g. "www.bbc.co.uk".
This is the normalized netloc: scheme, userinfo, port, path, query, and fragment stripped, trailing root labels dropped, and the three non-ASCII IDNA separators folded to .. Casing and punycode spelling are preserved.
Unlike registrable_domain, a host with no recognized suffix still has a name, so "localhost" and "127.0.0.1" come back as themselves rather than null. Only input with no host at all yields null. A bracketed IPv6 literal keeps its brackets, matching what extract reports as its domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr | IntoExprColumn | String column of URLs (or bare hostnames). | required |
include_private | bool | Whether to treat the PSL's private section as suffixes. Does not change the result -- the same labels are rejoined either way -- but is taken so every expression accepts the same keywords. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Utf8 column of hostnames, null where the input held no host. |
Source code in python/polars_tldextract/_expr.py
registrable_domain ¶
registrable_domain(
expr: IntoExprColumn,
*,
include_private: bool = False,
parallel: bool = True,
) -> pl.Expr
Extract "domain.suffix", or null when either half is missing.
Computed in one pass, without materializing the other parts. Strict on purpose: an IP or an unrecognized suffix has no registrable domain, so it yields null rather than a half-formed string. Use fqdn when you want the hostname regardless.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr | IntoExprColumn | String column of URLs (or bare hostnames). | required |
include_private | bool | Whether to treat the PSL's private section as suffixes. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Utf8 column of registrable domains, null where none could be parsed. |
Source code in python/polars_tldextract/_expr.py
subdomain ¶
subdomain(
expr: IntoExprColumn,
*,
include_private: bool = False,
parallel: bool = True,
) -> pl.Expr
Extract the subdomain, e.g. "www" from "www.bbc.co.uk".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr | IntoExprColumn | String column of URLs (or bare hostnames). | required |
include_private | bool | Whether to treat the PSL's private section as suffixes. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Utf8 column, null where there is no subdomain. |
Source code in python/polars_tldextract/_expr.py
domain ¶
Extract the registrable label, e.g. "bbc" from "bbc.co.uk".
This is tldextract's domain field -- the label you register, not the whole hostname. Use fqdn for the hostname and registrable_domain for "bbc.co.uk".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr | IntoExprColumn | String column of URLs (or bare hostnames). | required |
include_private | bool | Whether to treat the PSL's private section as suffixes. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Utf8 column, null where there is no registrable label. |
Source code in python/polars_tldextract/_expr.py
suffix ¶
Extract the public suffix, e.g. "co.uk" from "bbc.co.uk".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr | IntoExprColumn | String column of URLs (or bare hostnames). | required |
include_private | bool | Whether to treat the PSL's private section as suffixes. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Utf8 column, null where no suffix rule matched. |
Source code in python/polars_tldextract/_expr.py
The .tld namespace¶
Importing polars_tldextract registers this, so pl.col("url").tld.extract() works without importing anything else. Each method mirrors the module-level function of the same name.
TldNamespace ¶
tldextract-compatible URL parsing, as pl.col(...).tld.*.
Bind the namespace to an expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr | Expr | The string expression the namespace methods operate on. | required |
Source code in python/polars_tldextract/_namespace.py
extract ¶
Parse into a tldextract-faithful struct.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_private | bool | Whether to treat the PSL's private section as suffixes. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Struct of |
Source code in python/polars_tldextract/_namespace.py
fqdn ¶
Extract the whole hostname, e.g. "www.bbc.co.uk".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_private | bool | Whether to treat the PSL's private section as suffixes. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Utf8 column of hostnames, null where the input held no host. |
Source code in python/polars_tldextract/_namespace.py
registrable_domain ¶
Extract "domain.suffix", or null when either half is missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_private | bool | Whether to treat the PSL's private section as suffixes. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Utf8 column of registrable domains. |
Source code in python/polars_tldextract/_namespace.py
subdomain ¶
Extract the subdomain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_private | bool | Whether to treat the PSL's private section as suffixes. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Utf8 column of subdomains, null where there is none. |
Source code in python/polars_tldextract/_namespace.py
domain ¶
Extract the registrable label, e.g. "bbc" from "bbc.co.uk".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_private | bool | Whether to treat the PSL's private section as suffixes. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Utf8 column of registrable labels, null where there is none. |
Source code in python/polars_tldextract/_namespace.py
suffix ¶
Extract the public suffix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_private | bool | Whether to treat the PSL's private section as suffixes. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Utf8 column of public suffixes, null where no rule matched. |
Source code in python/polars_tldextract/_namespace.py
parts ¶
Build the 0.1 struct. Use registrable_domain/domain/suffix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_private | bool | Whether to treat the PSL's private section as suffixes. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Struct of |
Source code in python/polars_tldextract/_namespace.py
top_domain ¶
Extract the registrable label. Deprecated alias for domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_private | bool | Whether to treat the PSL's private section as suffixes. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Utf8 column of registrable labels, null where there is none. |
Source code in python/polars_tldextract/_namespace.py
Scalars¶
For code that is not holding a DataFrame — the same Rust core, no Polars round-trip.
extract_scalar builtin ¶
extract_scalar(
url: str | None, *, include_private: bool = False
) -> tuple[str | None, str | None, str | None]
Parse one URL, for callers that are not holding a DataFrame.
Returns (registrable_domain, domain, suffix) with the same null semantics as the single-field kernels, so scalar and vectorized paths agree by construction.
extract_scalar_full builtin ¶
Parse one URL into (subdomain, domain, suffix, is_private), the faithful tldextract result with empty strings for absent parts.
The suffix list¶
psl_version builtin ¶
The VERSION: stamp of the Public Suffix List actually in use.
load_psl ¶
Replace the live Public Suffix List, and return its version.
Takes effect for every extraction that starts after it returns. A query already running keeps the list it started with, so no column can be parsed against two different lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source | str | Path | A path to a | required |
Returns:
| Type | Description |
|---|---|
str | The |
Raises:
| Type | Description |
|---|---|
ValueError | If the file cannot be read, or the list cannot be parsed, or it is missing the ICANN/private section markers. The previously loaded list stays in use. |
Examples:
>>> import polars_tldextract as tld
>>> path = "/mnt/reference/public_suffix_list.dat"
>>> tld.load_psl(path)
'2026-07-21_08-00-00_UTC'
Source code in python/polars_tldextract/_psl.py
refresh_psl ¶
refresh_psl(
url: str = PSL_URL,
*,
timeout: float = 60.0,
save_to: str | Path | None = None,
) -> str
Download the current Public Suffix List and load it.
This is the only function in the package that touches the network, and only when you call it. Call it before the extraction whose results should reflect the newer list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | str | Where to fetch the list from. Point this at an internal mirror if outbound access is restricted. | `PSL_URL` |
timeout | float | Seconds to wait for the download. | 60.0 |
save_to | str | Path | None | If given, also write the downloaded list here, so a later run can | None |
Returns:
| Type | Description |
|---|---|
str | The |
Raises:
| Type | Description |
|---|---|
OSError | If the download fails. The previously loaded list stays in use. |
ValueError | If what comes back is not a usable Public Suffix List. The previously loaded list stays in use. |
Examples:
Source code in python/polars_tldextract/_psl.py
Deprecated¶
Removed in 0.3. See migrating from 0.1.
parts ¶
Build the 0.1 full_domain / sld / tld struct. Deprecated.
The three fields are registrable_domain, domain, and suffix, which now carry the null semantics parts existed to provide. full_domain was a misnomer for the registrable domain -- fqdn is the actual full domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr | IntoExprColumn | String column of URLs (or bare hostnames). | required |
include_private | bool | Whether to treat the PSL's private section as suffixes. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Struct of |
Source code in python/polars_tldextract/_deprecated.py
top_domain ¶
top_domain(
expr: IntoExprColumn,
*,
include_private: bool = False,
parallel: bool = True,
) -> pl.Expr
Extract the registrable label. Deprecated alias for domain.
top_domain returned an empty string where there was no registrable label; domain returns null, like every other single-field expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr | IntoExprColumn | String column of URLs (or bare hostnames). | required |
include_private | bool | Whether to treat the PSL's private section as suffixes. | False |
parallel | bool | Whether the plugin may split large columns across rayon threads. | True |
Returns:
| Type | Description |
|---|---|
Expr | Utf8 column, null where there is no registrable label. |