Metadata-Version: 2.4
Name: perexchange
Version: 2.1.0
Summary: Library for fetching Peruvian exchange rates
Author-email: David Duran <dadch1404@gmail.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/totallynotdavid/perexchange
Project-URL: Repository, https://github.com/totallynotdavid/perexchange
Project-URL: Issues, https://github.com/totallynotdavid/perexchange/issues
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: beautifulsoup4>=4.15.0
Requires-Dist: httpx[http2]>=0.28.1
Requires-Dist: lxml>=6.1.3
Dynamic: license-file

# perexchange

perexchange is an asynchronous Python library that fetches live PEN/USD exchange
rates from Peruvian exchange houses. It queries the houses concurrently and
returns the rates that arrived. It needs no API key and requires Python 3.12 or
later.

## Install

```bash
python -m pip install perexchange
```

## Fetch rates

```python
import asyncio

import perexchange


async def main() -> None:
    report = await perexchange.fetch_rates_report()

    for failure in report.failures:
        print(f"{failure.source} failed: {failure.message}")

    if report.rates:
        cheapest = min(report.rates, key=lambda rate: rate.sell_price)
        print(f"{cheapest.source} charges S/{cheapest.sell_price} for a dollar")


asyncio.run(main())
```

Each `ExchangeRate` has a `buy_price`, what the house pays you for a dollar, and
a `sell_price`, what it charges you. A source that fails is listed in
`report.failures` and does not stop the others.

## Learn more

[API reference](https://github.com/totallynotdavid/perexchange/blob/master/docs/api.md)
covers source selection, fetch settings, retries, failures and the data classes.
The [repository](https://github.com/totallynotdavid/perexchange) has the issue
tracker and the contributing guide.
