Skip to main content

Supported Python Versions pypi version Last commit Coverage Downloads

Python Compatibility Checker for Package Authors

Version guard your Python package • Check OS compatibility • Prevent runtime errors

Ensure your Python package runs on the right versions, warn users about untested versions, and gracefully handle incompatible environments.

Compatibility is a lightweight, zero-dependency library that helps Python package authors and library developers provide a better user experience by checking Python version compatibility, operating system compatibility (Linux, macOS, Windows), and gently reminding users to update. Uses Python's standard gettext for translations and follows PEP 561 (typed package). Perfect for PyPI package maintainers who want to replace cryptic errors with helpful guidance to users.

Why Use This Library?

  • Clear messages instead of cryptic errors - Tell users when they run your package on an incompatible Python version
  • Zero dependencies - Uses only Python's standard library
  • Fully typed - Complete type hints (PEP 484) for better IDE support
  • Multilingual - Built-in English and German messages, plus AI-translated French, Dutch, and Spanish
  • User-friendly warnings - Inform users about untested Python versions
  • OS compatibility checks - Validate Linux, macOS, and Windows support
  • Update reminders - Gently encourage users to check for package updates
  • High test coverage - 100% coverage (statements and branches) for reliability

Table of Contents

What It Does

  1. Python Version Validation - Check if the running Python interpreter meets minimum requirements and isn't in your list of incompatible versions. Raises RuntimeError for incompatible versions.
  2. Untested Version Warnings - Warn users when running your package on Python versions newer than you've tested.
  3. End-of-Life Warnings - Optionally warn users whose Python version has reached its end of life and no longer receives security updates (built-in dates, no network access).
  4. Package Version Logging - Log package name, version, and release date for better debugging.
  5. Privacy-Friendly Update Reminders - Optionally remind users to check for updates after N days (without phoning home or checking if updates exist).
  6. Operating System Compatibility - Validate whether the OS (Linux, macOS, Windows) is fully supported, partially supported, or incompatible.

All messages are available in English and German (plus AI-translated French, Dutch, and Spanish), selectable per-instance. See Translations.

What It Does Not Do

  • No update lookup - The update reminder only counts the days since your release date. It never contacts PyPI or any other server, so it cannot tell whether a newer version exists.
  • No dependency checks - It checks the Python interpreter and the operating system, not the versions of other installed packages. Declare those as dependencies in your pyproject.toml, so pip resolves them.
  • No patch versions - Python versions are matched on major and minor version, optionally with the release level (like '3.12' or '3.12.beta'). You cannot target a single patch release such as 3.12.1.
  • No OS versions or distributions - Operating systems are only distinguished as Linux, MacOS, and Windows.
  • No protection before your code is imported - The check runs in your constructor. An error while Python imports your modules comes first (see Avoid running your package with an incompatible version of Python).

Key Features

  • Zero Dependencies: Pure Python stdlib - no external packages required
  • Type Safe: Full type hints (PEP 484) for excellent IDE integration
  • Well Tested: 100% coverage (statements and branches), enforced in CI
  • Python 3.10+: Supports Python 3.10 through 3.15.

Installation

pip install compatibility

That's it! No other dependencies to manage.

Quick Start

Note: To see compatibility's informational messages and warnings, configure logging first:

import logging
logging.basicConfig(level=logging.INFO)

Here's a minimal example to get started:

from datetime import date
import logging
import compatibility

# Configure logging to see messages
logging.basicConfig(level=logging.INFO)

class MyPackage:
    def __init__(self):
        compatibility.Check(
            package_name='my_package',
            package_version='1.0.0',
            release_date=date(2025, 1, 1),
            python_version_support={
                'min_version': '3.10',
                'incompatible_versions': [],
                'max_tested_version': '3.15'
            }
        )

MyPackage()  # The check runs when the class is instantiated

Output:

INFO:compatibility:You are using my_package 1.0.0 (released: 2025-01-01)

Extended Example

Here's a more complete example using all optional features:

from datetime import date
import logging
import compatibility

logging.basicConfig(level=logging.INFO)

