Skip to main content
pycents logo

Tests Python Version Linter: Ruff Checked with mypy codecov License: MIT

pycents is a strongly typed Python library for representing and manipulating monetary values with ISO 4217 and custom currencies, explicit rounding semantics and rich formatting options.

  • ISO 4217 & custom currencies: built-in support for ISO 4217 currencies with standardized codes and minor-unit definitions. Custom currencies such as cryptocurrencies can be registered at runtime. Some popular cryptocurrencies are pre-registered and ready to use.

  • Money uses integer minor units for exact monetary representation.

  • Explicit rounding — PyCents use a dual-type architecture for exact and high-precision operations:

  • Money The core immutable type that stores exact monetary values as integer minor units (e.g., cents).

  • UnroundedMoney: A high-precision type designed for complex intermediate calculations without premature rounding.

  • Seamless Integration: Both types work together fluidly in arithmetic. Calling .round() on an UnroundedMoney instance explicitly converts it back into standard Money.

Features

  • 100% Test Coverage & Property-Based Testing: Fully covered and rigorously verified using Hypothesis to guarantee mathematical invariants.
  • ISO 4217 currency definitions
  • Custom currency support with runtime registration
  • Pre-registered popular cryptocurrencies
  • Immutable Money type
  • Precise decimal arithmetic
  • Explicit rounding semantics.
  • Locale-aware currency formatting
  • Pluggable formatting backends
  • Custom format specification

Example

from decimal import Decimal

from pycents import Money, UnroundedMoney, formatting, allocation as alloc

# Use a locale-aware formatting backend
formatting.use_backend("babel")  # Other options are: 'std'(default) and 'icu'

rent = Money.from_major(121_555, "USD")
# the '.2c' format field is for displaying in compact notation
# while retaining 2 decimals
print(f"{rent:.2c}")  # Output: $121.56K

# Apply an 8.875% municipal property tax
tax_rate = Decimal("0.08875")

# `tax` is not a Money instance!
tax = rent * tax_rate
assert isinstance(tax, UnroundedMoney)

# At the end the arithmetic pipeling, call round to get a `Money` instance
total = (rent + tax).round()

# allocate the rent among three clients according to a given ratios
shares = alloc.allocate(total, [1000, 2000, 3000])
result = ", ".join(f"{share:.2c}" for share in shares)
print("Allocated Shares:", f"[{result}]")
# Output: Allocated Shares: [$22.06K, $44.11K, $66.17K]

Documentation

Documentation and API reference are available at pycents.readthedocs.io. This is still a work in progress, some guide are complete (Quickstart, formatting and allocation) but still need to be polished.

License

pycents is distributed under the MIT License. See the LICENSE file for details.

Metadata

Release files for pycents 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycents 1.3.0
File Size Uploaded
pycents-1.3.0.tar.gz 177.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycents 1.3.0
File Interpreter ABI Platform
pycents-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 219.1 kB

Release files / pycents-1.3.0.tar.gz

Download URL pycents-1.3.0.tar.gz
Size 177.0 kB
Tags Source
SHA-256 checksum
How to use checksums
91c38a859ca23e33a1d7cd1baeb1d2970769d6db37eac903f4456de9d3acf3c9
BLAKE2b-256 checksum
How to use checksums
de1a68246c9be2a5973ad70656e383d696c03ee98c1dd72f50b7d3aef86b0b03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pycents-1.3.0-py3-none-any.whl

Download URL pycents-1.3.0-py3-none-any.whl
Size 42.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17a6a57d75b89891f605c9279270dc9cdc9999d4fb2ced5e0348c574ee58f48b
BLAKE2b-256 checksum
How to use checksums
4352baba9f8b60309c72a54f81d0f0b33a97a0985ffa295acdf4a3ae511e8414
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

1.5.0

2 release files

1.4.0

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

This release

1.3.0 This release

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page