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:
- Minimal Dependencies: Depends only on
plum-dispatch, not on JAX, NumPy, or Astropy - Extensibility: Allows third-party packages to register their own implementations
- Type Safety: Provides a clear contract for what functions exist and what they should do
- 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:
- Functions can have multiple implementations based on argument types
- You can register your own implementations for custom types
- 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:
- unxt-api API Reference
- Extending unxt Guide
- Main unxt Documentation
- plum Documentation - Multiple dispatch library
Contributing
Contributions are welcome! Please see the main unxt repository for contributing guidelines.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unxt_api-1.8.1.tar.gz.
File metadata
- Download URL: unxt_api-1.8.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8dd6a5f9846d3d9685218fefa811f1a8b130f016481beaba0fb432e1dc93b6e
|
|
| MD5 |
6e19615327ca82d71c274368a4e348a1
|
|
| BLAKE2b-256 |
5e50034a6d8571c060a2d05eacc66abd0d44ee7bd37969fd82d07ab4011ace02
|
Provenance
The following attestation bundles were made for unxt_api-1.8.1.tar.gz:
Publisher:
cd-unxt-api.yml on GalacticDynamics/unxt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unxt_api-1.8.1.tar.gz -
Subject digest:
e8dd6a5f9846d3d9685218fefa811f1a8b130f016481beaba0fb432e1dc93b6e - Sigstore transparency entry: 774094694
- Sigstore integration time:
-
Permalink:
GalacticDynamics/unxt@221fe4d23c23a09ea951623a6024dfc7d8f83f6e -
Branch / Tag:
refs/tags/unxt-api-v1.8.1 - Owner: https://github.com/GalacticDynamics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd-unxt-api.yml@221fe4d23c23a09ea951623a6024dfc7d8f83f6e -
Trigger Event:
release
-
Statement type:
File details
Details for the file unxt_api-1.8.1-py3-none-any.whl.
File metadata
- Download URL: unxt_api-1.8.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acdb7bf813326db241e3c2bc0342f71148c2767004af590950a42dbbd59f7e15
|
|
| MD5 |
ff86ed137e9b07d1255121a34bdf6a0d
|
|
| BLAKE2b-256 |
43da616b74161e28e9ed380f2477a6a51ce1ca493aad5df6dedb119483109275
|
Provenance
The following attestation bundles were made for unxt_api-1.8.1-py3-none-any.whl:
Publisher:
cd-unxt-api.yml on GalacticDynamics/unxt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unxt_api-1.8.1-py3-none-any.whl -
Subject digest:
acdb7bf813326db241e3c2bc0342f71148c2767004af590950a42dbbd59f7e15 - Sigstore transparency entry: 774094695
- Sigstore integration time:
-
Permalink:
GalacticDynamics/unxt@221fe4d23c23a09ea951623a6024dfc7d8f83f6e -
Branch / Tag:
refs/tags/unxt-api-v1.8.1 - Owner: https://github.com/GalacticDynamics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd-unxt-api.yml@221fe4d23c23a09ea951623a6024dfc7d8f83f6e -
Trigger Event:
release
-
Statement type: