Skip to main content

ub-needs-exchange

A library for the sphinx-needs family, which the extensions pull in – not a Sphinx extension, and nothing to add to conf.py.

It is the record of the needs.json exchange format: the file sphinx-needs’ needs builder writes, its needimport directive and needs_external_needs option read, and ubCode both writes and reads. It holds the part of that format more than one tool reads, so that it is read one way:

  • the envelope – the project, the current_version, the versions, and a format_version;

  • selecting a version – the one asked for, or the file’s current one;

  • the records – each keyed by its id, with the legacy description read as content and the version’s needs_schema defaults merged under it.

Standard library only: no Sphinx, no docutils, no sibling distribution. A converter or a build action that runs without the documentation toolchain can use it.

Reading a file

from ub_needs_exchange import ExchangeError, load

try:
    version = load("needs.json").select_version(None)  # or a version's name
except ExchangeError as err:
    err.code       # what is wrong, e.g. "version_not_found"
    err.message    # for a person
else:
    records = version.records()
    for record in records:
        record.key        # the need's id
        record.fields     # its fields, schema defaults merged under them
    version.diagnostics   # findings about the version -- report them, or not
    [d for r in records for d in r.diagnostics]   # findings about each record

Every refusal is an ExchangeError whose code names the rule that was broken; every finding is a Diagnostic with a code, the path of what was found in the file, and a message.

Consumers decide the policy

This package decides nothing a consumer has reason to decide differently: which fields a project defines and which of a record’s keys it takes, the ids it accepts, the prefix it adds, how a record becomes a need, and whether a finding deserves a warning are each tool’s own.

The contract

design/exchange-contract.md is the normative specification, and tests/fixtures/needs_json_reading_conformance.toml is its executable half: a corpus of needs.json files and expected results that this package’s suite runs, and that ubCode is to vendor and run against its own readers.

Metadata

Release files for ub-needs-exchange 1.0.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 ub-needs-exchange 1.0.0
File Size Uploaded
ub_needs_exchange-1.0.0.tar.gz 7.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ub-needs-exchange 1.0.0
File Interpreter ABI Platform
ub_needs_exchange-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.7 kB

Release files / ub_needs_exchange-1.0.0.tar.gz

Download URL ub_needs_exchange-1.0.0.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8c58c25754d4e8d04dd241edac4f45b2df0a5bacd41edb18864f012bd905b957
BLAKE2b-256 checksum
How to use checksums
5c7b787f9569ced23c8c380f9b3b67eac70bedf202b7992c30e049d3cd106de7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ub_needs_exchange-1.0.0-py3-none-any.whl

Download URL ub_needs_exchange-1.0.0-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd644364eaeb0a3305764c2f4280a2eecb6a039f3010ccea6a524209d7f5bd55
BLAKE2b-256 checksum
How to use checksums
f7d487033681e4eddddbc01d9a5436ca9c35b2c633b26191a50b49c4899032df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

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