Currencies and exchange rates for the Stapel framework
Project description
stapel-currencies
Currencies and exchange rates — configurable base currency, pluggable rate providers (ECB by default), cross-rate conversion as a comm Function
Part of the Stapel framework — composable Django apps that deploy as a monolith or as microservices without changing module code.
Install
pip install stapel-currencies
# settings.py
INSTALLED_APPS = [
# ...
"stapel_currencies",
]
# urls.py
path("currencies/", include("stapel_currencies.urls"))
Seed the catalog and pull live rates:
python manage.py migrate
python manage.py load_default_currencies
python manage.py update_exchange_rates # ECB by default; --dry-run supported
Or schedule the Celery task:
CELERY_BEAT_SCHEDULE = {
"update-exchange-rates": {
"task": "stapel_currencies.tasks.update_exchange_rates",
"schedule": crontab(hour=16, minute=30), # ECB publishes ~16:00 CET
},
}
Converting
from decimal import Decimal
from stapel_core.comm import call
call("currencies.convert", {
"amount": "100.00", # decimal strings on the wire
"from_currency": "USD",
"to_currency": "GBP", # non-base pairs go via the base cross rate
})
# -> {"amount": "78.70"}
# In-process, same math:
from stapel_currencies import convert
convert(Decimal("100"), "USD", "GBP") # Decimal("78.70")
Settings
All configuration lives in the STAPEL_CURRENCIES namespace (dict setting, flat
setting, or env var — resolved lazily):
| Key | Default | Meaning |
|---|---|---|
BASE_CURRENCY |
"EUR" |
ISO code all stored rates are relative to (base = 1). |
RATE_PROVIDER |
"stapel_currencies.providers.ECBRateProvider" |
Dotted path to a RateProvider subclass — the rate-source seam. |
DEFAULT_CURRENCIES |
16 European currencies | Seed list for load_default_currencies. |
CONVERSION_DECIMAL_PLACES |
2 |
Quantization of conversion results (ROUND_HALF_UP). |
HTTP API
Read-only (writes happen via the Django admin and the rate-update task):
| Route | Meaning |
|---|---|
GET currencies/api/ |
Active currencies (code, display_name, value, symbol, is_active). |
GET currencies/api/<code>/ |
One currency by ISO code. |
comm surface
| Kind | Name | Contract |
|---|---|---|
| Function | currencies.convert |
{"amount": "<decimal str>", "from_currency", "to_currency"} -> {"amount": "<decimal str>"} — schema |
Extension points
See MODULE.md — the agent-facing map of every fork-free seam (settings,
the RateProvider ABC with a custom-provider recipe, serializer seam, comm surface,
system checks).
Development
pip install -e . && pip install pytest pytest-django pytest-cov ruff jsonschema
./setup-hooks.sh
pytest tests/
License
MIT
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 stapel_currencies-0.1.0.tar.gz.
File metadata
- Download URL: stapel_currencies-0.1.0.tar.gz
- Upload date:
- Size: 23.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
514054c4ef70c2b27fbcc04d60837ba120a7d36d32813551954c873f7567295b
|
|
| MD5 |
7cc05813ea26d691a23f26abca8cac2d
|
|
| BLAKE2b-256 |
18332e2e02a49736766e8f25e55f038a7efae04f4efe558e46203835f534cff3
|
Provenance
The following attestation bundles were made for stapel_currencies-0.1.0.tar.gz:
Publisher:
publish.yml on usestapel/stapel-currencies
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stapel_currencies-0.1.0.tar.gz -
Subject digest:
514054c4ef70c2b27fbcc04d60837ba120a7d36d32813551954c873f7567295b - Sigstore transparency entry: 2069466306
- Sigstore integration time:
-
Permalink:
usestapel/stapel-currencies@8850fd0bc2514f68e3a29533e031f24d1cb222dc -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/usestapel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8850fd0bc2514f68e3a29533e031f24d1cb222dc -
Trigger Event:
push
-
Statement type:
File details
Details for the file stapel_currencies-0.1.0-py3-none-any.whl.
File metadata
- Download URL: stapel_currencies-0.1.0-py3-none-any.whl
- Upload date:
- Size: 33.6 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 |
2cb5f1f65bf8ce8d00a1add4650bcaf1118740d2a2462084d8bc0f88eeeb6d79
|
|
| MD5 |
1e0f3e19397992b8d308aa2568c4e762
|
|
| BLAKE2b-256 |
3e385f591c316af2bf990f7c65d193bcf755bb012a5f2f7b9db1666b4eb75f13
|
Provenance
The following attestation bundles were made for stapel_currencies-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on usestapel/stapel-currencies
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stapel_currencies-0.1.0-py3-none-any.whl -
Subject digest:
2cb5f1f65bf8ce8d00a1add4650bcaf1118740d2a2462084d8bc0f88eeeb6d79 - Sigstore transparency entry: 2069466757
- Sigstore integration time:
-
Permalink:
usestapel/stapel-currencies@8850fd0bc2514f68e3a29533e031f24d1cb222dc -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/usestapel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8850fd0bc2514f68e3a29533e031f24d1cb222dc -
Trigger Event:
push
-
Statement type: