Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

monetils

Tests Coverage License PyPI TestPyPI
A utility library for representing monetary amounts in Python.

Installation

pip install monetils

Usage

monetils provides BTC and USD classes for representing monetary amounts exactly, without floating-point rounding artifacts.

Construction and formatting

from monetils import BTC, USD

usd = USD(1234.5)
print(str(usd))  # "1234.50"

btc = BTC(1)
print(str(btc))  # "1.00000000"

# Construct from a non-default unit
half_btc = BTC.sat(50_000_000)
print(str(half_btc))  # "0.50000000"

nineteen_ninety_nine = USD.cent(1999)
print(str(nineteen_ninety_nine))  # "19.99"

Arithmetic

from monetils import BTC, USD, CurrencyMismatchError

total = USD(10.50) + USD(5.25)  # USD(15.75)

# A plain number used with +/- is treated as an amount in the currency's base unit
one_more_btc = BTC(1) + 1  # BTC(2)

# A plain number used with */÷ is a dimensionless scaling factor
doubled = BTC(1) * 2  # BTC(2)

# Mixing currencies raises CurrencyMismatchError instead of a silent wrong result
try:
    BTC(1) + USD(1)
except CurrencyMismatchError:
    print("rejected as expected")

Unit conversion

from monetils import BTC

one_btc = BTC(1)
one_btc.to("sat")  # Decimal("100000000")
one_btc.sats  # 100000000

msat_value = one_btc.to("msat")
BTC.msat(msat_value) == one_btc  # True — lossless round trip

Pydantic support

BTC and USD work directly as Pydantic v2 model fields — no wrapper type needed. This requires pydantic>=2.0,<3 to be installed in your own project; monetils does not depend on it (it stays a zero-runtime-dependency library).

from pydantic import BaseModel
from monetils import BTC, USD

class Invoice(BaseModel):
    price: USD
    fee: BTC | None = None

# Accepts a plain number/string, or an existing BTC/USD instance
invoice = Invoice(price=19.99, fee="0.5")

invoice.model_dump()        # {"price": USD(19.99), "fee": BTC(0.5)} — instances, unchanged
invoice.model_dump_json()   # '{"price":"19.99","fee":"0.50000000"}' — the same str() convention
Invoice.model_json_schema() # describes price/fee as JSON string properties

# Invalid input (wrong currency, unparseable value) raises a standard pydantic.ValidationError

License

This project is licensed under the terms of the MIT license.

Metadata

Release files for monetils 0.2.0b3

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

Source distribution (sdist)

Source distribution for monetils 0.2.0b3
File Size Uploaded Provenance Actions
monetils-0.2.0b3.tar.gz 231.7 kB With provenance Details for monetils-0.2.0b3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for monetils 0.2.0b3
File Interpreter ABI Platform Actions
monetils-0.2.0b3-py3-none-any.whl Python 3 none any Details for monetils-0.2.0b3-py3-none-any.whl

Total release size: 240.0 kB

Release files / monetils-0.2.0b3.tar.gz

Download URL monetils-0.2.0b3.tar.gz
Size 231.7 kB
Tags Source
SHA-256 checksum
How to use checksums
864f30011958277ec02f79a353864ee8dbeb6e8a4702a90585b4479762e0e3a1
BLAKE2b-256 checksum
How to use checksums
cfe00e8587b84e5b58177f9641271d382540b1edcef2a17f6423e042787be0c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Release files / monetils-0.2.0b3-py3-none-any.whl

Download URL monetils-0.2.0b3-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b64c85b5f2ec31227bba270ade1b43d87b602566b540584837b1030b0639ceaf
BLAKE2b-256 checksum
How to use checksums
82e0c2ec131445a7747ffc06f09720024bd4110fc5afb856176573f2cbbcbf7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Security for monetils 0.2.0b3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for monetils-0.2.0b3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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