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.1.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.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: unxt_api-1.9.1.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.1.tar.gz
Algorithm Hash digest
SHA256 7970f21973bca464f6af166f885d3f8b8bfd1d103e8ff51bd2af3f88f6388da7
MD5 4022d797a4247d548eedfeb678d25f72
BLAKE2b-256 010fffaac1ef3d409125a07b8d77b1b39a8f7466b979945ec1b2764cb4c40ec3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: unxt_api-1.9.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1b6848fcf6a08aafc6283df43d0d1a5cab42222ae6278e2b5096ed3dafae885e
MD5 2333608ed367531475262d21fcac79dc
BLAKE2b-256 fa150bc89489a3aceec2508439a7bc4cc84c7a72f8f3366040b017c1695068f3

See more details on using hashes here.

Provenance

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