Skip to main content

Abstract dispatch API definitions for unxt

Project description

unxt-api

Abstract dispatch API for unxt.

unxt-api defines the abstract dispatch interfaces that unxt and other packages implement. It provides a minimal dependency foundation for packages that want to define or use unxt's multiple-dispatch-based API without pulling in the full unxt implementation.

The unxt-api package serves several important purposes:

  1. Minimal Dependencies: Depends only on plum-dispatch, not on JAX, NumPy, or Astropy
  2. Extensibility: Allows third-party packages to register their own implementations
  3. Type Safety: Provides a clear contract for what functions exist and what they should do
  4. Separation of Concerns: API definitions are separate from implementation details

Installation

pip install unxt-api

Or with uv:

uv add unxt-api

Core API

The unxt-api package defines abstract dispatch functions organized by domain:

  • Dimensions (dimension, dimension_of) - Working with physical dimensions
  • Units (unit, unit_of) - Constructing and inspecting units
  • Quantities (uconvert, ustrip, is_unit_convertible, wrap_to) - Unit conversion and quantity operations
  • Unit Systems (unitsystem_of) - Inspecting unit systems

Using Multiple Dispatch

All functions in unxt-api use plum for multiple dispatch. This means:

  1. Functions can have multiple implementations based on argument types
  2. You can register your own implementations for custom types
  3. Type annotations drive dispatch - the runtime types of arguments determine which implementation runs

Viewing All Implementations

To see all registered implementations of a function:

import unxt as u

# View all dimension() implementations
u.dimension.methods

# View all uconvert() implementations
u.uconvert.methods

# View all unit_of() implementations
u.unit_of.methods

Registering Custom Implementations

You can extend unxt-api's dispatch system with your own types:

from plum import dispatch
import unxt_api as u


class MyCustomQuantity:
    def __init__(self, value, unit_str):
        self.value = value
        self.unit_str = unit_str


# Register implementation for your type
@dispatch
def unit_of(obj: MyCustomQuantity, /):
    """Get unit from MyCustomQuantity."""
    return u.unit(obj.unit_str)


# Now it works with the dispatch system
my_q = MyCustomQuantity(5.0, "m")
u.unit_of(my_q)  # Unit("m")

Integration with unxt

The unxt package provides the concrete implementations of all unxt-api functions. When you use:

import unxt as u

q = u.Q(5, "m")
u.uconvert("km", q)

The u.uconvert function is the implementation registered by unxt for the abstract unxt_api.uconvert function.

Documentation

For comprehensive documentation, examples, and extension guides, see:

Contributing

Contributions are welcome! Please see the main unxt repository for contributing guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unxt_api-1.11.0.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unxt_api-1.11.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file unxt_api-1.11.0.tar.gz.

File metadata

  • Download URL: unxt_api-1.11.0.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for unxt_api-1.11.0.tar.gz
Algorithm Hash digest
SHA256 5882f11d54dd5d6557abeba915b522ad1dae852fbe6df9f1bca6e8070e877688
MD5 e4fe72976154deda80b73d3b32b0e86a
BLAKE2b-256 60d4057ee928ebd3a9f55b1d6a8c708ac6b59e6593c0e0f0c90c23e1f908a530

See more details on using hashes here.

Provenance

The following attestation bundles were made for unxt_api-1.11.0.tar.gz:

Publisher: cd-unxt-api.yml on GalacticDynamics/unxt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file unxt_api-1.11.0-py3-none-any.whl.

File metadata

  • Download URL: unxt_api-1.11.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for unxt_api-1.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 69d327184d08588457fda37accc74ae3db244eb786f9851ad683f69174f06ec9
MD5 739759e185b0597055a3fc214314d59b
BLAKE2b-256 685fd568994f170c4bf0892ecdff255f4c0e0a4ce7eec40f888f3ac0eb021363

See more details on using hashes here.

Provenance

The following attestation bundles were made for unxt_api-1.11.0-py3-none-any.whl:

Publisher: cd-unxt-api.yml on GalacticDynamics/unxt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page