class MyAdvancedPackage:
    def __init__(self):
        compatibility.Check(
            package_name='my_advanced_package',
            package_version='2.0.0',
            release_date=date(2025, 1, 15),
            python_version_support={
                'min_version': '3.10',
                'incompatible_versions': ['3.13.alpha'],  # e.g. a pre-release with a known bug
                'max_tested_version': '3.15'
            },
            nag_over_update={
                'nag_days_after_release': 90,  # Start reminding after 90 days
                'nag_in_hundred': 25            # Show reminder 25% of the time
            },
            language_messages='en',  # 'en', 'de', 'fr', 'nl', 'es', or 'auto'
            system_support={
                'full': {'Linux', 'MacOS'},     # Fully tested
                'partial': {'Windows'},          # Should work, less tested
                'incompatible': set()            # No known incompatibilities
            },
            warn_eol=True  # Warn if the running Python has reached its end of life
        )

MyAdvancedPackage()

Detailed Usage

⚠️ Important: Where to Call Compatibility

Call compatibility.Check() in your class constructor, NOT in __init__.py

# ❌ DON'T DO THIS (in __init__.py)
import compatibility
compatibility.Check(...)  # Runs at import time, before user configures logging

# ✅ DO THIS (in your class __init__)
class MyClass:
    def __init__(self):
        compatibility.Check(...)  # Runs when instantiated, after logging is configured

Why? If you call it in __init__.py, it runs immediately on import, usually before the application has configured logging. Its messages are then lost: the compatibility logger has no handler of its own, so nothing is shown until logging is set up. Calling it in the class constructor lets users set up logging first. It also keeps your package importable on an incompatible system (for example for documentation tools), as the RuntimeError is only raised when your class is used.

Complete Example

Here's a real-world example from the salted package:

# [...]
from datetime import date
import logging
# [...]

import compatibility
# [...]


class Salted:
    """Main class. Creates the other Objects, starts workers,
       collects results and starts the report of results. """

    VERSION = '0.6.1'

    def __init__(self,
                 [...]) -> None:

        compatibility.Check(
            package_name='salted',
            package_version=self.VERSION,
            release_date=date(2025, 6, 18),
            python_version_support={
                'min_version': '3.10',
                'incompatible_versions': [],
                'max_tested_version': '3.15'},
            nag_over_update={
                    'nag_days_after_release': 30,
                    'nag_in_hundred': 50},
            language_messages='en',
            system_support={
                'full': {'Linux', 'MacOS', 'Windows'}
            })

These settings ensure the package runs on Python 3.10 or higher, with testing confirmed through Python 3.15. Salted in that specific version is a relatively young package that will receive frequent updates. So beginning a month after the release this will nag the user over looking for an update every second time - provided the user activated logging.

Recipes

The test suite runs every example in this section, as well as the Quick Start and the Extended Example.

Command-Line Tool: Configure Logging First

In a command-line tool, configure logging first and create the class that runs the check afterwards. Otherwise the messages are lost:

import argparse
from datetime import date
import logging

import compatibility


class MyTool:
    def __init__(self):
        compatibility.Check(
            package_name='my_tool',
            package_version='1.0.0',
            release_date=date(2025, 1, 1))


def main(argv=None):
    parser = argparse.ArgumentParser(prog='my_tool')
    parser.add_argument('--verbose', action='store_true')
    args = parser.parse_args(argv)
    # Configure logging before anything creates MyTool:
    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
    MyTool()


if __name__ == '__main__':
    main()

Output:

INFO:compatibility:You are using my_tool 1.0.0 (released: 2025-01-01)

Warn Instead of Raising

By default an incompatible Python version or operating system raises RuntimeError. With on_incompatible='warn' it only logs a warning, and your package keeps running. Use this if your users should decide whether to continue:

from datetime import date
import logging

import compatibility

logging.basicConfig(level=logging.INFO)


