API and Bi-directional converter babbage/fdp

schema, jsontableschema, jts, fdp, fiscal, data, babbage
pip install babbage_fiscal==0.0.10


Babbage Fiscal Data Package Support

Gitter Build Status Coverage Status

This module is intended to provide support for loading OKFN's Fiscal Data Packages into a DB, while creating an internal model compatible with babbage.


This section is intended to be used by end-users of the library.


To get started (under development):

$ pip install babbage_fiscal


To run the tests, make sure you have an ElasticSearch running locally on http://localhost:9200 and run:

$ tox

Command-line interface

You can use the library using a simple command line interface:

$ export FISCAL_PACKAGE_ENGINE=<database-connection-string>
$ bb-fdp-cli load-fdp --package <path--or-url-of-datapackage.json>

For example:

$ bb-fdp-cli load-fdp --package

Python API

You can access the same functionality using a Python interface:

from babbage_fiscal import FDPLoader

FDPLoader().load_fdp_to_db(package, engine)

# engine is an SQLAlchemy engine. 
# if not supplied, will create one based on the FISCAL_PACKAGE_ENGINE env variable

API interface

The package also provides a Flask Blueprint, which exposes one endpoint with the following parameters:

  • package: URL for datapackage.json
  • callback: URL to call once load is complete

Example usage:

from flask import Flask
from babbage_fiscal import FDPLoaderBlueprint

app = Flask('demo')
app.register_blueprint(FDPLoaderBlueprint, url_prefix='/loader')

Design Overview

Internally the loader uses the following packages

  • datapackage to parse the provided data-package and load its resources
  • jts-sql to load the data into the database

The internal ModelRegistry class is used for managing the babbage models in the provided database. All models are stored in a dedicated table (''models'').

In order to avoid contention, all other resource data is stored in dedicated tables, whose names get prefixed by a constant value (current;y 'fdp_')