iso_4217: Yet another currency data package for Python
This package contains ISO 4217 active and historical currency data. Supports pint for operations with currency units.
>>> from iso_4217 import Currency
>>> Currency.USD
<Currency.USD: 'US Dollar'>
>>> Currency.USD.value
'US Dollar'
>>> Currency.USD.number
840
>>> Currency('US Dollar')
<Currency.USD: 'US Dollar'>
>>> Currency.JPY.entities
frozenset({'JAPAN'})
>>> Currency.ZWR
<Currency.ZWR: 'Zimbabwe Dollar (2009)'>
>>> Currency.ZWR.entities
frozenset()
>>> Currency.ZWR.withdrew_entities
(Historic(entity='ZIMBABWE', name='Zimbabwe Dollar'...2009, month=6), begin=None)),)
>>> Currency.VED
<Currency.VED: 'Bolívar Soberano (VED)'>
Pint units and subunits are available with convenient unit and subunit
properties on Currency. Accessing these properties requires pint package installed
and automatically defines currency units in application default registry.
>>> Currency.USD.unit * 5 + Currency.USD.subunit * 5 <Quantity(5.05, 'USD')>
Currency units can be defined in any UnitRegistry manually
>>> import pint >>> from decimal import Decimal >>> from iso_4217 import define_currency_units >>> reg = define_currency_units(pint.UnitRegistry(non_int_type=Decimal)) >>> 5 * reg.USD <Quantity(5, 'USD')>
But units from separate registries should not be mixed
>>> Currency.USD.unit == reg.USD Traceback (most recent call last): ... ValueError: Cannot operate with Unit and Unit of different registries.
If you want to replace registry used by Currency just replace the application registry:
>>> pint.set_application_registry(reg) >>> Currency.USD.unit == reg.USD True
Subunits are defined with s suffix:
>>> 5 * reg.USDs
<Quantity(5, 'USDs')>
>>> (5 * reg.USDs).to("USD")
<Quantity(0.05, 'USD')>
>>> (5 * reg.BHDs).to_base_units()
<Quantity(0.005, 'BHD')>
Each currency is defined within it’s own dimension:
>>> (5 * reg.USD).to('EUR')
Traceback (most recent call last):
...
pint.errors.DimensionalityError: Cannot convert from 'USD' ([currency_USD]) to 'EUR' ([currency_EUR])
But automatic currency conversion can be made via pint Contexts
>>> context = pint.Context()
>>> eur_to_usd = lambda r, eur: eur * r("1.2 USD/EUR")
>>> context.add_transformation("[currency_EUR]", "[currency_USD]", eur_to_usd)
>>> (Currency.EUR.unit * 5).to('USD', context)
<Quantity(6.0, 'USD')>
Inspired by iso4217 package by Hong Minhee.
Metadata
Release files for iso-4217 0.8.260101
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| iso_4217-0.8.260101.tar.gz | 18.9 kB | Without provenance | Details for iso_4217-0.8.260101.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| iso_4217-0.8.260101-py3-none-any.whl | Python 3 | none | any | Details for iso_4217-0.8.260101-py3-none-any.whl |
Total release size: 36.5 kB
Release files / iso_4217-0.8.260101.tar.gz
| Download URL | iso_4217-0.8.260101.tar.gz |
|---|---|
| Size | 18.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cb03c7b49a2facd1a15a52529249bfe517e93fe65e895bba1ed473286e6c9608
|
|
BLAKE2b-256 checksum How to use checksums |
99d55d6dda62ac08fa6f89fc659edcf5cbbb5ea78e66ff43762ed8aef2e116f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / iso_4217-0.8.260101-py3-none-any.whl
| Download URL | iso_4217-0.8.260101-py3-none-any.whl |
|---|---|
| Size | 17.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
107f90c04dc0a3686f8222bfe2e2db6b1a2830e57600da51c46dca2b8ee5bc87
|
|
BLAKE2b-256 checksum How to use checksums |
d956c405470260da707a65e1182e8e37a844b32212fd5524551889bea2b722b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for iso-4217 0.8.260101
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.