class MyPackage:
    def __init__(self):
        compatibility.Check(
            package_name='my_package',
            package_version='1.0.0',
            release_date=date(2025, 1, 1),
            python_version_support={
                'min_version': '3.10',
                'incompatible_versions': [],
                'max_tested_version': '3.15'},
            system_support={'full': {'Linux', 'MacOS', 'Windows'}},
            on_incompatible='warn')


MyPackage()

With on_incompatible='ignore' the message is only logged at DEBUG level.

Typed Configuration

The parameter dictionaries have matching TypedDict types: PythonVersionSupport, SystemSupport, and NagOverUpdate. Annotate your configuration with them, and a type checker such as mypy reports a misspelled or missing key before your code runs:

from datetime import date
import logging

import compatibility
from compatibility import NagOverUpdate, PythonVersionSupport, SystemSupport

logging.basicConfig(level=logging.INFO)

PYTHON_SUPPORT: PythonVersionSupport = {
    'min_version': '3.10',
    'incompatible_versions': [],
    'max_tested_version': '3.15',
}
SYSTEM_SUPPORT: SystemSupport = {'full': {'Linux', 'MacOS', 'Windows'}}
NAG: NagOverUpdate = {'nag_days_after_release': 90, 'nag_in_hundred': 25}


class MyPackage:
    def __init__(self) -> None:
        compatibility.Check(
            package_name='my_package',
            package_version='1.0.0',
            release_date=date(2025, 1, 1),
            python_version_support=PYTHON_SUPPORT,
            system_support=SYSTEM_SUPPORT,
            nag_over_update=NAG)


MyPackage()

Parameters

Required Parameters

  • package_name: the name of your package.
  • package_version: the version number of your package as a string.
  • release_date: a datetime.date (like date(2021, 1, 1)), or a string in the format YYYY-MM-DD (like '2021-01-01'; leading zeros are optional). A datetime.datetime is accepted too; its time is ignored.

Optional Parameters

For python_version_support, nag_over_update, and system_support, leaving the parameter out, passing None, or passing an empty dictionary {} all skip that check. Any other value that is not a dictionary raises a ValueError.

  • python_version_support: requires a dictionary with the three following keys:

    • min_version: a string with the number of the oldest supported version (like '3.10').
    • incompatible_versions: a list of incompatible versions that, by default, raise the RuntimeError exception if they try to run your package (configurable with on_incompatible).
    • max_tested_version: the latest version of the interpreter you successfully tested your code with.
  • nag_over_update (optional): requires a dictionary with the two following keys:

    • nag_days_after_release: wait this number of days (int) since the release before reminding users to check for an update.
    • nag_in_hundred: Whether to nag over a possible update is random, but this sets the probability in the form how many times (int) out of a hundred starts the message is logged. Accordingly 100 means every time.
  • language_messages (optional): the language of the messages logged by this — en (English), de (German), fr (French), nl (Dutch), es (Spanish), or auto. Defaults to en. Any explicit code selects that language; auto detects the language from the user's environment locale (LANGUAGE/LC_ALL/LC_MESSAGES/LANG) and falls back to English when no matching catalog is available. See Translations for the quality status of each language.

  • system_support (optional): allows you to state the level of compatibility between your code and different Operating System groups. This is purposefully done on a very high level: valid inputs are only 'Linux', 'MacOS', and 'Windows' and not specific versions and distributions. The dictionary allows three keys with a set as value each:

    • full: The set of operating systems that are tested on production level.
    • partial: The set of systems that should work, but are not as rigorously tested as those with full support. A system found running here logs a warning.
    • incompatible: The set of systems of which you know they will fail to run the code properly. By default, if an OS in this set tries to run the code, this will yield a RuntimeError exception (configurable with on_incompatible).

    An operating system may appear in only one of the three sets; listing it in two raises ParameterContradiction.

  • on_incompatible (optional): what to do when the running Python version or operating system is incompatible. One of:

    • 'raise' (default): raise a RuntimeError — the current behaviour.
    • 'warn': log a warning and continue.
    • 'ignore': continue silently (logged at DEBUG only). You take responsibility for running in an unsupported environment.
  • warn_eol (optional): set to True to log a warning if the running Python version has reached its end of life and no longer receives security updates. Defaults to False. The end-of-life dates are built in, so the check works offline; a Python version newer than the installed release of this library is not reported.

