{ "info": { "author": "Friedrich Lindenberg", "author_email": "friedrich@pudo.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "# Babbage Analytical Engine\n\n[![Gitter](https://img.shields.io/gitter/room/openspending/chat.svg)](https://gitter.im/openspending/chat)\n[![Build Status](https://travis-ci.org/openspending/babbage.svg?branch=master)](https://travis-ci.org/openspending/babbage)\n[![Coverage Status](https://coveralls.io/repos/openspending/babbage/badge.svg?branch=master&service=github)](https://coveralls.io/github/openspending/babbage?branch=master)\n\n``babbage`` is a lightweight implementation of an OLAP-style database\nquery tool for PostgreSQL. Given a database schema and a logical model\nof the data, it can be used to perform analytical queries against that\ndata - programmatically or via a web API.\n\nIt is heavily inspired by [Cubes](http://cubes.databrewery.org/) but\nhas less ambitious goals, i.e. no pre-computation of aggregates, or\nmultiple storage backends.\n\n``babbage`` is not specific to government finances, and could easily be used e.g. for ReGENESIS, a project that makes German national statistics available via an API. The API functions by interpreting modelling metadata generated by the user (measures and dimensions).\n\n## Installation and test\n\n``babbage`` will normally included as a PyPI dependency, or installed via\n``pip``:\n\n```bash\n$ pip install babbage\n```\n\nPeople interested in contributing to the package should instead check out the\nsource repository and then use the provided ``Makefile`` to install the\nlibrary (this requires ``virtualenv`` to be installed):\n\n```bash\n$ git clone https://github.com/openspending/babbage.git\n$ cd babbage\n$ make install\n$ pip install tox\n$ export BABBAGE_TEST_DB=postgresql://postgres@localhost:5432/postgres\n$ make test\n```\n\n## Usage\n\n``babbage`` is used to query a set of existing database tables, using an \nabstract, logical model to query them. A sample of a logical model can be\nfound in ``tests/fixtures/models/cra.json``, and a JSON schema specifying\nthe model is available in ``babbage/schema/model.json``.\n\nThe central unit of ``babbage`` is a ``Cube``, i.e. a [OLAP cube](https://en.wikipedia.org/wiki/OLAP_cube) that uses the provided model metadata to construct queries \nagainst a database table. Additionally, the application supports managing\nmultiple cubes at the same time via a ``CubeManager``, which can be\nsubclassed to enable application-specific ways of defining cubes and where\ntheir metadata is stored.\n\nFuther, ``babbage`` includes a Flask Blueprint that can be used to expose\na standard API via HTTP. This API is consumed by the JavaScript ``babbage.ui``\npackage and it is very closely modelled on the Cubes and OpenSpending HTTP\nAPIs.\n\n### Programmatic usage\n\nLet's assume you have an existing database table of procurement data and\nwant to query it using ``babbage`` in a Python shell. A session might look\nlike this:\n\n```python\nimport json\nfrom sqlalchemy import create_engine\nfrom babbage.cube import Cube\nfrom babbage.model import Measure\n\nengine = create_engine('postgresql://localhost/procurement')\nmodel = json.load(open('procurement_model.json', 'r'))\n\ncube = Cube(engine, 'procurement', model)\nfacts = cube.facts(page_size=5)\n\n# There are 17201 rows in the table:\nassert facts['total_fact_count'] == 17201\n\n# There's a field called 'total_value':\nassert 'total_value' in facts['fields']\n\n# We can get metadata about it:\nconcept = cube.model['total_value']\nassert isinstance(concept, Measure)\nassert concept.label == 'Total Value'\n\n# And there's some actual data:\nassert len(facts['data']) == 5\nfact_0 = facts['data'][0]\nassert 'total_value' in fact_0\n\n# For dimensions, we can get all the distinct values:\nmembers = cube.members('supplier', cut='year:2015', page_size=500)\nassert len(members['data']) <= 500\nassert members['total_member_count']\n\n# And, finally, we can aggregate by specific dimensions:\naggregate = cube.aggregate(aggregates='total_value.sum',\n drilldowns='supplier|authority'\n cut='year:2015|authority.country:GB',\n page_size=500)\n# This translates to: \n# Aggregate the procurement data by summing up the 'total_value'\n# for each unique pair of values in the 'supplier' and 'authority'\n# dimensions, and filter for only those entries where the 'year'\n# dimensions key attribute is '2015' and the 'authority' dimensions\n# 'country' attribute is 'GB'. Return the first 500 results.\nassert aggregate['total_cell_count']\nassert len(aggregate['cells']) <= 500\naggregate_0 = aggregate['cells'][0]\nassert 'total_value.sum' in aggregate_0\n\n# Note that these attribute names are made up for this example, they\n# should be reflected from the model:\nassert 'supplier.code' in aggregate_0\nassert 'supplier.label' in aggregate_0\nassert 'authority.code' in aggregate_0\nassert 'authority.label' in aggregate_0\n```\n\n### Using the HTTP API\n\nThe HTTP API for ``babbage`` is a simple Flask [Blueprint](http://flask.pocoo.org/docs/latest/blueprints/) used to expose a small set of calls that correspond to\nthe cube functions listed above. To include it into an existing Flask\napplication, you would need to create a ``CubeManager`` and then\nconfigure the API like this: \n\n```python\nfrom flask import Flask\nfrom sqlalchemy import create_engine\nfrom babbage.manager import JSONCubeManager\nfrom babbage.api import configure_api\n\napp = Flask('demo')\nengine = \nmodels_directory = 'models/'\nmanager = JSONCubeManager(engine, models_directory)\nblueprint = configure_api(app, manager)\napp.register_blueprint(blueprint, url_prefix='/api/babbage')\n\napp.run()\n```\n\nOf course, you can define your own ``CubeManager``, for example if\nyou wish to retrieve model metadata from a database.\n\nWhen enabled, the API will expose a number of JSON(P) endpoints\nrelative to the given ``url_prefix``:\n\n* ``/``, returns the system status and version.\n* ``/cubes``, returns a list of the available cubes (name only).\n* ``/cubes//model``, returns full metadata for a given \n cube (i.e. measures, dimensions, aggregates etc.)\n* ``/cubes//facts`` is used to return individual entries from\n the cube in a non-aggregated form. Supports filters (``cut``), a\n set of ``fields`` to return and a ``sort`` (``field_name:direction``),\n as well as ``page`` and ``page_size``.\n* ``/cubes//members`` is used to return the distinct set of \n values for a given dimension, e.g. all the suppliers mentioned in\n a procurement dataset. Supports filters (``cut``), a and a ``sort``\n (``field_name:direction``), as well as ``page`` and ``page_size``.\n* ``/cubes//aggregate`` is the main endpoint for generating \n aggregate views of the data. Supports specifying the ``aggregates``\n to include, the ``drilldowns`` to aggregate by, a set of filters\n (``cut``), a and a ``sort`` (``field_name:direction``), as well\n as ``page`` and ``page_size``.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/openspending/babbage", "keywords": "sql sqlalchemy olap cubes analytics", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "babbage", "package_url": "https://pypi.org/project/babbage/", "platform": "", "project_url": "https://pypi.org/project/babbage/", "project_urls": { "Homepage": "http://github.com/openspending/babbage" }, "release_url": "https://pypi.org/project/babbage/0.3.6/", "requires_dist": null, "requires_python": "", "summary": "A light-weight analytical engine for OLAP processing", "version": "0.3.6" }, "last_serial": 3821012, "releases": { "0.0.1": [], "0.1.0": [ { "comment_text": "", "digests": { "md5": "893cfb3e0ccdd47cd52e4374951ebdce", "sha256": "2f11985d5ee79d334d6d3ac01ee54a6a50daad70dadf7ad517758dc627135826" }, "downloads": -1, "filename": "babbage-0.1.0-py2-none-any.whl", "has_sig": false, "md5_digest": "893cfb3e0ccdd47cd52e4374951ebdce", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 20317, "upload_time": "2015-08-21T17:44:53", "url": "https://files.pythonhosted.org/packages/dd/54/6e26b8b68e1334d469faa2d3386132689c47eeef047c1939d7395940dffe/babbage-0.1.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1edac420cb44a53ee2002d2857629178", "sha256": "a9178bbcf1b897e424aa5737651d2d485150ac2cf7c9dcffbc9ada3999505e29" }, "downloads": -1, "filename": "babbage-0.1.0.tar.gz", "has_sig": false, "md5_digest": "1edac420cb44a53ee2002d2857629178", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16505, "upload_time": "2015-08-21T17:41:22", "url": "https://files.pythonhosted.org/packages/40/20/204264155df81dfa5e07cb239f546939814300bf1838c44b0596bc6d2230/babbage-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "5630bd4ebc8b5ba637d271da60bbec52", "sha256": "73414d254d6ccc2912711885764c483e90cf63fb11f08e8edee1b312d8a227d5" }, "downloads": -1, "filename": "babbage-0.1.1-py2-none-any.whl", "has_sig": false, "md5_digest": "5630bd4ebc8b5ba637d271da60bbec52", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 20318, "upload_time": "2015-08-21T17:45:48", "url": "https://files.pythonhosted.org/packages/4c/80/cc8d1aa544bd19b3127c34969c8734fa7e21ff896880a2db70834b03a73c/babbage-0.1.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f80faf802c804f34fb2d7a2b78d7c2ae", "sha256": "c324e3f8b3a8b051a2d084b70409d673817c2e5ccd445d41c20b39bbe99b71ee" }, "downloads": -1, "filename": "babbage-0.1.1.tar.gz", "has_sig": false, "md5_digest": "f80faf802c804f34fb2d7a2b78d7c2ae", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16488, "upload_time": "2015-08-21T17:45:43", "url": "https://files.pythonhosted.org/packages/4e/e7/ce20b0292240dd20458b7f1b46c2407b1ff61a629149c415970c6750f882/babbage-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "8d9115b2fb3381920a9ac4b08a691b98", "sha256": "4ce49a417dce3c629c64870c048831b856ac8319586ff8ed053dbae6c302b651" }, "downloads": -1, "filename": "babbage-0.2.0.tar.gz", "has_sig": false, "md5_digest": "8d9115b2fb3381920a9ac4b08a691b98", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16469, "upload_time": "2016-07-05T15:29:30", "url": "https://files.pythonhosted.org/packages/86/76/498510c34a3323bd0625e58481241bacc9bc4ec7d0d9309327e64afd0457/babbage-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "a3e662b73a4ead4a3fb9eed74bf50330", "sha256": "1ca587c88b4e8ffba88d8fd3e1ae7c1f523be5f302000da5fa1e27bdb40b13ea" }, "downloads": -1, "filename": "babbage-0.2.1.tar.gz", "has_sig": false, "md5_digest": "a3e662b73a4ead4a3fb9eed74bf50330", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16549, "upload_time": "2017-04-21T05:05:58", "url": "https://files.pythonhosted.org/packages/1e/e8/9107d24aa2bfbd97d01a9967bf8c0511029b0ab603ac0598ea723b5b335f/babbage-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "11d68a541da3b6f8ecafa640403fb224", "sha256": "3d575af2fd5efb2f5ee1c1305cdf8f36b5563500fe0f67ede2064b7d3ade2982" }, "downloads": -1, "filename": "babbage-0.2.2.tar.gz", "has_sig": false, "md5_digest": "11d68a541da3b6f8ecafa640403fb224", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16997, "upload_time": "2017-08-08T06:22:46", "url": "https://files.pythonhosted.org/packages/9f/a4/1eadf2bfa3a5b18c0c26c1825502a09c84e45a2a2412318a0149af50ee8b/babbage-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "e5455227dc63bd1b35bf02f5c08b0bbd", "sha256": "ddca3d76919efa6cfc0b51163e889c25df11dfc891302d4d31634c31ec031634" }, "downloads": -1, "filename": "babbage-0.2.3.tar.gz", "has_sig": false, "md5_digest": "e5455227dc63bd1b35bf02f5c08b0bbd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16961, "upload_time": "2017-08-08T07:42:41", "url": "https://files.pythonhosted.org/packages/4b/f2/7eabdc84beb64ea9f7f7c242c1086c337391d632ee353c2047220c2a9fb0/babbage-0.2.3.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "67eee7c7f23efa95cba1a5da29572103", "sha256": "b33175c744e7dbf858d2af2e6681799dcdc6dc2f96307dd062042d722b3c69c8" }, "downloads": -1, "filename": "babbage-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "67eee7c7f23efa95cba1a5da29572103", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 23646, "upload_time": "2017-08-10T14:21:29", "url": "https://files.pythonhosted.org/packages/46/fd/ae8853a8efe7f79f433d86a8d3d00688fef05d7744bfeda2970e3eecf2a4/babbage-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "db153ab8188056d40f37e8672edfd718", "sha256": "4038bf5021ddb7a6a9ee6686b56627fb7e874be057b135d99e5e9fd03a69812e" }, "downloads": -1, "filename": "babbage-0.3.0.tar.gz", "has_sig": false, "md5_digest": "db153ab8188056d40f37e8672edfd718", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17379, "upload_time": "2017-08-10T14:21:31", "url": "https://files.pythonhosted.org/packages/37/9b/3489ae5b4fd9c1b4603c56544c6f30a6b3c2c649d482d826d3fb0cddfc7b/babbage-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "9b950666dd373bf378760994fe55c8d6", "sha256": "3ec4b197e5ec1ceaba6cf742d98458e0c0e819eb8c1910c0f382b1f82248e572" }, "downloads": -1, "filename": "babbage-0.3.1-py3-none-any.whl", "has_sig": false, "md5_digest": "9b950666dd373bf378760994fe55c8d6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 23652, "upload_time": "2017-08-19T15:40:42", "url": "https://files.pythonhosted.org/packages/46/8c/198705699b5496e7e35db6bad815431b67ee057250a01754de09de249813/babbage-0.3.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "08aa5c059e1673a07ce30d5de09f6932", "sha256": "94c123f6378385be91713f2aeed8ce772266ba3874abc563e1404ccf21c745b5" }, "downloads": -1, "filename": "babbage-0.3.1.tar.gz", "has_sig": false, "md5_digest": "08aa5c059e1673a07ce30d5de09f6932", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17359, "upload_time": "2017-08-19T15:40:43", "url": "https://files.pythonhosted.org/packages/1f/2d/32678d435aae0ad5abd189c200c9713170e1c4b645e1ea04eb606d627938/babbage-0.3.1.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "666b8dc8bc8f90e93faf0efc0c20d2b8", "sha256": "fd132af1be16cd956eb02eeed181d04529cc1fa252c246ab7b27fb62551f3673" }, "downloads": -1, "filename": "babbage-0.3.2.tar.gz", "has_sig": false, "md5_digest": "666b8dc8bc8f90e93faf0efc0c20d2b8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17282, "upload_time": "2017-09-27T18:02:28", "url": "https://files.pythonhosted.org/packages/5c/28/c598c1e202ae26b250266edd4a770d12ec28ed3177f3906fe3448b712ef1/babbage-0.3.2.tar.gz" } ], "0.3.3": [ { "comment_text": "", "digests": { "md5": "1f8c784bd47f8f619b48be4139b2e74d", "sha256": "60ec445d6767a8e8bfd958620e89281bbf1c768bad09028434c6707ecac7cd3a" }, "downloads": -1, "filename": "babbage-0.3.3.tar.gz", "has_sig": false, "md5_digest": "1f8c784bd47f8f619b48be4139b2e74d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17272, "upload_time": "2017-09-27T19:07:39", "url": "https://files.pythonhosted.org/packages/d4/10/6f2e035ec4c35f07658bf29def1632a4b0cae396dd7f9f3ae465f3113cdc/babbage-0.3.3.tar.gz" } ], "0.3.4": [ { "comment_text": "", "digests": { "md5": "56e5b7c0a54b0279351222eed4c63fee", "sha256": "eeb5acf91a0620789d1974825c862d957b59c68e6283c23ba2cc972ca2d5ff33" }, "downloads": -1, "filename": "babbage-0.3.4.tar.gz", "has_sig": false, "md5_digest": "56e5b7c0a54b0279351222eed4c63fee", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17393, "upload_time": "2018-03-11T20:26:15", "url": "https://files.pythonhosted.org/packages/7d/af/78a42f6a8fd3a7051d50cc4fc691f7337106c274092c5e015b44abac7443/babbage-0.3.4.tar.gz" } ], "0.3.5": [ { "comment_text": "", "digests": { "md5": "e2af3774faf252ff6125d6b25948fa2f", "sha256": "29ffabb28a060d37712eb315f88286337fda42cd08935db6836ad24169e0aea8" }, "downloads": -1, "filename": "babbage-0.3.5-py3.6.egg", "has_sig": false, "md5_digest": "e2af3774faf252ff6125d6b25948fa2f", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 57200, "upload_time": "2018-04-30T14:38:22", "url": "https://files.pythonhosted.org/packages/38/7a/27260cb153a3774fd82687fc40f6991ef5c16f47357af7962e36e1fd29bd/babbage-0.3.5-py3.6.egg" }, { "comment_text": "", "digests": { "md5": "251e23444de76ed7533423e38525c21f", "sha256": "dac5c3c1da333ad0b6d7520db302617c85f07f0b40d1fbb8e6435b64b8e24c99" }, "downloads": -1, "filename": "babbage-0.3.5.tar.gz", "has_sig": false, "md5_digest": "251e23444de76ed7533423e38525c21f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17404, "upload_time": "2018-03-12T08:17:43", "url": "https://files.pythonhosted.org/packages/e7/a2/c7966cfd3de2a4fe89dc8af0da1eb1d974b8b29bea05597e0b22c4a147e8/babbage-0.3.5.tar.gz" } ], "0.3.6": [ { "comment_text": "", "digests": { "md5": "8f0b0a673318adbfeeb2314737e53700", "sha256": "e033267278b125d4cc2212027e4233df86afac96db2ab19b82fc90d7a93ffa65" }, "downloads": -1, "filename": "babbage-0.3.6.tar.gz", "has_sig": false, "md5_digest": "8f0b0a673318adbfeeb2314737e53700", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17981, "upload_time": "2018-04-30T14:38:23", "url": "https://files.pythonhosted.org/packages/df/e8/40a345c4f242b9e01bb00dffc5e1e4b1386e7690d28baf528d5a0b4bbd4c/babbage-0.3.6.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8f0b0a673318adbfeeb2314737e53700", "sha256": "e033267278b125d4cc2212027e4233df86afac96db2ab19b82fc90d7a93ffa65" }, "downloads": -1, "filename": "babbage-0.3.6.tar.gz", "has_sig": false, "md5_digest": "8f0b0a673318adbfeeb2314737e53700", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17981, "upload_time": "2018-04-30T14:38:23", "url": "https://files.pythonhosted.org/packages/df/e8/40a345c4f242b9e01bb00dffc5e1e4b1386e7690d28baf528d5a0b4bbd4c/babbage-0.3.6.tar.gz" } ] }