A simple python utility library for representing cryptocurrency amounts
Project description
cryptils
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 with other amounts
result = BTC("0.5") + BTC("0.25")
print(result) # 0.75000000 BTC
# Arithmetic with built-in types (int, float, Decimal)
from decimal import Decimal
btc = BTC("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 - BTC("2.5")) # 7.50000000 BTC (int - 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.Decimalinternally 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
This project is licensed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cryptils-0.1.0a2.tar.gz.
File metadata
- Download URL: cryptils-0.1.0a2.tar.gz
- Upload date:
- Size: 40.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
117639f1a89443dca8a388ec5ed213e0876fe49aa9329c7c19d450f6af045ab5
|
|
| MD5 |
04df18e928dc57f45d8a32d8c1e5fade
|
|
| BLAKE2b-256 |
a44be53b2321d09a169d5533acab3eee83fda91cb5be8ffeed0a98aa7393fc3c
|
Provenance
The following attestation bundles were made for cryptils-0.1.0a2.tar.gz:
Publisher:
publish-pypi.yml on seba3c/cryptils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cryptils-0.1.0a2.tar.gz -
Subject digest:
117639f1a89443dca8a388ec5ed213e0876fe49aa9329c7c19d450f6af045ab5 - Sigstore transparency entry: 1588394527
- Sigstore integration time:
-
Permalink:
seba3c/cryptils@aea4c6b9af2bdcd6ebc8a43ba19359ac8bbd18a5 -
Branch / Tag:
refs/tags/v.0.1.0a2 - Owner: https://github.com/seba3c
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@aea4c6b9af2bdcd6ebc8a43ba19359ac8bbd18a5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cryptils-0.1.0a2-py3-none-any.whl.
File metadata
- Download URL: cryptils-0.1.0a2-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87ce4f2b5046de5700b6bfc064e6f440cc19c28c0e162be4a7c831713d835d31
|
|
| MD5 |
a17cded0d28517ae3f5c8d9b97ad2eae
|
|
| BLAKE2b-256 |
efc6bb874ecff9a0a6659ecd154f68811cffa587bca20920d93323869b2daaec
|
Provenance
The following attestation bundles were made for cryptils-0.1.0a2-py3-none-any.whl:
Publisher:
publish-pypi.yml on seba3c/cryptils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cryptils-0.1.0a2-py3-none-any.whl -
Subject digest:
87ce4f2b5046de5700b6bfc064e6f440cc19c28c0e162be4a7c831713d835d31 - Sigstore transparency entry: 1588394685
- Sigstore integration time:
-
Permalink:
seba3c/cryptils@aea4c6b9af2bdcd6ebc8a43ba19359ac8bbd18a5 -
Branch / Tag:
refs/tags/v.0.1.0a2 - Owner: https://github.com/seba3c
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@aea4c6b9af2bdcd6ebc8a43ba19359ac8bbd18a5 -
Trigger Event:
push
-
Statement type: