https://github.com/openspending/babbage.fiscal-data-package
Fiscal Data Package support for babbage
https://github.com/openspending/babbage.fiscal-data-package
Last synced: 6 months ago
JSON representation
Fiscal Data Package support for babbage
- Host: GitHub
- URL: https://github.com/openspending/babbage.fiscal-data-package
- Owner: openspending
- License: mit
- Created: 2015-12-02T21:29:23.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-09-27T19:11:56.000Z (over 8 years ago)
- Last Synced: 2025-11-27T13:18:17.527Z (7 months ago)
- Language: Python
- Homepage:
- Size: 199 KB
- Stars: 3
- Watchers: 5
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Babbage Fiscal Data Package Support
[](https://gitter.im/openspending/chat)
[](https://travis-ci.org/openspending/babbage.fiscal-data-package)
[](https://coveralls.io/github/openspending/babbage.fiscal-data-package?branch=master)
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:
```bash
$ export FISCAL_PACKAGE_ENGINE=
$ bb-fdp-cli load-fdp --package
```
For example:
```bash
$ 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:
```python
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:
```python
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_')