Dinero
A Dinero object is an immutable data structure representing a specific monetary value. It comes with methods for creating, parsing, manipulating, testing and formatting them.
Install
Dinero is a dependency free project.
pip install dinero
The problem
Using floats to do exact calculations in Python can be dangerous. When you try to find out how much 2.32 x 3 is, Python tells you it's 6.959999999999999. For some calculations, that’s fine. But if you are calculating a transaction involving money, that’s not what you want to see. Sure, you could round it off, but that's a little hacky.
>>> 2.32 * 3 == 6.96
False
>>> 2.32 * 3
6.959999999999999
You can read How to Count Money Exactly in Python to get a better idea.
Why Dinero?
Python Decimal instances are enough for basic cases but when you face more complex use-cases they often show limitations and are not so intuitive to work with. Dinero provides a cleaner and more easy to use API while still relying on the standard library. So it's still Decimal but easier.
>>> from dinero import Dinero
>>> from dinero.currencies import USD
>>>
>>> Dinero(2.32, USD) * 3 == 6.96
True
Dinero give you access to more than 100 different currencies:
>>> from dinero import Dinero
>>> from dinero.currencies import USD, EUR, GBP, INR, CLP
>>> Dinero(2.32, EUR)
Dinero(amount=2.32, currency={'code': 'EUR', 'base': 10, 'exponent': 2, 'symbol': '€'})
>>> Dinero(2.32, EUR).format(symbol=True, currency=True)
'€2.32 EUR'
>>> Dinero(2.32, EUR).raw_amount
Decimal('2.32')
You can perform operations:
>>> total = Dinero(456.343567, USD) + 345.32 * 3
>>> print(total)
# 1,492.30
>>> product = Dinero(345.32, USD).multiply(3)
>>> total = product.add(456.343567)
>>> print(total)
# 1,492.30
And comparisons:
>>> Dinero(100, EUR) == Dinero(100, EUR)
True
>>> Dinero(100, EUR) < Dinero(100, EUR)
False
>>> Dinero(100, EUR) <= Dinero(100, EUR)
True
>>> Dinero(100, EUR) > Dinero(100, EUR)
False
>>> Dinero(100, EUR) >= Dinero(100, EUR)
True
Metadata
Release files for dinero 0.1.2
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 |
|---|---|---|---|---|
| dinero-0.1.2.tar.gz | 15.8 kB | Without provenance | Details for dinero-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dinero-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for dinero-0.1.2-py3-none-any.whl |
Total release size: 58.2 kB
Release files / dinero-0.1.2.tar.gz
| Download URL | dinero-0.1.2.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9369ab3cb0d96ee96ea2b312b2840ec300df36e2af26a9eec9cf48708aba9180
|
|
BLAKE2b-256 checksum How to use checksums |
b6579e78b87381a58e61ef2acf6c31d05791a2a961bbb6f9425efd5cd5964ac3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.8.10 Linux/5.10.16.3-microsoft-standard-WSL2
|
Release files / dinero-0.1.2-py3-none-any.whl
| Download URL | dinero-0.1.2-py3-none-any.whl |
|---|---|
| Size | 42.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
598374e23a2222d72e61452e2362c3b923761e01cde3c5e0eb4326d43644052c
|
|
BLAKE2b-256 checksum How to use checksums |
52e9c81e737c48724db4ee57abe72a4421e11f18511ff16ecf075aa43d2a78f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.8.10 Linux/5.10.16.3-microsoft-standard-WSL2
|
Security for dinero 0.1.2
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.