Metadata-Version: 2.3
Name: oxr
Version: 0.1.1
Summary: Type-safe client for the openexchangerates API.
Author-email: Maxwell Muoto <maxmuoto@gmail.com>
License: MIT License
        
        Copyright (c) 2024 Maxwell Muoto
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Requires-Python: >=3.9
Requires-Dist: pydantic<3,>=2.0.0
Requires-Dist: requests<3,>=2.0.0
Requires-Dist: typing-extensions<5,>=4.0.0
Provides-Extra: async
Requires-Dist: aiohttp<4,>=3.0.0; extra == 'async'
Description-Content-Type: text/markdown

# oxr

`oxr` is a type-safe Python client with synchronous and asynchronous support for the [Open Exchange Rates API](https://openexchangerates.org/). Allowing you to easily fetch exchange rates and convert between currencies.


## Installation

```bash
pip install oxr
```

If you want to use the asynchronous client, you can install the package with the following command:

```bash
pip install oxr[async]
```

## Usage

### Synchronous Client

```python
import oxr

import datetime as dt

# Base default to USD
client = oxr.Client(app_id='your_app_id')

# Fetch the latest exchange rates
rates = client.latest(symbols=['EUR', 'JPY'])

# Convert 100 USD to EUR
converted = client.convert(100, 'USD', 'EUR')

# Get time series data
timeseries = client.timeseries(start_date=dt.date(2020, 1, 1), end_date=dt.date(2020, 1, 31), symbols=['EUR', 'JPY'])

# Get open, high, low, close data
ohlc = client.ohlc(start_time=dt.datetime(2020, 1, 1), period="1m", symbols=['EUR', 'JPY'])
```

### Asynchronous Client

The asynchronous client is built on top of `aiohttp`, and can be used in an `async` context.

```python
import oxr.asynchronous
import asyncio
import datetime as dt

async def main():
    async with oxr.asynchronous.Client(app_id='your_app_id') as client:        
        # Fetch the latest exchange rates asynchronously
        rates = await client.latest(symbols=['EUR', 'JPY'])

        # Asynchronously convert 100 USD to EUR
        converted = await client.convert(100, 'USD', 'EUR')

        # Get time series data asynchronously
        timeseries = await client.timeseries(start_date=dt.date(2020, 1, 1), end_date=dt.date(2020, 1, 31), symbols=['EUR', 'JPY'])

        # Get OHLC data asynchronously
        ohlc = await client.ohlc(start_time=dt.datetime(2020, 1, 1), period="1m", symbols=['EUR', 'JPY'])

asyncio.run(main())
```

## License

MIT

