Skip to main content

notwork

Python functions for when your network might notwork.

Read the documentation at cariad.github.io/notwork.

Installation

notwork needs Python 3.14 or later, and has no dependencies.

pip install notwork

Or with uv:

uv add notwork

Usage

Check a port number

is_port_in_range says whether a port number is valid, and check_port_is_in_range raises PortOutOfRangeError when it isn't.

from notwork import check_port_is_in_range, is_port_in_range

is_port_in_range(8000)
# True

check_port_is_in_range(70000)
# PortOutOfRangeError: Port 70000 must be 1-65535

Check for IPv6

has_ipv6 says whether this machine can bind ::1, the IPv6 loopback address.

from notwork import has_ipv6

has_ipv6()
# True when this machine can bind ::1

Claim a port

claim_port claims a port on every address that localhost can mean, and returns a ClaimedPort to listen on.

If another program is already using the port on localhost, it raises PortInUseError.

On Linux, the sockets are already listening when they're returned. On Windows, another program can still bind the port on :: with a socket that accepts IPv4 and IPv6 at once.

from notwork import claim_port

with claim_port(8000) as port:
    # Bound to 127.0.0.1, and ::1 when there's IPv6
    for sock in port.sockets:
        sock.listen()

# Leaving the `with` block closed the port.

Find a free port

free_port returns a port that claim_port can claim right now, on every address that localhost can mean.

It doesn't hold the port, so another program can take it before you use it: it's intended for tests and simple local tools.

from notwork import claim_port, free_port

with claim_port(free_port()) as port:
    for sock in port.sockets:
        sock.listen()

Metadata

Release files for notwork 1.2.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 notwork 1.2.0
File Size Uploaded Provenance Actions
notwork-1.2.0.tar.gz 53.9 kB With provenance Details for notwork-1.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 66.2 kB

Release files / notwork-1.2.0.tar.gz

Download URL notwork-1.2.0.tar.gz
Size 53.9 kB
Tags Source
SHA-256 checksum
How to use checksums
568e97e9fd3370ac7741bc1dff9d27eb39b143661e5da4d69bbb212943a1972f
BLAKE2b-256 checksum
How to use checksums
796bd8446958333ac92fd5e63bc7499d28d8d5c76f939854af84e274f7f86a9f
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 8, 2026.

Transparency log

Release files / notwork-1.2.0-py3-none-any.whl

Download URL notwork-1.2.0-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09604b5548d7c8dbdb3dd67b48946cb0f0d87961a1e97bf5b8c18d84a5d14c17
BLAKE2b-256 checksum
How to use checksums
c7aade949381dfa95e7d284860c05f6f201af341023cbc8dc13ddb9d3098b564
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 8, 2026.

Transparency log

Security for notwork 1.2.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 notwork-1.2.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 8, 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