Currency classes to work with monetary values
Project description
Monepy
A python package that implements currency classes to work with monetary values.
Install
From PyPI using pip:
pip install monepy
Behavior
The currency classes behave like a numeric type, with a formatted() method
that returns the value in the currency format:
>>> from monepy import USD
>>> x = USD(10)
>>> x
<USD 10.00>
>>> x.formatted()
'$10.00'
>>> x == 1
False
>>> x == 10
True
>>> x > 10
False
>>> x < 10.1
True
The class constructor does not round the values recieved. If a value with more
significant digits than the currency supports is provided, a ValueError will
be raised.
Operators
Only supported operators are +, -, * and /.
The + and -
Operations with + and - can only be done with currencies of the same type
and will return an object of the same currency:
>>> x = USD(10)
>>> y = USD(0.1)
>>> x + y
<USD 10.10>
>>> x - y
<USD 9.90>
The *
The * is only possible with a numeric value:
>>> x = USD(1.99)
>>> x * 1.23
<USD 2.44>
The /
The / operator is possible with both numeric and a currency of the same type:
>>> x = USD(10)
>>> x / 2
<USD 5.00>
>>> y = USD(3)
>>> x / y
3.3333333333333335
The %
The % is only supports numeric values
>>> x = USD(100)
>>> x / 15
<USD 6.66>
>>> x % 15
<USD 0.10>
Pandas integration
Currency classes can be used with the pandas library:
>>> import pandas as pd
>>> from monepy import EUR
>>> df = pd.DataFrame({
... "product": ["x", "y", "z"],
... "price": [10, 0.99, 25],
... "quantity": [8, 50, 200]
... })
>>> df
product price quantity
0 x 10.00 8
1 y 0.99 50
2 z 25.00 200
>>> df["price"] = df["price"].map(EUR, na_action="ignore")
>>> df
product price quantity
0 x 10,00 8
1 y 0,99 50
2 z 25,00 200
>>> df["subtotal"] = df["price"] * df["quantity"]
>>> df
product price quantity subtotal
0 x 10,00 8 80,00
1 y 0,99 50 49,50
2 z 25,00 200 5 000,00
>>> df[df["price"] >= 10]
product price quantity subtotal
0 x 10,00 8 80,00
2 z 25,00 200 5 000,00
>>> total = df["subtotal"].sum()
>>> print(f"The total is {total.formatted()}.")
The total is 5 129,50 €.
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 monepy-0.2.tar.gz.
File metadata
- Download URL: monepy-0.2.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5367f4381a10494fcb879032babfdbce76d899a4430d7fd04e67f9e762171738
|
|
| MD5 |
b7b29af127725e49c2dc4bd25ad6510c
|
|
| BLAKE2b-256 |
eb5ecf4580e03ab76d9c71bbf1a30c4135a5600083f83c6da7f79dc9654b35e3
|
Provenance
The following attestation bundles were made for monepy-0.2.tar.gz:
Publisher:
publish.yml on vsbits/monepy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
monepy-0.2.tar.gz -
Subject digest:
5367f4381a10494fcb879032babfdbce76d899a4430d7fd04e67f9e762171738 - Sigstore transparency entry: 173055478
- Sigstore integration time:
-
Permalink:
vsbits/monepy@1c3c10388ac9be6424b32beba17a4cd2f8770f7d -
Branch / Tag:
refs/tags/v0.2 - Owner: https://github.com/vsbits
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1c3c10388ac9be6424b32beba17a4cd2f8770f7d -
Trigger Event:
release
-
Statement type:
File details
Details for the file monepy-0.2-py3-none-any.whl.
File metadata
- Download URL: monepy-0.2-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0661109be69fc8bac22f2e31022dc8cc5ee93453fff156de6ed4924d0d4cfb39
|
|
| MD5 |
8c1ea65030186e20baacae53578f779b
|
|
| BLAKE2b-256 |
7431e081c2ced35d7d3a2fdca9e8e73252e2a4c300b769dde0ef982aa29cda71
|
Provenance
The following attestation bundles were made for monepy-0.2-py3-none-any.whl:
Publisher:
publish.yml on vsbits/monepy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
monepy-0.2-py3-none-any.whl -
Subject digest:
0661109be69fc8bac22f2e31022dc8cc5ee93453fff156de6ed4924d0d4cfb39 - Sigstore transparency entry: 173055480
- Sigstore integration time:
-
Permalink:
vsbits/monepy@1c3c10388ac9be6424b32beba17a4cd2f8770f7d -
Branch / Tag:
refs/tags/v0.2 - Owner: https://github.com/vsbits
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1c3c10388ac9be6424b32beba17a4cd2f8770f7d -
Trigger Event:
release
-
Statement type: