Skip to main content

A simple python utility library for representing cryptocurrency amounts

Project description

cryptils

Tests Coverage License PyPI TestPyPI

An utility library for representing cryptocurrency amounts in Python.

Installation

pip install cryptils

Quick Start

from cryptils import BTC, ETH, USDC, USDT

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

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

# Arithmetic
result = BTC("0.5") + BTC("0.25")
print(result)  # 0.75000000 BTC

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

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

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

Features

  • Uses decimal.Decimal internally to avoid floating-point errors.
  • Consistent precision handling per currency (e.g., 8 decimals for BTC, 6 for USDC).
  • Simple, explicit API designed for financial precision.

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 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

MIT

Project details


Download files

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

Source Distribution

cryptils-0.1.0a1.tar.gz (39.9 kB view details)

Uploaded Source

Built Distribution

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

cryptils-0.1.0a1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file cryptils-0.1.0a1.tar.gz.

File metadata

  • Download URL: cryptils-0.1.0a1.tar.gz
  • Upload date:
  • Size: 39.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cryptils-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 dcab23ea0828c237a6d061d7d3c7a815341d76da6697b5db0ef4342ea50bd181
MD5 dc4888368c9b4a455aa3582f142cd3b8
BLAKE2b-256 99a3efc49ab3540af60308599e8d6eddcd029b449a4ff91931319c04b939390a

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryptils-0.1.0a1.tar.gz:

Publisher: publish-pypi.yml on seba3c/cryptils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryptils-0.1.0a1-py3-none-any.whl.

File metadata

  • Download URL: cryptils-0.1.0a1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cryptils-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 46b1b1eaabe82a907507758219319f5badc0d1380cbd6b8016917eb5206446dc
MD5 2508b83b5a02597fc842a76861de1678
BLAKE2b-256 494276733481a8d2851290cbf6f8eb0682c785abbb72199981561b8256386b21

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryptils-0.1.0a1-py3-none-any.whl:

Publisher: publish-pypi.yml on seba3c/cryptils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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