git
Show by ID
Python library and CLI tool to query the Open Exchange Rates API
Statistics are disabled for this repository
Downloads are disabled for this repository
Revision Commit Message Age Author Refs
5a73d3d8f8d4 historical: Move normalize_rate and _pretty_rate to base Formatter. 8 days and 20 hours ago Brett Smith
77393ee80fde tests: Make consistent rate test a little more robust. 8 days and 20 hours ago Brett Smith
c9382a26044a historical: Fix the rate ordering with two dates. 8 days and 21 hours ago Brett Smith
ae3e4617d31e historical: Always format rates with the same precision. 9 days and 20 hours ago Brett Smith
8dede9d1398c historical: Swap Ledger and Beancount formatters in the class hierarchy. 9 days and 20 hours ago Brett Smith
c3fd55ec15b7 historical: Beancount can handle commas in amounts. 9 days and 21 hours ago Brett Smith
e158eae7d9ae gitignore: Modernize. 11 days and 22 hours ago Brett Smith
30e9f1c1e88a setup: Version 2.0 for all the recent changes. 11 days and 22 hours ago Brett Smith
5573caf7ee0e oxrlib_example: Update for Beancount. 11 days and 22 hours ago Brett Smith
3a3afb79786b historical: Add Beancount output format. 11 days and 22 hours ago Brett Smith
< 1 2 3 4 5 .. 7 >

oxrlib

Introduction

oxrlib provides a Python library and CLI tool to query the Open Exchange Rates API. It emphasizes support for rich data types throughout, and supports caching API results to the filesystem.

It currently only supports OXR's "historical" API.

Getting started with the CLI tool

oxrlib includes an oxrquery tool to access the OXR API directly from the command line. By default, it reads your OXR credentials and other common configuration from ~/.config/oxrlib.ini. Copy oxrlib_example.ini from the source to ~/.config/oxrlib.ini, then edit that file following the instructions in the comments.

Run oxrquery --help for instructions to use the tool.

Getting started with the library

Here's an example of using the Python library, complete with caching results:

from oxrlib import cache, loaders, rate

filename_format = '{date}_{base}_rates.json'
cache_writer = cache.CacheWriter(DIR_PATH, historical=filename_format)
loader = loaders.LoaderChain()
loader.add_loader(loaders.FileCache(DIR_PATH, historical=filename_format))
loader.add_loader(loaders.OXRAPIRequest(APP_ID_STRING))
with loader.historical(DATE, BASE_CODE_STRING) as json_response:
    hist_rate = rate.Rate.from_json_file(json_response)
if loader.should_cache():
    cache_writer.save_rate(hist_rate)
# Rates are available from the hist_rate.rates dict.

Running tests

Run ./setup.py test from your checkout directory.