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.9.0.tar.gz (19.6 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.9.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: unxt_api-1.9.0.tar.gz
  • Upload date:
  • Size: 19.6 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.9.0.tar.gz
Algorithm Hash digest
SHA256 6faec0fcea6d37b5db90bfa9875c273bf88e1638cc924a4cf8417afdf7decd7e
MD5 abfb0b0eb26d713d0a94066cd2d713cf
BLAKE2b-256 139af906c16e01dec4d94b02f79268002834df3b113b72dead4be4ff07123584

See more details on using hashes here.

Provenance

The following attestation bundles were made for unxt_api-1.9.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.9.0-py3-none-any.whl.

File metadata

  • Download URL: unxt_api-1.9.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 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.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92abf1007ba7817881f9bb07ff5dd158fdf4a2b538f0b2411e1feadc38e380e7
MD5 0626489583ae99ccc19325448312f0b6
BLAKE2b-256 c1d2f088521a808508d09ee9dc9ff162ac0039abbed6b7d5f5eb9ec16d0118c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for unxt_api-1.9.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