{"id":35060901,"url":"https://github.com/openspending/babbage","last_synced_at":"2025-12-27T10:31:56.193Z","repository":{"id":57413605,"uuid":"38893307","full_name":"openspending/babbage","owner":"openspending","description":"A light-weight, OLAP-style analytical engine for Postgres (focused on OpenSpending)","archived":false,"fork":false,"pushed_at":"2022-11-20T16:34:02.000Z","size":116,"stargazers_count":38,"open_issues_count":13,"forks_count":16,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-11-07T17:17:00.766Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openspending.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-10T17:31:47.000Z","updated_at":"2025-06-17T13:07:54.000Z","dependencies_parsed_at":"2023-01-22T01:54:39.909Z","dependency_job_id":null,"html_url":"https://github.com/openspending/babbage","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/openspending/babbage","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openspending%2Fbabbage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openspending%2Fbabbage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openspending%2Fbabbage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openspending%2Fbabbage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openspending","download_url":"https://codeload.github.com/openspending/babbage/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openspending%2Fbabbage/sbom","scorecard":{"id":710341,"data":{"date":"2025-08-11","repo":{"name":"github.com/openspending/babbage","commit":"9416105fd18dda13b06aaaeec0ce7abdd13d8453"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/27 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 10 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-22T07:59:52.619Z","repository_id":57413605,"created_at":"2025-08-22T07:59:52.619Z","updated_at":"2025-08-22T07:59:52.619Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28077502,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-27T02:00:05.897Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-27T10:31:54.711Z","updated_at":"2025-12-27T10:31:56.187Z","avatar_url":"https://github.com/openspending.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 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\u0026service=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']) \u003c= 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']) \u003c= 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/\u003cname\u003e/model``, returns full metadata for a given \n  cube (i.e. measures, dimensions, aggregates etc.)\n* ``/cubes/\u003cname\u003e/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/\u003cname\u003e/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/\u003cname\u003e/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``.\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenspending%2Fbabbage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenspending%2Fbabbage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenspending%2Fbabbage/lists"}