feu.compat¶
Registry-based package/Python-version compatibility resolution: given a package name and a target environment, find out which versions of that package are known to work.
Concepts¶
Targetidentifies the environment a constraint applies to:python_versionandfree_threaded(always concrete), plus optionalos/arch.Noneonos/archmeans "any" when stored in the registry, and "unspecified" when used as a lookup key.VersionRangeis one contiguous(min, max)span of valid package versions; either bound may beNonefor unbounded. A package/target can have several disjoint ranges (e.g. a package supported1.0-1.10, then unsupported for a stretch, then supported again from2.8onward).CompatRegistrystores package constraints populated from the shipped data offeu/compat/data(one JSON file per package, parsed the first time the package is looked up, seeget_default_compat_registry()), and user calls toregister_compat(). A target registered with an empty list of ranges is explicitly unsupported, whereas a package/target with no entry is unconfigured and accepts any version.
A lookup target matches a stored entry when python_version and
free_threaded are equal, and each of os/arch is None in the entry
(wildcard), None in the lookup (unspecified: any platform) or equal.
Among the matching entries, the most specific ones (most non-None
os/arch) are kept and the answer is the union of their ranges.
Discovery¶
discover_compat_targets(pkg_name, targets=DEFAULT_TARGETS, *, companion=None,
ignore_versions=None) computes compatibility data from PyPI rather than
requiring it to be hand-maintained, with one algorithm for every package. For
each release, it parses the wheel file names (via WheelTag /
parse_wheel_filename) and the requires-python metadata to determine, per
target (Python version, OS, arch, free-threaded), the range of package
versions that support it. It returns a Discovery: the considered versions
and the ranges of each target.
A package whose wheels do not carry the platform tags is described by data, not
by a class: a companion package (SameVersion("jaxlib") for jax,
PinnedDependency("polars-runtime-32") for polars,
PinnedDependency("pydantic-core") for pydantic, see COMPANIONS) and the
releases to ignore (IGNORED_VERSIONS, e.g. duckdb 0.0.0). For such a
package a pure-Python wheel says nothing about the platform and never counts:
the release is judged by its platform wheels, or by the wheels of the
companion release. Pass companion= or ignore_versions= to handle a new
case.
The discovered data is the built-in compatibility data: one JSON file per
package in feu/compat/data/<canonical-name>.json (the format is documented
in feu.compat.shipped), regenerated by dev/generate_compat_data.py and run
on a schedule by the bot-update-discovered-compat CI workflow
(.github/workflows/bot-update-discovered-compat.yaml). The list of packages
is the list of files: add a package with
python dev/generate_compat_data.py --new <package>, no other file is edited.
CompatRegistry.packages() lists them without parsing any file.
Usage¶
>>> from feu.compat import Target, find_closest_version, is_valid_version
>>> target = Target(python_version="3.11")
>>> is_valid_version("numpy", "1.23.2", target)
True
>>> find_closest_version("numpy", "0.1.0", target)
'...'
Corrections can be registered on top of the built-in data:
>>> from feu.compat import Target, register_compat
>>> from feu.compat.registry import VersionRange
>>> register_compat({"mypkg": {Target(python_version="3.12"): [VersionRange("2.0", None)]}})
API reference¶
feu.compat ¶
Contain a registry-based system for package/target compatibility resolution.
feu.compat.CompatRegistry ¶
Manage package version compatibility across different compatibility targets.
The registry maps the canonical package name (PEP 503) to Target
to a list of
VersionRange. A package version is valid for a target if it
falls within any of the registered ranges; an empty list means no
version is valid for that target. A lookup target matches a
stored entry when python_version and free_threaded are
equal, and each of os/arch is None in the stored entry
(wildcard), None in the lookup target (unspecified, i.e. any
platform) or equal. Among all matching entries, the most specific
ones (most non-None os/arch fields) are kept and the
answer is the union of their ranges. A lookup target that leaves
os/arch to None therefore gets the versions published
for at least one platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_state
|
dict[str, dict[Target, list[VersionRange]]] | None
|
Optional initial mapping of package
constraints. If provided, the state is deep-copied to
prevent external mutations. It is validated like
|
None
|
loader
|
DataLoader | None
|
Optional loader of the data of the packages. The data
of a package is loaded the first time the package is
looked up or registered into, so creating the registry
and listing its packages cost nothing. A registration into
a package that is not loaded yet loads it first, so the
conflict check and |
None
|
version_source
|
Callable[[str], Iterable[str]] | None
|
Optional function that returns the releases of
a package (given its canonical name), in any order. It is
called only to match a wildcard request (e.g. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a range of |
Example
>>> from feu.compat import CompatRegistry, Target
>>> from feu.compat.registry import VersionRange
>>> registry = CompatRegistry()
>>> registry.register(
... pkg_name="numpy",
... target=Target(python_version="3.11"),
... ranges=[VersionRange("1.23.2", "2.4.6")],
... )
>>> registry.is_valid_version("numpy", "2.0.2", Target(python_version="3.11"))
True
feu.compat.CompatRegistry.state
property
¶
state: Mapping[str, Mapping[Target, list[VersionRange]]]
A read-only view of the registered package constraints, as a
mapping of canonical package name to Target to a list of
VersionRange.
Reading it loads the data of every package of the loader.
feu.compat.CompatRegistry.find_closest_version ¶
find_closest_version(
pkg_name: str, pkg_version: str | None, target: Target
) -> str
Find the closest valid version for a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to check (e.g., |
required |
pkg_version
|
str | None
|
The requested package version: an exact
version (e.g. |
required |
target
|
Target
|
The compatibility target. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The version to install, as a string. |
str
|
|
str
|
|
str
|
|
str
|
|
Raises:
| Type | Description |
|---|---|
UnsupportedVersionError
|
If no package version is valid for the given target, or if no known version satisfies a wildcard request. |
ValueError
|
If |
Example
>>> from feu.compat import CompatRegistry, Target, VersionRange
>>> target = Target(python_version="3.11")
>>> registry = CompatRegistry({"numpy": {target: [VersionRange("1.0.0", "1.26.4")]}})
>>> registry.register_versions("numpy", ["1.0.0", "1.26.4", "2.0.0"])
>>> registry.find_closest_version("numpy", "2.0.0", target)
'1.26.4'
>>> registry.find_closest_version("numpy", "", target)
'1.26.4'
feu.compat.CompatRegistry.get_compatible_versions ¶
get_compatible_versions(
pkg_name: str,
target: Target,
pkg_version: str | None = "",
) -> list[str]
Get the known versions that are valid for a target and satisfy a version request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name (e.g., |
required |
target
|
Target
|
The compatibility target. |
required |
pkg_version
|
str | None
|
The version request: an exact version, a
wildcard (e.g. |
''
|
Returns:
| Type | Description |
|---|---|
list[str]
|
The known versions that lie in a valid range of the target and satisfy the request, in PEP 440 order. The versions are the registered ones or, if there are none, the ones of the version source (downloaded when the method is called). The list is empty if the package has no data, if no version is valid for the target, or if nothing matches. A package that has no configuration for the target accepts every known version. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
>>> from feu.compat import CompatRegistry, Target, VersionRange
>>> target = Target(python_version="3.11")
>>> registry = CompatRegistry({"numpy": {target: [VersionRange("1.0.0", "1.26.4")]}})
>>> registry.register_versions("numpy", ["1.0.0", "1.26.4", "2.0.0"])
>>> registry.get_compatible_versions("numpy", target)
['1.0.0', '1.26.4']
>>> registry.get_compatible_versions("numpy", target, "2.*")
[]
feu.compat.CompatRegistry.get_config ¶
get_config(
pkg_name: str, target: Target
) -> list[VersionRange]
Get the list of valid version ranges for a package and compatibility target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to query (e.g., |
required |
target
|
Target
|
The compatibility target. |
required |
Returns:
| Type | Description |
|---|---|
list[VersionRange]
|
The list of |
list[VersionRange]
|
list if no configuration matches. |
feu.compat.CompatRegistry.get_version_ranges ¶
get_version_ranges(
pkg_name: str, target: Target
) -> list[tuple[Version | None, Version | None]]
Get the valid version ranges as Version objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to query (e.g., |
required |
target
|
Target
|
The compatibility target. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[Version | None, Version | None]]
|
A list of |
Raises:
| Type | Description |
|---|---|
UnsupportedVersionError
|
If no package version is valid for the given target. |
feu.compat.CompatRegistry.has_package ¶
has_package(pkg_name: str) -> bool
Indicate if at least one configuration is registered for a package.
An unknown package is permissive (any version is valid), so this method lets the caller detect that case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to check (e.g., |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
feu.compat.CompatRegistry.is_unsupported ¶
is_unsupported(pkg_name: str, target: Target) -> bool
Indicate if no package version is valid for a target.
This is distinct from a target having no registered
configuration at all: an unconfigured target is treated as
permissive (False), whereas a target explicitly
registered with an empty range list is unsupported
(True).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to check (e.g., |
required |
target
|
Target
|
The compatibility target. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
given target, |
feu.compat.CompatRegistry.is_valid_version ¶
is_valid_version(
pkg_name: str, pkg_version: str | None, target: Target
) -> bool
Check if a package version is valid for a target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to check (e.g., |
required |
pkg_version
|
str | None
|
The package version request: an exact
version, a wildcard (e.g. |
required |
target
|
Target
|
The compatibility target. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool
|
For an exact version: |
|
bool
|
range or unconfigured, |
|
bool
|
no package version is valid for the given target. For a |
|
wildcard |
bool
|
|
bool
|
version satisfies the request (see |
|
bool
|
|
|
bool
|
versions); a package without data gives |
|
bool
|
the latest version: |
|
bool
|
the package and a version is valid for the target; no |
|
bool
|
version is downloaded. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
>>> from feu.compat import CompatRegistry, Target, VersionRange
>>> target = Target(python_version="3.11")
>>> registry = CompatRegistry({"numpy": {target: [VersionRange("1.0.0", "1.26.4")]}})
>>> registry.register_versions("numpy", ["1.0.0", "1.26.4", "2.0.0"])
>>> registry.is_valid_version("numpy", "1.*", target)
True
>>> registry.is_valid_version("numpy", "2.*", target)
False
feu.compat.CompatRegistry.packages ¶
packages() -> list[str]
Get the packages of the registry.
Returns:
| Type | Description |
|---|---|
list[str]
|
The sorted canonical names of the registered packages and of the packages that the loader can load. No data is loaded. |
Example
>>> from feu.compat import CompatRegistry, Target, VersionRange
>>> registry = CompatRegistry({"NumPy": {Target("3.11"): [VersionRange("1.0", None)]}})
>>> registry.packages()
['numpy']
feu.compat.CompatRegistry.register ¶
register(
pkg_name: str,
target: Target,
*,
ranges: list[VersionRange],
exist_ok: bool = False,
) -> None
Register a package configuration for a compatibility target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to register (e.g., |
required |
target
|
Target
|
The compatibility target. |
required |
ranges
|
list[VersionRange]
|
The list of valid version ranges for this target. An empty list means no version is valid. |
required |
exist_ok
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a configuration already exists for the
given package name and target, and |
ValueError
|
If a bound of a range is not a valid PEP 440 version, or if a minimum is greater than the maximum of the same range. Nothing is registered in that case. |
feu.compat.CompatRegistry.register_many ¶
register_many(
mapping: dict[str, dict[Target, list[VersionRange]]],
exist_ok: bool = False,
) -> None
Register multiple package configurations at once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
dict[str, dict[Target, list[VersionRange]]]
|
Mapping of package name to |
required |
exist_ok
|
bool
|
Forwarded to |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If any configuration already exists for a
given package name and target, and |
feu.compat.CompatRegistry.register_versions ¶
register_versions(
pkg_name: str,
versions: Iterable[str],
*,
exist_ok: bool = False,
) -> None
Register the versions the registry knows for a package.
A wildcard or empty version request (e.g. "2.*") is matched
against these versions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name (e.g., |
required |
versions
|
Iterable[str]
|
The known versions, in any order. Duplicates are removed and the versions are sorted by PEP 440 order. |
required |
exist_ok
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If versions are already registered for the
package and |
InvalidVersion
|
If a version is not a valid PEP 440 version. |
Example
>>> from feu.compat import CompatRegistry
>>> registry = CompatRegistry()
>>> registry.register_versions("numpy", ["2.0.0", "1.26.4", "2.0.2"])
feu.compat.Discovery ¶
Bases: NamedTuple
Represent the result of discover_compat_targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
versions
|
The releases that were considered (stable, valid and not ignored), in PEP 440 order. |
required | |
targets
|
The ranges of compatible versions of each target. A
range that reaches the latest release is open (its
|
required |
feu.compat.PinnedDependency
dataclass
¶
Describe a companion package whose release is pinned by the
release of the package (e.g. polars pins polars-runtime-32
and pydantic pins pydantic-core).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
str
|
The companion package name. |
required |
feu.compat.SameVersion
dataclass
¶
Describe a companion package that has a release with the same
version (e.g. jax and jaxlib).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
str
|
The companion package name. |
required |
feu.compat.Target
dataclass
¶
Identify the environment a package compatibility constraint applies to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
python_version
|
str
|
The Python version, e.g. |
required |
free_threaded
|
bool
|
|
False
|
os
|
str | None
|
The operating system, e.g. |
None
|
arch
|
str | None
|
The CPU architecture, e.g. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Example
>>> from feu.compat.target import Target
>>> Target(python_version="3.14", free_threaded=True, os="linux", arch="x86_64")
Target(python_version='3.14', free_threaded=True, os='linux', arch='x86_64')
feu.compat.UnsupportedVersionError ¶
Bases: Exception
Raised when no package version is compatible with a given target.
feu.compat.VersionRange ¶
Bases: NamedTuple
Represent one contiguous range of valid package versions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min
|
The minimum valid package version, or |
required | |
max
|
The maximum valid package version, or |
required |
feu.compat.WheelTag
dataclass
¶
Represent one (interpreter, abi, platform) tag of a wheel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
python_version
|
str | None
|
The CPython version (e.g. |
required |
free_threaded
|
bool
|
|
required |
os
|
str | None
|
The operating system ( |
required |
arch
|
str | None
|
The CPU architecture ( |
required |
abi3
|
bool
|
|
False
|
Example
>>> from feu.compat.wheel_tags import WheelTag
>>> WheelTag(python_version="3.12", free_threaded=False, os="linux", arch="x86_64")
WheelTag(python_version='3.12', free_threaded=False, os='linux', arch='x86_64', abi3=False)
feu.compat.discover_compat_targets ¶
discover_compat_targets(
pkg_name: str,
targets: Sequence[Target] = DEFAULT_TARGETS,
*,
companion: Companion | None = None,
ignore_versions: Collection[str] | None = None,
) -> Discovery
Discover the versions of a package that are compatible with each target, from the files published on PyPI.
A release is compatible with a target if a wheel runs on it:
- A package without companion: one wheel matches exactly
(Python version, free-threaded flag, OS and architecture), or is
abi3with a minimum Python at or below the target, or is pure Python andrequires-pythonallows the target. A release with no wheel is treated as pure Python only if some release of the package published a pure-Python wheel. - A package with a companion (
jax,polars,pydantic): a pure-Python wheel of the package says nothing about the platform and never counts. The release is judged by its platform wheels if it has any; otherwise by the wheels of the companion release (the release with the same version, or the one pinned by the release). An unknown companion release means "not compatible".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to inspect (e.g., |
required |
targets
|
Sequence[Target]
|
The compatibility targets to compute constraints for.
Each target must have concrete (non- |
DEFAULT_TARGETS
|
companion
|
Companion | None
|
The companion package. |
None
|
ignore_versions
|
Collection[str] | None
|
The releases to ignore. |
None
|
Returns:
| Type | Description |
|---|---|
Discovery
|
The considered versions and the ranges of compatible versions
of each target. The ranges can be given to
|
Example
>>> from feu.compat import discover_compat_targets
>>> discovery = discover_compat_targets("numpy") # doctest: +SKIP
feu.compat.fetch_known_versions ¶
fetch_known_versions(pkg_name: str) -> tuple[str, ...]
Fetch the releases of a package that the registry considers.
The versions are downloaded from PyPI when the function is called (the download of a package is cached), so the list is always up to date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
The stable, valid, not yanked and not ignored releases (see
|
Example
>>> from feu.compat import fetch_known_versions
>>> versions = fetch_known_versions("numpy") # doctest: +SKIP
feu.compat.find_closest_version ¶
find_closest_version(
pkg_name: str,
pkg_version: str | None,
target: Target,
*,
registry: CompatRegistry | None = None,
) -> str
Find the closest valid version for a package using the default registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to check (e.g., |
required |
pkg_version
|
str | None
|
The requested package version: an exact
version, a wildcard (e.g. |
required |
target
|
Target
|
The compatibility target. |
required |
registry
|
CompatRegistry | None
|
The compatibility registry. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The closest valid version as a string. An exact version is
returned unchanged if it is valid or if the package is not
configured for the target. A wildcard or empty request is
resolved to the latest compatible version, or returned
unchanged if it lies in an open-ended range (see
|
Raises:
| Type | Description |
|---|---|
UnsupportedVersionError
|
If no package version is valid for the given target, or if no known version satisfies a wildcard request. |
ValueError
|
If |
Example
>>> from feu.compat import find_closest_version, Target
>>> find_closest_version(
... pkg_name="numpy", pkg_version="2.0.2", target=Target(python_version="3.11")
... )
'2.0.2'
feu.compat.get_compatible_versions ¶
get_compatible_versions(
pkg_name: str,
target: Target,
pkg_version: str | None = "",
*,
registry: CompatRegistry | None = None,
) -> list[str]
Get the known versions that are valid for a target and satisfy a version request, using the default registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name (e.g., |
required |
target
|
Target
|
The compatibility target. |
required |
pkg_version
|
str | None
|
The version request: an exact version, a
wildcard (e.g. |
''
|
registry
|
CompatRegistry | None
|
The compatibility registry. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
The known compatible versions that satisfy the request, in
PEP 440 order (see
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
>>> from feu.compat import get_compatible_versions, Target
>>> versions = get_compatible_versions(
... "numpy", Target(python_version="3.9", os="linux", arch="x86_64"), "1.26.*"
... )
>>> versions[-1]
'1.26.4'
feu.compat.get_default_compat_registry
cached
¶
get_default_compat_registry() -> CompatRegistry
Return the default global compatibility registry.
The registry is created on the first call and reused on all
subsequent calls (singleton pattern). Its packages are the JSON
files of feu/compat/data, generated by
dev/generate_compat_data.py; the file of a package is parsed
the first time the package is looked up.
Returns:
| Type | Description |
|---|---|
CompatRegistry
|
A singleton |
Example
>>> from feu.compat import get_default_compat_registry, Target
>>> registry = get_default_compat_registry()
>>> registry.is_valid_version("numpy", "2.0.2", Target(python_version="3.11"))
True
feu.compat.group_into_ranges ¶
group_into_ranges(
versions: Sequence[str],
compatible: Collection[str],
latest: str | None,
) -> list[VersionRange]
Group the compatible versions into ranges of consecutive releases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
versions
|
Sequence[str]
|
All the considered versions, in ascending order. |
required |
compatible
|
Collection[str]
|
The versions that are compatible. |
required |
latest
|
str | None
|
The latest release. A range that ends with it is open. |
required |
Returns:
| Type | Description |
|---|---|
list[VersionRange]
|
The ranges of consecutive compatible versions. The |
Example
>>> from feu.compat import group_into_ranges
>>> group_into_ranges(["1", "2", "3", "4"], {"1", "2", "4"}, "4")
[VersionRange(min='1', max='2'), VersionRange(min='4', max=None)]
feu.compat.is_compatible ¶
is_compatible(
requires_python: str | None, python_version: str
) -> bool
Indicate if a requires_python specifier allows a given Python
version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requires_python
|
str | None
|
The |
required |
python_version
|
str
|
The Python version to check (e.g., |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Example
>>> from feu.compat import is_compatible
>>> is_compatible(">=3.9", "3.11")
True
>>> is_compatible(">=3.9", "3.8")
False
feu.compat.is_valid_version ¶
is_valid_version(
pkg_name: str,
pkg_version: str | None,
target: Target,
*,
registry: CompatRegistry | None = None,
) -> bool
Check if a package version is valid for a target using the default registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to check (e.g., |
required |
pkg_version
|
str | None
|
The package version request to validate: an
exact version, a wildcard (e.g. |
required |
target
|
Target
|
The compatibility target. |
required |
registry
|
CompatRegistry | None
|
The compatibility registry. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
>>> from feu.compat import is_valid_version, Target
>>> is_valid_version(
... pkg_name="numpy", pkg_version="2.0.2", target=Target(python_version="3.11")
... )
True
feu.compat.parse_wheel_filename ¶
parse_wheel_filename(filename: str) -> tuple[WheelTag, ...]
Parse the tags of a wheel file name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The wheel file name, e.g.
|
required |
Returns:
| Type | Description |
|---|---|
tuple[WheelTag, ...]
|
The distinct tags of the wheel, sorted. A wheel with a
compressed tag set ( |
Example
>>> from feu.compat.wheel_tags import parse_wheel_filename
>>> parse_wheel_filename("numpy-2.3.0-cp312-cp312-macosx_11_0_universal2.whl")
(WheelTag(python_version='3.12', free_threaded=False, os='macos', arch='arm64', abi3=False),
WheelTag(python_version='3.12', free_threaded=False, os='macos', arch='x86_64', abi3=False))
feu.compat.register_compat ¶
register_compat(
mapping: dict[str, dict[Target, list[VersionRange]]],
*,
exist_ok: bool = False,
) -> None
Register custom package configurations into the default global registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
dict[str, dict[Target, list[VersionRange]]]
|
Mapping of package name to |
required |
exist_ok
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If any entry is already registered and
|
Example
>>> from feu.compat import register_compat, Target, VersionRange
>>> register_compat(
... {"my_package": {Target(python_version="3.11"): [VersionRange("1.0.0", None)]}}
... )
feu.compat.resolve_target ¶
resolve_target(
python_version: str | None = None,
*,
free_threaded: bool | None = None,
) -> Target
Resolve the Target of an environment.
The platform (OS and CPU architecture) is always the current one. The Python version and the free-threaded flag can be chosen, e.g. by a CI matrix that checks other Python versions, and fall back to the current interpreter.
If python_version ends with t, the target is a
free-threaded build. In that case, free_threaded=False is
invalid because it contradicts the t suffix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
python_version
|
str | None
|
The Python version, e.g. |
None
|
free_threaded
|
bool | None
|
Whether the target is a free-threaded build.
If not provided, it is inferred from |
None
|
Returns:
| Type | Description |
|---|---|
Target
|
The resolved target, with the current OS and architecture. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Example
>>> from feu.compat.target import resolve_target
>>> target = resolve_target(python_version="3.14t")
>>> target.python_version, target.free_threaded
('3.14', True)
feu.compat.show_compat_targets ¶
show_compat_targets(
compat: Discovery | Mapping[Target, list[VersionRange]],
pkg_name: str | None = None,
) -> None
Print the output of discover_compat_targets as a table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compat
|
Discovery | Mapping[Target, list[VersionRange]]
|
The output of |
required |
pkg_name
|
str | None
|
The package name to show in the table title, if any. |
None
|
Raises:
| Type | Description |
|---|---|
MissingPackageError
|
if the |
Example
>>> from feu.compat import discover_compat_targets, show_compat_targets
>>> compat = discover_compat_targets("numpy") # doctest: +SKIP
>>> show_compat_targets(compat, pkg_name="numpy") # doctest: +SKIP
feu.compat.tags_match_exactly ¶
Indicate if a wheel tag runs on a wanted platform.
The os, arch and free_threaded fields must be equal. An
abi3 wheel matches a Python version at or above its own; any
other wheel needs the same Python version. A pure-Python tag (its
os and arch are None) never matches a platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
WheelTag
|
The tag of a wheel. |
required |
wanted
|
WheelTag
|
The wanted platform. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Example
>>> from feu.compat.wheel_tags import WheelTag
>>> from feu.compat import tags_match_exactly
>>> tag = WheelTag("3.9", False, "linux", "x86_64", abi3=True)
>>> tags_match_exactly(tag, WheelTag("3.12", False, "linux", "x86_64"))
True
feu.compat.discover ¶
Contain the function that discovers the package/target compatibility from the files published on PyPI.
One algorithm is used for every package. The packages whose wheels do not carry the platform tags themselves are described by data (a companion package, a version to ignore), not by a class.
feu.compat.discover.Discovery ¶
Bases: NamedTuple
Represent the result of discover_compat_targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
versions
|
The releases that were considered (stable, valid and not ignored), in PEP 440 order. |
required | |
targets
|
The ranges of compatible versions of each target. A
range that reaches the latest release is open (its
|
required |
feu.compat.discover.PinnedDependency
dataclass
¶
Describe a companion package whose release is pinned by the
release of the package (e.g. polars pins polars-runtime-32
and pydantic pins pydantic-core).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
str
|
The companion package name. |
required |
feu.compat.discover.SameVersion
dataclass
¶
Describe a companion package that has a release with the same
version (e.g. jax and jaxlib).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
str
|
The companion package name. |
required |
feu.compat.discover.discover_compat_targets ¶
discover_compat_targets(
pkg_name: str,
targets: Sequence[Target] = DEFAULT_TARGETS,
*,
companion: Companion | None = None,
ignore_versions: Collection[str] | None = None,
) -> Discovery
Discover the versions of a package that are compatible with each target, from the files published on PyPI.
A release is compatible with a target if a wheel runs on it:
- A package without companion: one wheel matches exactly
(Python version, free-threaded flag, OS and architecture), or is
abi3with a minimum Python at or below the target, or is pure Python andrequires-pythonallows the target. A release with no wheel is treated as pure Python only if some release of the package published a pure-Python wheel. - A package with a companion (
jax,polars,pydantic): a pure-Python wheel of the package says nothing about the platform and never counts. The release is judged by its platform wheels if it has any; otherwise by the wheels of the companion release (the release with the same version, or the one pinned by the release). An unknown companion release means "not compatible".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to inspect (e.g., |
required |
targets
|
Sequence[Target]
|
The compatibility targets to compute constraints for.
Each target must have concrete (non- |
DEFAULT_TARGETS
|
companion
|
Companion | None
|
The companion package. |
None
|
ignore_versions
|
Collection[str] | None
|
The releases to ignore. |
None
|
Returns:
| Type | Description |
|---|---|
Discovery
|
The considered versions and the ranges of compatible versions
of each target. The ranges can be given to
|
Example
>>> from feu.compat import discover_compat_targets
>>> discovery = discover_compat_targets("numpy") # doctest: +SKIP
feu.compat.discover.fetch_known_versions ¶
fetch_known_versions(pkg_name: str) -> tuple[str, ...]
Fetch the releases of a package that the registry considers.
The versions are downloaded from PyPI when the function is called (the download of a package is cached), so the list is always up to date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
The stable, valid, not yanked and not ignored releases (see
|
Example
>>> from feu.compat import fetch_known_versions
>>> versions = fetch_known_versions("numpy") # doctest: +SKIP
feu.compat.discover.group_into_ranges ¶
group_into_ranges(
versions: Sequence[str],
compatible: Collection[str],
latest: str | None,
) -> list[VersionRange]
Group the compatible versions into ranges of consecutive releases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
versions
|
Sequence[str]
|
All the considered versions, in ascending order. |
required |
compatible
|
Collection[str]
|
The versions that are compatible. |
required |
latest
|
str | None
|
The latest release. A range that ends with it is open. |
required |
Returns:
| Type | Description |
|---|---|
list[VersionRange]
|
The ranges of consecutive compatible versions. The |
Example
>>> from feu.compat import group_into_ranges
>>> group_into_ranges(["1", "2", "3", "4"], {"1", "2", "4"}, "4")
[VersionRange(min='1', max='2'), VersionRange(min='4', max=None)]
feu.compat.discover.is_compatible ¶
is_compatible(
requires_python: str | None, python_version: str
) -> bool
Indicate if a requires_python specifier allows a given Python
version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requires_python
|
str | None
|
The |
required |
python_version
|
str
|
The Python version to check (e.g., |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Example
>>> from feu.compat import is_compatible
>>> is_compatible(">=3.9", "3.11")
True
>>> is_compatible(">=3.9", "3.8")
False
feu.compat.discover.tags_match_exactly ¶
Indicate if a wheel tag runs on a wanted platform.
The os, arch and free_threaded fields must be equal. An
abi3 wheel matches a Python version at or above its own; any
other wheel needs the same Python version. A pure-Python tag (its
os and arch are None) never matches a platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
WheelTag
|
The tag of a wheel. |
required |
wanted
|
WheelTag
|
The wanted platform. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Example
>>> from feu.compat.wheel_tags import WheelTag
>>> from feu.compat import tags_match_exactly
>>> tag = WheelTag("3.9", False, "linux", "x86_64", abi3=True)
>>> tags_match_exactly(tag, WheelTag("3.12", False, "linux", "x86_64"))
True
feu.compat.display ¶
Contain functions to display the discovered compatibility.
feu.compat.display.show_compat_targets ¶
show_compat_targets(
compat: Discovery | Mapping[Target, list[VersionRange]],
pkg_name: str | None = None,
) -> None
Print the output of discover_compat_targets as a table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compat
|
Discovery | Mapping[Target, list[VersionRange]]
|
The output of |
required |
pkg_name
|
str | None
|
The package name to show in the table title, if any. |
None
|
Raises:
| Type | Description |
|---|---|
MissingPackageError
|
if the |
Example
>>> from feu.compat import discover_compat_targets, show_compat_targets
>>> compat = discover_compat_targets("numpy") # doctest: +SKIP
>>> show_compat_targets(compat, pkg_name="numpy") # doctest: +SKIP
feu.compat.registry ¶
Define the compatibility registry for package version resolution.
This module provides a registry system that manages and resolves valid package version ranges per compatibility target, enabling lookup of the closest valid version and validation of a given version.
feu.compat.registry.CompatRegistry ¶
Manage package version compatibility across different compatibility targets.
The registry maps the canonical package name (PEP 503) to Target
to a list of
VersionRange. A package version is valid for a target if it
falls within any of the registered ranges; an empty list means no
version is valid for that target. A lookup target matches a
stored entry when python_version and free_threaded are
equal, and each of os/arch is None in the stored entry
(wildcard), None in the lookup target (unspecified, i.e. any
platform) or equal. Among all matching entries, the most specific
ones (most non-None os/arch fields) are kept and the
answer is the union of their ranges. A lookup target that leaves
os/arch to None therefore gets the versions published
for at least one platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_state
|
dict[str, dict[Target, list[VersionRange]]] | None
|
Optional initial mapping of package
constraints. If provided, the state is deep-copied to
prevent external mutations. It is validated like
|
None
|
loader
|
DataLoader | None
|
Optional loader of the data of the packages. The data
of a package is loaded the first time the package is
looked up or registered into, so creating the registry
and listing its packages cost nothing. A registration into
a package that is not loaded yet loads it first, so the
conflict check and |
None
|
version_source
|
Callable[[str], Iterable[str]] | None
|
Optional function that returns the releases of
a package (given its canonical name), in any order. It is
called only to match a wildcard request (e.g. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a range of |
Example
>>> from feu.compat import CompatRegistry, Target
>>> from feu.compat.registry import VersionRange
>>> registry = CompatRegistry()
>>> registry.register(
... pkg_name="numpy",
... target=Target(python_version="3.11"),
... ranges=[VersionRange("1.23.2", "2.4.6")],
... )
>>> registry.is_valid_version("numpy", "2.0.2", Target(python_version="3.11"))
True
feu.compat.registry.CompatRegistry.state
property
¶
state: Mapping[str, Mapping[Target, list[VersionRange]]]
A read-only view of the registered package constraints, as a
mapping of canonical package name to Target to a list of
VersionRange.
Reading it loads the data of every package of the loader.
feu.compat.registry.CompatRegistry.find_closest_version ¶
find_closest_version(
pkg_name: str, pkg_version: str | None, target: Target
) -> str
Find the closest valid version for a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to check (e.g., |
required |
pkg_version
|
str | None
|
The requested package version: an exact
version (e.g. |
required |
target
|
Target
|
The compatibility target. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The version to install, as a string. |
str
|
|
str
|
|
str
|
|
str
|
|
Raises:
| Type | Description |
|---|---|
UnsupportedVersionError
|
If no package version is valid for the given target, or if no known version satisfies a wildcard request. |
ValueError
|
If |
Example
>>> from feu.compat import CompatRegistry, Target, VersionRange
>>> target = Target(python_version="3.11")
>>> registry = CompatRegistry({"numpy": {target: [VersionRange("1.0.0", "1.26.4")]}})
>>> registry.register_versions("numpy", ["1.0.0", "1.26.4", "2.0.0"])
>>> registry.find_closest_version("numpy", "2.0.0", target)
'1.26.4'
>>> registry.find_closest_version("numpy", "", target)
'1.26.4'
feu.compat.registry.CompatRegistry.get_compatible_versions ¶
get_compatible_versions(
pkg_name: str,
target: Target,
pkg_version: str | None = "",
) -> list[str]
Get the known versions that are valid for a target and satisfy a version request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name (e.g., |
required |
target
|
Target
|
The compatibility target. |
required |
pkg_version
|
str | None
|
The version request: an exact version, a
wildcard (e.g. |
''
|
Returns:
| Type | Description |
|---|---|
list[str]
|
The known versions that lie in a valid range of the target and satisfy the request, in PEP 440 order. The versions are the registered ones or, if there are none, the ones of the version source (downloaded when the method is called). The list is empty if the package has no data, if no version is valid for the target, or if nothing matches. A package that has no configuration for the target accepts every known version. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
>>> from feu.compat import CompatRegistry, Target, VersionRange
>>> target = Target(python_version="3.11")
>>> registry = CompatRegistry({"numpy": {target: [VersionRange("1.0.0", "1.26.4")]}})
>>> registry.register_versions("numpy", ["1.0.0", "1.26.4", "2.0.0"])
>>> registry.get_compatible_versions("numpy", target)
['1.0.0', '1.26.4']
>>> registry.get_compatible_versions("numpy", target, "2.*")
[]
feu.compat.registry.CompatRegistry.get_config ¶
get_config(
pkg_name: str, target: Target
) -> list[VersionRange]
Get the list of valid version ranges for a package and compatibility target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to query (e.g., |
required |
target
|
Target
|
The compatibility target. |
required |
Returns:
| Type | Description |
|---|---|
list[VersionRange]
|
The list of |
list[VersionRange]
|
list if no configuration matches. |
feu.compat.registry.CompatRegistry.get_version_ranges ¶
get_version_ranges(
pkg_name: str, target: Target
) -> list[tuple[Version | None, Version | None]]
Get the valid version ranges as Version objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to query (e.g., |
required |
target
|
Target
|
The compatibility target. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[Version | None, Version | None]]
|
A list of |
Raises:
| Type | Description |
|---|---|
UnsupportedVersionError
|
If no package version is valid for the given target. |
feu.compat.registry.CompatRegistry.has_package ¶
has_package(pkg_name: str) -> bool
Indicate if at least one configuration is registered for a package.
An unknown package is permissive (any version is valid), so this method lets the caller detect that case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to check (e.g., |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
feu.compat.registry.CompatRegistry.is_unsupported ¶
is_unsupported(pkg_name: str, target: Target) -> bool
Indicate if no package version is valid for a target.
This is distinct from a target having no registered
configuration at all: an unconfigured target is treated as
permissive (False), whereas a target explicitly
registered with an empty range list is unsupported
(True).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to check (e.g., |
required |
target
|
Target
|
The compatibility target. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
given target, |
feu.compat.registry.CompatRegistry.is_valid_version ¶
is_valid_version(
pkg_name: str, pkg_version: str | None, target: Target
) -> bool
Check if a package version is valid for a target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to check (e.g., |
required |
pkg_version
|
str | None
|
The package version request: an exact
version, a wildcard (e.g. |
required |
target
|
Target
|
The compatibility target. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool
|
For an exact version: |
|
bool
|
range or unconfigured, |
|
bool
|
no package version is valid for the given target. For a |
|
wildcard |
bool
|
|
bool
|
version satisfies the request (see |
|
bool
|
|
|
bool
|
versions); a package without data gives |
|
bool
|
the latest version: |
|
bool
|
the package and a version is valid for the target; no |
|
bool
|
version is downloaded. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
>>> from feu.compat import CompatRegistry, Target, VersionRange
>>> target = Target(python_version="3.11")
>>> registry = CompatRegistry({"numpy": {target: [VersionRange("1.0.0", "1.26.4")]}})
>>> registry.register_versions("numpy", ["1.0.0", "1.26.4", "2.0.0"])
>>> registry.is_valid_version("numpy", "1.*", target)
True
>>> registry.is_valid_version("numpy", "2.*", target)
False
feu.compat.registry.CompatRegistry.packages ¶
packages() -> list[str]
Get the packages of the registry.
Returns:
| Type | Description |
|---|---|
list[str]
|
The sorted canonical names of the registered packages and of the packages that the loader can load. No data is loaded. |
Example
>>> from feu.compat import CompatRegistry, Target, VersionRange
>>> registry = CompatRegistry({"NumPy": {Target("3.11"): [VersionRange("1.0", None)]}})
>>> registry.packages()
['numpy']
feu.compat.registry.CompatRegistry.register ¶
register(
pkg_name: str,
target: Target,
*,
ranges: list[VersionRange],
exist_ok: bool = False,
) -> None
Register a package configuration for a compatibility target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name to register (e.g., |
required |
target
|
Target
|
The compatibility target. |
required |
ranges
|
list[VersionRange]
|
The list of valid version ranges for this target. An empty list means no version is valid. |
required |
exist_ok
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a configuration already exists for the
given package name and target, and |
ValueError
|
If a bound of a range is not a valid PEP 440 version, or if a minimum is greater than the maximum of the same range. Nothing is registered in that case. |
feu.compat.registry.CompatRegistry.register_many ¶
register_many(
mapping: dict[str, dict[Target, list[VersionRange]]],
exist_ok: bool = False,
) -> None
Register multiple package configurations at once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
dict[str, dict[Target, list[VersionRange]]]
|
Mapping of package name to |
required |
exist_ok
|
bool
|
Forwarded to |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If any configuration already exists for a
given package name and target, and |
feu.compat.registry.CompatRegistry.register_versions ¶
register_versions(
pkg_name: str,
versions: Iterable[str],
*,
exist_ok: bool = False,
) -> None
Register the versions the registry knows for a package.
A wildcard or empty version request (e.g. "2.*") is matched
against these versions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_name
|
str
|
The package name (e.g., |
required |
versions
|
Iterable[str]
|
The known versions, in any order. Duplicates are removed and the versions are sorted by PEP 440 order. |
required |
exist_ok
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If versions are already registered for the
package and |
InvalidVersion
|
If a version is not a valid PEP 440 version. |
Example
>>> from feu.compat import CompatRegistry
>>> registry = CompatRegistry()
>>> registry.register_versions("numpy", ["2.0.0", "1.26.4", "2.0.2"])
feu.compat.registry.DataLoader ¶
Bases: Protocol
Define the interface of the loader of the data of a registry.
A registry asks its loader for the list of packages (cheap) and loads the data of a package the first time it needs it.
feu.compat.registry.DataLoader.load ¶
load(name: str) -> PackageData
Load the data of a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The canonical package name. |
required |
feu.compat.registry.DataLoader.packages ¶
packages() -> Collection[str]
Get the canonical names of the packages that have data.
feu.compat.registry.PackageData ¶
Bases: NamedTuple
Represent the compatibility data of one package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
targets
|
The ranges of each target. |
required |
feu.compat.registry.UnsupportedVersionError ¶
Bases: Exception
Raised when no package version is compatible with a given target.
feu.compat.registry.VersionRange ¶
Bases: NamedTuple
Represent one contiguous range of valid package versions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min
|
The minimum valid package version, or |
required | |
max
|
The maximum valid package version, or |
required |
feu.compat.shipped ¶
Contain the loader of the shipped compatibility data.
The data is one JSON file per package in feu/compat/data/, named by
the canonical package name (PEP 503):
.. code-block:: json
{
"package": "numpy",
"generated": "2026-11-09",
"targets": [
{"python": "3.12", "free_threaded": false, "os": "linux", "arch": "x86_64",
"ranges": [["1.26.0", null]]}
]
}
There is no list of versions: a wildcard request is matched against the
releases downloaded from PyPI (see CompatRegistry), so it never goes
stale. A range whose max is null is open: the latest release was
compatible when the file was generated. The entries are sorted by
(python, free_threaded, os, arch).
The list of packages is the list of files, so a package is added by
running dev/generate_compat_data.py with its name.
feu.compat.shipped.ShippedData ¶
Load the compatibility data shipped in feu/compat/data.
The list of packages is read from the file names (no file is parsed), and a file is parsed when its package is loaded.
Example
>>> from feu.compat.shipped import ShippedData
>>> "numpy" in ShippedData().packages()
True
feu.compat.shipped.ShippedData.load ¶
load(name: str) -> PackageData
Load the data of a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The canonical package name. |
required |
Returns:
| Type | Description |
|---|---|
PackageData
|
The ranges of each target. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If there is no data for the package. |
ValueError
|
If the file is not valid. |
feu.compat.shipped.ShippedData.packages ¶
packages() -> Collection[str]
Get the packages that have shipped data.
Returns:
| Type | Description |
|---|---|
Collection[str]
|
The canonical names of the packages, sorted. |
feu.compat.shipped.format_package_data ¶
format_package_data(
package: str,
generated: str,
targets: Mapping[Target, Sequence[VersionRange]],
) -> str
Format the compatibility data of a package as the text of its JSON file.
The output is deterministic: the same input gives the same text.
The targets are sorted by (python, free_threaded, os, arch),
one target per line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
str
|
The canonical package name. |
required |
generated
|
str
|
The generation date, in ISO 8601 format e.g.
|
required |
targets
|
Mapping[Target, Sequence[VersionRange]]
|
The ranges of each target. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text of the JSON file, ending with a newline. |
Example
>>> from feu.compat import Target, VersionRange
>>> from feu.compat.shipped import format_package_data
>>> target = Target("3.12", False, "linux", "x86_64")
>>> print(
... format_package_data(
... "numpy", "2026-11-09", {target: [VersionRange("1.0", None)]}
... )
... )
{
"package": "numpy",
"generated": "2026-11-09",
"targets": [
{"python": "3.12", "free_threaded": false, "os": "linux", "arch": "x86_64", "ranges": [["1.0", null]]}
]
}
<BLANKLINE>
feu.compat.shipped.parse_package_data ¶
parse_package_data(text: str) -> PackageData
Parse the text of the JSON file of a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text of the JSON file. |
required |
Returns:
| Type | Description |
|---|---|
PackageData
|
The ranges of each target. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the text is not valid JSON or does not have the format of the shipped data. |
Example
>>> from feu.compat.shipped import parse_package_data
>>> data = parse_package_data(
... '{"package": "numpy", "generated": "2026-11-09", "targets": []}'
... )
>>> data.targets
{}
feu.compat.target ¶
Define the compatibility target key used to look up package version constraints.
feu.compat.target.Target
dataclass
¶
Identify the environment a package compatibility constraint applies to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
python_version
|
str
|
The Python version, e.g. |
required |
free_threaded
|
bool
|
|
False
|
os
|
str | None
|
The operating system, e.g. |
None
|
arch
|
str | None
|
The CPU architecture, e.g. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Example
>>> from feu.compat.target import Target
>>> Target(python_version="3.14", free_threaded=True, os="linux", arch="x86_64")
Target(python_version='3.14', free_threaded=True, os='linux', arch='x86_64')
feu.compat.target.resolve_target ¶
resolve_target(
python_version: str | None = None,
*,
free_threaded: bool | None = None,
) -> Target
Resolve the Target of an environment.
The platform (OS and CPU architecture) is always the current one. The Python version and the free-threaded flag can be chosen, e.g. by a CI matrix that checks other Python versions, and fall back to the current interpreter.
If python_version ends with t, the target is a
free-threaded build. In that case, free_threaded=False is
invalid because it contradicts the t suffix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
python_version
|
str | None
|
The Python version, e.g. |
None
|
free_threaded
|
bool | None
|
Whether the target is a free-threaded build.
If not provided, it is inferred from |
None
|
Returns:
| Type | Description |
|---|---|
Target
|
The resolved target, with the current OS and architecture. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Example
>>> from feu.compat.target import resolve_target
>>> target = resolve_target(python_version="3.14t")
>>> target.python_version, target.free_threaded
('3.14', True)
feu.compat.wheel_tags ¶
Contain the parser of the tags of a wheel file name.
The file name is parsed by packaging.utils.parse_wheel_filename,
which expands the compressed tag sets (e.g.
macosx_10_9_x86_64.macosx_11_0_arm64). Each (interpreter, abi,
platform) is then mapped to a WheelTag.
The platforms that feu knows are linux, macos and
windows on x86_64 and arm64 (the vocabulary of Target).
The other platforms (musllinux, win32, i686, armv7l,
ppc64le, ...) and the other interpreters (PyPy, GraalPy, ...) are
out of scope: they give no tag.
feu.compat.wheel_tags.WheelTag
dataclass
¶
Represent one (interpreter, abi, platform) tag of a wheel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
python_version
|
str | None
|
The CPython version (e.g. |
required |
free_threaded
|
bool
|
|
required |
os
|
str | None
|
The operating system ( |
required |
arch
|
str | None
|
The CPU architecture ( |
required |
abi3
|
bool
|
|
False
|
Example
>>> from feu.compat.wheel_tags import WheelTag
>>> WheelTag(python_version="3.12", free_threaded=False, os="linux", arch="x86_64")
WheelTag(python_version='3.12', free_threaded=False, os='linux', arch='x86_64', abi3=False)
feu.compat.wheel_tags.parse_wheel_filename ¶
parse_wheel_filename(filename: str) -> tuple[WheelTag, ...]
Parse the tags of a wheel file name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The wheel file name, e.g.
|
required |
Returns:
| Type | Description |
|---|---|
tuple[WheelTag, ...]
|
The distinct tags of the wheel, sorted. A wheel with a
compressed tag set ( |
Example
>>> from feu.compat.wheel_tags import parse_wheel_filename
>>> parse_wheel_filename("numpy-2.3.0-cp312-cp312-macosx_11_0_universal2.whl")
(WheelTag(python_version='3.12', free_threaded=False, os='macos', arch='arm64', abi3=False),
WheelTag(python_version='3.12', free_threaded=False, os='macos', arch='x86_64', abi3=False))