Skip to main content

ucon

Pronounced: yoo · cahn

tests codecov publish

A lightweight, unit-aware computation library for Python — built on first-principles.

Documentation · Quickstart · API Reference


What is ucon?

ucon helps Python understand the physical meaning of your numbers. It treats units, dimensions, and scales as first-class objects — enforcing physics, not just labels.

from ucon import units

length = units.meter(5)
time = units.second(2)

speed = length / time      # <2.5 m/s>
invalid = length + time    # raises: incompatible dimensions

Installation

pip install ucon

With extras:

pip install ucon[pydantic]  # Pydantic v2 integration
pip install ucon[mcp]       # MCP server for AI agents

Quick Examples

Unit Conversion

from ucon import units, Scale

km = Scale.kilo * units.meter
distance = km(5)

print(distance.to(units.mile))  # <3.107... mi>

Dimensional Safety

from ucon import Number, Dimension, enforce_dimensions

@enforce_dimensions
def speed(
    distance: Number[Dimension.length],
    time: Number[Dimension.time],
) -> Number:
    return distance / time

speed(units.meter(100), units.second(10))   # <10.0 m/s>
speed(units.second(100), units.second(10))  # raises ValueError

Pydantic Integration

from pydantic import BaseModel
from ucon.pydantic import Number

class Measurement(BaseModel):
    value: Number

m = Measurement(value={"quantity": 9.8, "unit": "m/s^2"})
print(m.model_dump_json())
# {"value": {"quantity": 9.8, "unit": "m/s^2", "uncertainty": null}}

MCP Server for AI Agents

Configure in Claude Desktop:

{
  "mcpServers": {
    "ucon": {
      "command": "uvx",
      "args": ["--from", "ucon[mcp]", "ucon-mcp"]
    }
  }
}

AI agents can then convert units, check dimensions, and perform factor-label calculations with dimensional validation at each step.


Features

  • Dimensional algebra — Units combine through multiplication/division with automatic dimension tracking
  • Scale prefixes — Full SI (kilo, milli, micro, etc.) and binary (kibi, mebi) prefix support
  • Uncertainty propagation — Errors propagate through arithmetic and conversions
  • Pseudo-dimensions — Semantically isolated handling of angles, ratios, and counts
  • Pydantic v2 — Type-safe API validation and JSON serialization
  • MCP server — AI agent integration with Claude, Cursor, and other MCP clients
  • ConversionGraph — Extensible conversion registry with custom unit support

Roadmap Highlights

Version Theme Status
0.3.x Dimensional Algebra Complete
0.4.x Conversion System Complete
0.5.x Dimensionless Units + Uncertainty Complete
0.6.x Pydantic + MCP Server Complete
0.7.x Compute Tool + Extension API Complete
0.8.x String Parsing Planned
0.9.x Constants + Logarithmic Units Planned
0.10.x NumPy/Polars Integration Planned
1.0.0 API Stability Planned

See full roadmap: ROADMAP.md


Documentation

Section Description
Getting Started Why ucon, quickstart, installation
Guides MCP server, Pydantic, custom units, dimensional analysis
Reference API docs, unit tables, MCP tool schemas
Architecture Design principles, ConversionGraph, comparison with Pint

Contributing

make venv                        # Create virtual environment
source .ucon-3.12/bin/activate   # Activate
make test                        # Run tests
make test-all                    # Run tests across all python versions

License

Apache 2.0. See LICENSE.

Download files

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

Source Distribution

ucon-0.7.6.tar.gz (647.1 kB view details)

Uploaded Source

Built Distribution

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

ucon-0.7.6-py3-none-any.whl (70.2 kB view details)

Uploaded Python 3

File details

Details for the file ucon-0.7.6.tar.gz.

File metadata

  • Download URL: ucon-0.7.6.tar.gz
  • Upload date:
  • Size: 647.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ucon-0.7.6.tar.gz
Algorithm Hash digest
SHA256 4c4a4e3936595d1623d8c69f51eecedbb922db6a2892bcc7b5036f418553681d
MD5 401b7033d28742e2a763f706872be015
BLAKE2b-256 1b81f294f0da32c1a3897d1608cb27f1665c5aa20cca9b7986040f2ad0968327

See more details on using hashes here.

File details

Details for the file ucon-0.7.6-py3-none-any.whl.

File metadata

  • Download URL: ucon-0.7.6-py3-none-any.whl
  • Upload date:
  • Size: 70.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ucon-0.7.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f33cbb9a3bfe1f27e58746138cb87e94eb1538cc22147e577d92cf517bd3c426
MD5 69ffccdb41ea21c546cba26ce06da492
BLAKE2b-256 055e8752650e910ff5f8606db99ddd7ce80400bf1784ca4c2751db0e40660cc8

See more details on using hashes here.

Release history Release notifications | RSS feed

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