Lightweight Python library for precise money arithmetic with pluggable FX-rate backends, automatic currency conversion, and clean JSON serialization.
Project description
fxmoney
Lightweight Python library for precise money arithmetic with pluggable FX-rate backends, automatic currency conversion, and clean JSON serialization.
Installation
pip install fxmoney
Quickstart
from fxmoney import Money, install_backend
# Use the default ECB backend
a = Money(2, "EUR")
b = Money(3, "USD")
total = a + b
print(total) # prints the sum in EUR
print(total.to("GBP")) # converts to GBP
Features
- Decimal-based precision
- Operator overloads for
+,-,*,/ - Automatic currency conversion with historical and live rates
- Configurable fallback strategies
- Clean, human-editable JSON serialization
- Pluggable backends: ECB ZIP and exchangerate.host REST API
CLI Usage
fxmoney convert 100 USD EUR
fxmoney convert 100 USD EUR --date 2020-01-01 --fallback raise
fxmoney convert 100 USD EUR --verbose
Background Update
Thread-based
Enable automatic rate refresh every 4 hours:
from fxmoney.updater import enable_background_update, disable_background_update
# Start background updater (runs every 4 hours)
enable_background_update()
# ... your application runs ...
# Stop background updater
disable_background_update()
AsyncIO-based
Start an async task in your event loop:
import asyncio
from fxmoney.updater import async_background_update
stop_evt = asyncio.Event()
# Schedule updater to run every 14400 seconds (4 hours)
asyncio.create_task(async_background_update(14400, stop_evt))
# ... your async application runs ...
# Signal the updater to stop
stop_evt.set()
License
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 fxmoney-0.1.2.tar.gz.
File metadata
- Download URL: fxmoney-0.1.2.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9595a6688f1c93f7c491424494fd3414bb941ee6e7702fac4c7968b88f2d28a
|
|
| MD5 |
5b33c8521c4564949558c47a9d6b8be9
|
|
| BLAKE2b-256 |
0602420d2e91835e197ce11a37393b63a72891310a483a9d3151d933fc26bba0
|
File details
Details for the file fxmoney-0.1.2-py3-none-any.whl.
File metadata
- Download URL: fxmoney-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1f38db4cc8d4d1c4ddacc05acf3747c1aaa7641303647c5c7c424c28a2a3d3b
|
|
| MD5 |
01c59ccf57898541818f330801dc23d1
|
|
| BLAKE2b-256 |
6f4cde83098e17127d08f7f8411a9e4f026822cdf4daa773618d54e41d676b23
|