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

Uploaded Python 3

File details

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

File metadata

  • Download URL: unxt_api-1.8.2.tar.gz
  • Upload date:
  • Size: 19.5 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.8.2.tar.gz
Algorithm Hash digest
SHA256 35c8cf59b6f278209d7e33a7bb8a461d85c6d341f419ec55538f5e843a86c9de
MD5 89ac9ad111f65c5fcc15aae40d80843c
BLAKE2b-256 78e6acba5262c01505a794f28c49bd07d9316c807432404dde02e940b47c5e57

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: unxt_api-1.8.2-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.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f43b70435415f60a39142b8382744158c320644197b9860daaabf35a610ce621
MD5 8b1cd2a33b935fa1179f77ab5cb3e915
BLAKE2b-256 7262c7622e08ef68bf0d063ab88c71d6c08f78618c706c5256fdec7865391151

See more details on using hashes here.

Provenance

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