Metadata-Version: 2.5
Name: chenyikun
Version: 0.1.0
Summary: Small utilities from Chen Yikun's projects: exact money amounts for cross-border commerce
Author: Chen Yikun
License-Expression: MIT
License-File: LICENSE
Keywords: currency,e-commerce,fx,iso4217,money
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Office/Business :: Financial
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# chenyikun

Small utilities from my projects. The first module handles exact money amounts for cross-border e-commerce.

```bash
pip install chenyikun
```

## Money

Amounts are stored as integers in the currency's minor unit, so there is no floating-point error.
Minor units follow ISO 4217: USD has 2 decimal places, JPY has 0, KWD has 3.

```python
from chenyikun import Money, convert, fx_consistent

price = Money.parse("49.99", "USD")        # Money(amount_minor=4999, currency='USD')
print(price)                               # 49.99 USD

eur = convert(price, "EUR", "0.9235")      # rounded to the cent, banker's rounding by default
print(eur)                                 # 46.17 EUR

fx_consistent(price, Money(4616, "EUR"), "0.9235")   # True: within 1 minor unit
Money(100, "EUR") + Money(100, "USD")                # raises CurrencyMismatchError
```

- `Money.parse` rejects amounts with more decimal places than the currency allows, and rejects floats.
- `convert` rounds to the target currency's minor unit (`ROUND_HALF_EVEN` unless you pass another mode).
- `fx_consistent` checks a charged amount against a source amount and an exchange rate.

## License

MIT
