Summary
git Use 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
Brett Smith 348b82e08759
7 years ago
Brett Smith a6e46b0cca1f
7 years ago
Brett Smith 63b0ad3c76bf
7 years ago
Brett Smith 5fb01151d11f
7 years ago
Brett Smith 8e5cb0642fe1
7 years ago
Brett Smith 08840e6757a1
7 years ago
Brett Smith cff18d9d96b1
7 years ago
Brett Smith b49356bcb609
7 years ago
Brett Smith 3b5a563ef64b
7 years ago
Brett Smith 7ae8c359e0b9
7 years ago

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 <tt class="docutils literal">oxrquery</tt> tool to access the OXR API directly from the command line. By default, it reads your OXR credentials and other common configuration from <tt class="docutils literal">~/.config/oxrlib.ini</tt>. Copy <tt class="docutils literal">oxrlib_example.ini</tt> from the source to <tt class="docutils literal">~/.config/oxrlib.ini</tt>, then edit that file following the instructions in the comments.

Run <tt class="docutils literal">oxrquery --help</tt> 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 <tt class="docutils literal">./setup.py test</tt> from your checkout directory.