Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

cryptils

Tests Coverage License PyPI TestPyPI
A utility library for representing cryptocurrency and fiat amounts in Python.

Installation

pip install cryptils

Quick Start

from cryptils import BTCAmount, ETHAmount, USDCAmount, USDTAmount, USDAmount, JPYAmount

# Create amounts with exact decimal precision
btc = BTCAmount("1.5")
print(btc)  # 1.50000000 BTC

eth = ETHAmount("2.0")
print(eth)  # 2.000000000000000000 ETH

# Arithmetic with other amounts
result = BTCAmount("0.5") + BTCAmount("0.25")
print(result)  # 0.75000000 BTC

# Arithmetic with built-in types (int, float, Decimal)
from decimal import Decimal

btc = BTCAmount("1.0")
print(btc + 0.5)  # 1.50000000 BTC (added float)
print(btc + 2)  # 3.00000000 BTC (added int)
print(btc + Decimal("0.5"))  # 1.50000000 BTC (added Decimal)
print(2 * btc)  # 2.00000000 BTC (int * BTC)
print(10 - BTCAmount("2.5"))  # 7.50000000 BTC (int - BTC)

# Different currencies maintain their own precision
usdc = USDCAmount("100")
print(usdc)  # 100.000000 USDC

# Access the raw Decimal value
print(btc.to_decimal())  # Decimal('1.50000000')

# Get the formatted string explicitly
print(btc.to_string())  # BTC 1.50000000

# Fiat amounts with proper precision
usd = USDAmount("99.99")
print(usd)              # 99.99
print(usd.to_string())  # USD 99.99

jpy = JPYAmount("150")
print(jpy)              # 150
print(jpy.to_string())  # JPY 150

Features

  • Uses decimal.Decimal internally to avoid floating-point errors.
  • Consistent precision handling per currency (e.g., 8 decimals for BTC, 6 for USDC).
  • Full fiat currency support (USD, EUR, GBP, JPY, etc.) with correct decimal precision.
  • Simple, explicit API designed for financial precision.

Pydantic Support

CurrencyAmount subclasses (crypto and fiat) work as Pydantic v2 field types:

from pydantic import BaseModel
from cryptils import BTCAmount, ETHAmount, USDCAmount, USDAmount


class WalletBalance(BaseModel):
    btc: BTCAmount
    eth: ETHAmount
    usdc: USDCAmount
    usd: USDAmount


wallet = WalletBalance(btc="1.5", eth=2, usdc=100.0, usd="99.99")
print(wallet.model_dump_json())
# {"btc":"1.50000000","eth":"2.000000000000000000","usdc":"100.000000","usd":"99.99"}

Requires Pydantic v2 (pip install pydantic).

Development

This project uses uv for environment management, ruff for linting and formatting, and tox for testing across Python versions.

# Setup environment
uv sync

# Run tests
uv run pytest
# Run tests with coverage
uv run pytest --cov

# Run tests across all supported Python versions
uv run tox

# Format and lint
uv run ruff check --fix .
uv run ruff format .

# Install pre-commit hooks
uv run pre-commit install

# Run pre-commit on all files
uv run pre-commit run --all-files

License

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

Metadata

Release files for cryptils 0.1.0b2

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

Source distribution (sdist)

Source distribution for cryptils 0.1.0b2
File Size Uploaded Provenance Actions
cryptils-0.1.0b2.tar.gz 52.2 kB With provenance Details for cryptils-0.1.0b2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cryptils 0.1.0b2
File Interpreter ABI Platform Actions
cryptils-0.1.0b2-py3-none-any.whl Python 3 none any Details for cryptils-0.1.0b2-py3-none-any.whl

Total release size: 58.9 kB

Release files / cryptils-0.1.0b2.tar.gz

Download URL cryptils-0.1.0b2.tar.gz
Size 52.2 kB
Tags Source
SHA-256 checksum
How to use checksums
68bfc2f9b3b87519bc490255f25bc936af965635fdb43fc190f42a8f093c760f
BLAKE2b-256 checksum
How to use checksums
42b22b20b4e4534c8959f806e883d98ccc6039ee42ce7b9bdec9230ef2f2e085
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 21, 2026.

Transparency log

Release files / cryptils-0.1.0b2-py3-none-any.whl

Download URL cryptils-0.1.0b2-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b24bb445bfd07348d2cf3bfddf960370a159bac0e9ccf010b3d1537ac25a2ec
BLAKE2b-256 checksum
How to use checksums
cc130a783572b4feffc7fca55e29cab920f927f0e82155a6babd5c2186d21025
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 21, 2026.

Transparency log

Security for cryptils 0.1.0b2

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 cryptils-0.1.0b2.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 May 21, 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