The OpenSpending API is a Python app that provides a range of API endpoints to query an OpenSpending database.
- An analytical API powered by Babbage
- A search API to access package-level meta data
- A search API to access fiscal line-level data.
- A set of backwards-compatible OpenSpending V2 endpoints
You need to have Python 2.7.x or Python 3 to run the API. The API itself is a set of Flask blueprints. We recommend using Python 3.
The API can be installed as a component of the Platform, or as a stand alone component.
Which installation method should you choose?
- If your goal is to get a full instance of OpenSpending running, then go ahead with the platform installation.
- If you just want to hack on the API (Suggest new features! Fix bugs!), or even run your own API against a remote OpenSpending platform, then follow the standalone install.
If the options are confusing, then go ahead with the platform installation. This will allow you to easily upload new data into the platform, modify the API code and see how that affects the visualisation engines.
Follow the instructions for installing a development environment for the OpenSpending platform here.
Follow these steps to get the API running:
$ git clone https://github.com/openspending/os-api.git $ cd os-api $ export OS_API_ENGINE=sqlite:///`pwd`/osapi.db $ celery -A babbage_fiscal.tasks worker & $ python dev_server.py
Based on the default configuration of the API, you can now work with your local OpenSpending database hosted on your local machine. If you want to point to a different OpenSpending instance, configure your environment variables accordingly based on the details below.
- Returns the Fiscal Data-Pacakge for this dataset
- Returns a list of the available datasets in the store
- Returns the
babbagemodel for the dataset. This is the model which is used when querying the data.
- Returns individual entries from the dataset in non-aggregated form.
cut- filters on the data (
fields- fields to return
order- data ordering (e.g.
pagesize- number of entries in one batch of returned data
page- page selection
- Returns the distinct set of values for a specific dimension.
- Returns an aggregate of the data in the specified dataset.
drilldown- group by these dimensions (e.g.
aggregates- which measures to aggregate (and what function to perform (e.g.
- A backwards compatible version of the aggregate API.
dataset- dataset to query
measure- measure to aggregate
cut- filters on the data
drilldown- fields to group by the results
page_size- as above
order- same as
Found a bug? Got neat way to refactor an existing code path? Bursting with ideas to make OpenSpending more awesome?
We can't wait to see your contributions. Here are a few things that will help:
- All open issues for the API can be found here, labeled "API". If you are working on an existing issue, please let us know by commenting on an issue. Likewise, if you are working on something new, open an issue to let us know.
If anything is unclear, or you just want to talk with other people working on OpenSpending, then catch us on Gitter.im.