System Support Behavior:

System in... Log Level Exception Raised? Description
full DEBUG No Production-tested, fully supported
partial WARNING No Should work, but less rigorously tested
incompatible ERROR Yes (RuntimeError) Known to fail
Not listed INFO No Support status unknown

The incompatible row reflects the default on_incompatible='raise'. With 'warn' it logs a warning and continues; with 'ignore' it continues silently.

Version strings

For compatibility checks three elements of the version string are recognized:

  • The major version
  • The minor version
  • The release level (either alpha, beta, candidate, or final)

If you provide all three elements (for example '3.10.alpha') only this very specific version will be matched. If you provide only the first two (in this case '3.10'), all release levels of this version will match. So assume your code would have issues with Python 3.5.beta and you list that exact string as an incompatible version. If you are running the script under 3.5.alpha nothing will happen. If you listed it by using the string '3.5' running the script with 3.5.alpha (or any other release level of 3.5) will raise the RuntimeError exception.

However, min_version and max_tested_version ignore the release level part.

Avoid running your package with an incompatible version of Python

In the pyproject.toml file of your package, set requires-python in the [project] table (for example requires-python = ">=3.10") to tell pip about the supported versions of the interpreter. This blocks installation on incompatible systems. However, users can circumvent this with pip's --ignore-requires-python flag. More likely is a system upgrade that replaces the interpreter with an incompatible version through the system's package manager.

If you define incompatible versions while initializing the compatibility package, you add another layer of control. Even if your user ended up with an incompatible interpreter, that will trigger a RuntimeError exception once the user tries to run your package.

This works only if Python gets as far as running the check:

  • compatibility itself runs on Python 3.10 or newer. On an older interpreter it cannot import, so it cannot show any message.
  • Your package's modules are imported before your constructor runs. If one of them uses syntax or a feature that the running Python lacks, the user gets a SyntaxError or ImportError before the check. For example, except* and typing.Self need Python 3.11 and class C[T]: needs Python 3.12.

Logging

The compatibility package uses Python's standard logging module with a dedicated logger named 'compatibility'. This allows you to control the verbosity of compatibility messages independently from your application's logging.

Basic Usage

By default, compatibility messages propagate to the root logger, so they will appear if you have configured logging in your application:

import logging
logging.basicConfig(level=logging.INFO)

# You will see compatibility's INFO, WARNING, and ERROR messages

Fine-Grained Control

You can selectively control compatibility's log level:

import logging

# Configure your application's logging
logging.basicConfig(level=logging.INFO)

# Silence compatibility warnings (only show errors)
logging.getLogger('compatibility').setLevel(logging.ERROR)

# Or make compatibility more verbose (show debug messages)
logging.getLogger('compatibility').setLevel(logging.DEBUG)

Message Levels

The compatibility package logs at different levels:

  • DEBUG: Informational messages about full platform support
  • INFO: Package version information and update reminders
  • WARNING: Running newer Python than tested, a Python past its end of life (with warn_eol=True), or partial platform support
  • ERROR: Incompatible Python version or operating system (also raises exceptions)

Example Messages

