Python library and CLI tool to query the Open Exchange Rates API
Find a file
Brett Smith 8dede9d139 historical: Swap Ledger and Beancount formatters in the class hierarchy.
This makes sense for a couple of reasons:

* The Beancount formatter has "less features" than the Ledger formatter, so
  this is a more "logical" organization of the hierarchy anyway. Note how
  this eliminates the need for the BeancountFormatter.__init__ override to
  turn off Ledger features.

* Any future work will probably be focused on the Beancount formatter, so
  this reduces the amount of code you have to understand and hold in your
  head to do that.
2020-05-19 15:27:04 -04:00
oxrlib historical: Swap Ledger and Beancount formatters in the class hierarchy. 2020-05-19 15:27:04 -04:00
tests historical: Beancount can handle commas in amounts. 2020-05-19 15:22:00 -04:00
.gitignore gitignore: Modernize. 2020-05-17 14:12:15 -04:00
LICENSE LICENSE: Add license. 2017-05-17 14:40:50 -04:00
oxrlib_example.ini oxrlib_example: Update for Beancount. 2020-05-17 14:08:59 -04:00
README.rst Fix typo in variable name 2017-06-13 09:24:18 -04:00
setup.cfg .gitignore: setup.py: Integrate pytest to run tests. 2017-05-17 17:22:39 -04:00
setup.py setup: Version 2.0 for all the recent changes. 2020-05-17 14:10:17 -04:00

oxrlib
======

Introduction
------------

oxrlib provides a Python library and CLI tool to query the `Open Exchange Rates API <https://openexchangerates.org/>`_.  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.