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.0a0.tar.gz (15.1 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.0a0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file fxmoney-0.1.0a0.tar.gz.

File metadata

  • Download URL: fxmoney-0.1.0a0.tar.gz
  • Upload date:
  • Size: 15.1 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.0a0.tar.gz
Algorithm Hash digest
SHA256 453dfead7fad6477655076f8b1646b160bdc6db26bcd409ff47bf3087fbf740b
MD5 2e964597835264a0e96fe01bfeeb54c7
BLAKE2b-256 f031fee11a8d847fbe5a4dc019094166da2995c71ece3c3eab437b186c412829

See more details on using hashes here.

File details

Details for the file fxmoney-0.1.0a0-py3-none-any.whl.

File metadata

  • Download URL: fxmoney-0.1.0a0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 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.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9ae4023f3091dd230c0dc75c879b4fac1bf9198fa25105ef1a344d195f29187
MD5 5db7d3c47825bacb74c6dfb6fc5fe682
BLAKE2b-256 3b6ffec5527b8d561c2249c5b75a7eb3b2366bf4f29da499858068884e7191bf

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