With logging configured, the messages look like the following (the level/name prefix comes from your logging setup; here it is Python's basicConfig default):

DEBUG:compatibility:my_package fully supports Linux.
INFO:compatibility:You are using my_package 1.0.0 (released: 2025-01-01)
INFO:compatibility:Your version of my_package was released 120 days ago. Please check for updates.
WARNING:compatibility:my_package has only partial support on Windows.
WARNING:compatibility:You are running Python 3.16.final, but your version of my_package is only tested up to 3.15. Please check for updates.
WARNING:compatibility:Python 3.10 reached its end of life (2026-10-01) and no longer receives security updates. Please upgrade to a newer version of Python.
ERROR:compatibility:This version of my_package is incompatible with Windows!

An incompatible Python version (below min_version, or listed in incompatible_versions) is logged the same way and, with the default on_incompatible='raise', additionally raises RuntimeError:

ERROR:compatibility:You use Python 3.10.final, but need at least Python 3.11 to run my_package.

The same messages appear translated when you select another language (for example language_messages='de').

Translations

Each available language has one of the following quality levels:

Language Code Status
English en Default / source language
German de Reviewed by a native speaker
French fr Translated by AI (pending native review)
Dutch nl Translated by AI (pending native review)
Spanish es Translated by AI (pending native review)

The AI-translated languages are marked as such in the message catalog (.po) header until a native speaker has reviewed them. Corrections and reviews from native speakers are very welcome.

To add a new language, start from the template compatibility/locales/compatibility.pot, which lists every message.

Set language_messages='auto' to follow the user's environment locale (LANGUAGE/LC_ALL/LC_MESSAGES/LANG); if no matching catalog is available, messages fall back to English.

Exceptions

The compatibility package may raise the following exceptions:

  • RuntimeError: Raised when the Python version or operating system is incompatible with your package.
  • ValueError: Raised when invalid parameters are provided to the Check class.
  • compatibility.err.BadDate: Raised when the release_date parameter contains an invalid or malformed date.
  • compatibility.err.BadDateType: Raised when the release_date parameter is neither a datetime.date nor a string. Subclasses TypeError.
  • compatibility.err.ParameterContradiction: Raised when conflicting parameters are provided (e.g., a system marked as both fully supported and incompatible).

Use Cases

When Your Package Requires Specific Python Versions

Use min_version to stop your package from running on older Python versions that lack features it relies on at runtime, for example a standard library function or behavior added in a later version. A check in your constructor cannot catch syntax your modules use, as that fails on import (see Avoid running your package with an incompatible version of Python).

When You Know Specific Python Versions Are Broken

Use incompatible_versions to block specific Python versions where your package has known issues (e.g., bugs in Python itself, or dependencies that break on certain versions).

When Users Report Bugs on Untested Python Versions

Use max_tested_version to warn users when they're running your package on newer Python versions you haven't tested yet. This helps manage expectations and reduces false bug reports.

When Your Users Still Run an Unmaintained Python

Set warn_eol=True to warn users whose Python version has reached its end of life. Such a version gets no security fixes anymore, even if your package still supports it. The warning is opt-in, so it never surprises users of a package that did not ask for it.

When You Drop Support for Old Python Versions

After dropping (for example) Python 3.10 support, set min_version to '3.11'. Users who still end up on 3.10 get a clear error message instead of a cryptic runtime failure, as long as your package still imports on 3.10.

When Your Package Only Works on Certain Operating Systems

Use system_support to declare which operating systems (Linux, macOS, Windows) are fully supported, partially supported, or incompatible. For example, if your package uses Linux-specific system calls.

When You Want Users to Update Old Package Versions

Use nag_over_update to gently remind users to check for updates after your package has been out for a while, without any privacy concerns (no network calls, no tracking).

Metadata

Release files for compatibility 2.4.0

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

Source distribution (sdist)

Source distribution for compatibility 2.4.0
File Size Uploaded Provenance Actions
compatibility-2.4.0.tar.gz 38.0 kB With provenance Details for compatibility-2.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 84.6 kB

Release files / compatibility-2.4.0.tar.gz

Download URL compatibility-2.4.0.tar.gz
Size 38.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ec75d56008e458698a8822073c137b1c437722475623e86d77c469b587e23fa3
BLAKE2b-256 checksum
How to use checksums
f8a41e2d87c283753a4f94f9f4746dcd87b3a3fcc85e059dc1ec2849bda96a7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / compatibility-2.4.0-py3-none-any.whl

Download URL compatibility-2.4.0-py3-none-any.whl
Size 46.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3357f1921094f5e0576c4f4dda0b39e46d545c31ba01066d2e6b2bd770babb9e
BLAKE2b-256 checksum
How to use checksums
8df2d7a35fa9476951bf29068aefd7ad2181c1798d868d4de38b691227520b30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Security for compatibility 2.4.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for compatibility-2.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

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.

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