Skip to main content

Lightweight Python library for precise money arithmetic with pluggable FX-rate backends, automatic currency conversion, and clean JSON serialization.

Project description

PyPI Tests

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


Download files

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

Source Distribution

fxmoney-0.1.2.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

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

fxmoney-0.1.2-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

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

Hashes for fxmoney-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b9595a6688f1c93f7c491424494fd3414bb941ee6e7702fac4c7968b88f2d28a
MD5 5b33c8521c4564949558c47a9d6b8be9
BLAKE2b-256 0602420d2e91835e197ce11a37393b63a72891310a483a9d3151d933fc26bba0

See more details on using hashes here.

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

Hashes for fxmoney-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b1f38db4cc8d4d1c4ddacc05acf3747c1aaa7641303647c5c7c424c28a2a3d3b
MD5 01c59ccf57898541818f330801dc23d1
BLAKE2b-256 6f4cde83098e17127d08f7f8411a9e4f026822cdf4daa773618d54e41d676b23

See more details on using hashes here.

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