Skip to content

openspending/babbage.fiscal-data-package

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Usage

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

Installation

To get started (under development):

$ pip install babbage_fiscal

Testing

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 https://raw.githubusercontent.com/openspending/fiscal-data-package-demos/update-to-reflect-new-specs/boost-moldova/datapackage.json

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')

app.run()

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_')

About

Fiscal Data Package support for babbage

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages