Lightweight Python library for precise money arithmetic with pluggable FX-rate backends, automatic currency conversion, and clean JSON serialization.
pip install fxmoneyfrom 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- 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
fxmoney convert 100 USD EUR
fxmoney convert 100 USD EUR --date 2020-01-01 --fallback raise
fxmoney convert 100 USD EUR --verboseEnable 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()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()MIT License