Skip to main content

Type-safe client for the openexchangerates API.

Project description

oxr

oxr is a type-safe Python client with synchronous and asynchronous support for the Open Exchange Rates API. Allowing you to easily fetch exchange rates and convert between currencies.

Installation

pip install oxr

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

pip install oxr[async]

Usage

Synchronous Client

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.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oxr-0.1.1.tar.gz (86.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oxr-0.1.1-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file oxr-0.1.1.tar.gz.

File metadata

  • Download URL: oxr-0.1.1.tar.gz
  • Upload date:
  • Size: 86.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.7

File hashes

Hashes for oxr-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d62cd55398e1b095bc7ac090da25a30209530faac4c02a58d6c80c3357ddf676
MD5 e0eb8e1a84c7a1c9e74c9d026054dacd
BLAKE2b-256 87d7d21e5d8313d8f5e7a4130c1270bdeb4cc6c4cb94b0941bff3e9cda413e6d

See more details on using hashes here.

File details

Details for the file oxr-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: oxr-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.7

File hashes

Hashes for oxr-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 694396b5b8c17c6bcd7039489f52c1a32a9d7aae1bb84ad030e63177a4ca8abd
MD5 7c4ca42e19355b7984a902d308b4dcdc
BLAKE2b-256 c578995e019ef476e8ce4639615c32b1fa4ba7e17bfa71dd8a0f10d8c31e02d3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page