Skip to main content

No project description provided

Project description

A single package for accessing Nomis, Open Geography Portal, TfL Open Data Hub, and more


New name

The package previously known as LBLDataAccess has now been rebranded as Consensus. The package aims to create a single pipeline from Open Geography Portal to Nomis and other UK public data APIs. Currently, there are six modules:

  1. EsriConnector (extendable module to connect to ESRI FeatureServers);
  2. EsriServers, which contains two built-in servers that rely on Esri ArcGIS REST API: OpenGeography (Open Geography Portal connector) and TFL (TfL Open Data Hub connector);
  3. Nomis (API tool to download data from www.nomisweb.co.uk);
  4. GeocodeMerger (a graph theory-based tool that helps with downloading and merging multiple tables from Open Geography Portal);
  5. LG Inform Plus API (can only be used if your institution is a subscriber); and
  6. LocalMerger (a local version of GeocodeMerger designed to help you with building a DuckDB database from an assortment of local files based on shared column names) - this has not yet been fully implemented.

TODO and help needed:

  1. The next stage in the development is to create a DuckDB database cache backend that is searched before a query to Open Geography Portal is made and extended with every new call of FeatureServer class. Likewise, this database could be made use of to build a local storage of Nomis and other APIs.
  2. Implement geometry search for Open Geography Portal.
  3. Create tests for LocalMerger and improve its functionality.
  4. Add more APIs, for instance ONS, EPC, MetOffice. Easy wins would be to add more ESRI servers as they can be easily plugged in with the EsriConnector class (see how it is done with TFL module, for instance).
  5. Improve GeocodeMerger.py by adding the ability to choose additional nodes in the graph so that the graph is guided through these columns.
  6. Clean up code. I have relaxed the conditions to ignore PEP8:E501 and PEP8:E402 for flake8.
  7. Improve documentation. This will be a forever job.
  8. Add more test cases and examples.
  9. Reformat SmartLinker to use networkx (for 2.0 release).
  10. Pipeline improvements.

Purpose

The main purpose of this Python package is to allow easier navigation of the NOMIS API and easier collection of GSS geocodes from ONS Open Geography Portal. The GSS geocodes are necessary for selecting the right tables in the NOMIS API, which can otherwise be very difficult to navigate.

This package also includes a class to help with selecting data from LG Inform Plus, if your institution is a subscriber.

The caveats

The current version of the package relies on access to Open Geography Portal, but their ESRI servers are not always available. The official response from ONS and ESRI was that we can only keep trying, and while the package automatically retries whenever connection is lost, the download times can be at times quite long.

The second caveat is that the output from SmartLinker class is not guaranteed to contain the correct tables, but there is built-in capability to choose which tables you want to merge. This requires some knowledge of the data in the tables themselves, however. You may also be more interested in population weighted joins, which this package does not perform (only left joins are supported at the moment). However, the FeatureServer class does support downloading geometries from Open Geography Portal and NOMIS contains Census 2021 data for demographics, so in theory, you should be able to create your own population weighted joins using just this package.

Note that this package does not create any sort of file caches, so you should implement your own. This is in the todo pile for the package.

Installation

To install this package:

python -m pip install git+https://github.com/Ilkka-LBL/Consensus.git

Or

python -m pip install -U Consensus

Configuration

To begin using this package, you need to configure your API keys and proxies. To help with this, there is a ConfigManager class:

from Consensus.ConfigManager import ConfigManager

This class has three methods for saving, updating, and resetting the config.json file. The config.json file resides in the folder config inside the package installation folder.

The default config.json file contents are:

self.default_config = {
            "nomis_api_key": "",
            "lg_inform_key": "",
            "lg_inform_secret": "",
            "proxies": {
                "http": "",
                "https": ""
            }
        }

For the DownloadFromNomis class to function, you must provide at least the API key nomis_api_key, which you can get by signig up on www.nomisweb.co.uk and heading to your profile settings.

Minimum example:

from Consensus.ConfigManager import ConfigManager

config_dict = {"nomis_api_key": "your_new_api_key_value"}

conf = ConfigManager()
conf.update_config(config_dict)

If you also want to add proxies:

from Consensus.ConfigManager import ConfigManager

config_dict = {
                "nomis_api_key": "your_new_api_key_value", 
                "proxies.http": "your_proxy",
                "proxies.https": "your_proxy"
              }

conf = ConfigManager()
conf.update_config(config_dict)

NB! The config.json file requirements

Note that the modules and classes in this package rely on the keys provided in this config file. However, you can extend the config.json file with the .update_config() method, just remember to pass in the old

Building a lookup table for an Esri server

Building a lookup file (e.g. Open_Geography_Portal_lookup.json) and the associated pickle file (Open_Geography_Portal.pickle) is very much recommended if you want to make full use of the capabilities of this package:

from Consensus.EsriServers import OpenGeography  # could import TFL as well
import asyncio

def main():
    og = OpenGeography(max_retries=30)
    asyncio.run(og.build_lookup(replace_old=True))

if __name__ == "__main__":
    main()

or inside Jupyter notebook cells:

from Consensus.EsriServers import OpenGeography
og = OpenGeography(max_retries=30)
await og.build_lookup(replace_old=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

consensus-1.2.1.tar.gz (462.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

consensus-1.2.1-py3-none-any.whl (476.1 kB view details)

Uploaded Python 3

Consensus-1.2.1-py3-none-any.whl (475.8 kB view details)

Uploaded Python 3

File details

Details for the file consensus-1.2.1.tar.gz.

File metadata

  • Download URL: consensus-1.2.1.tar.gz
  • Upload date:
  • Size: 462.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for consensus-1.2.1.tar.gz
Algorithm Hash digest
SHA256 4834822dbcbe1b11a0410257ef57f048e351af5dcba01c90af472dfe896a5ade
MD5 07567fa1a75e27744c31f2f32264fcb7
BLAKE2b-256 45a60701e68bbad9d2591890ed790ed3f82e26b0ab20403b10da4c81ab756251

See more details on using hashes here.

File details

Details for the file consensus-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: consensus-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 476.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for consensus-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad427732e0fd77dd81762e5f9e734844b540110061d2846c00d95117495df538
MD5 595c2d74937ad095b8bd9f5214fc4ded
BLAKE2b-256 61fe981d71b373272c5f5e847caaf060e6227093e0d769d9acfd86831c1da61a

See more details on using hashes here.

File details

Details for the file Consensus-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: Consensus-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 475.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for Consensus-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa9e2c3c19c1d7c541d3682f91ccd80219c3a59ae7cf6c9511aae5d0e4c7d477
MD5 c1b461b1c715d515a6efdada3a434bc7
BLAKE2b-256 3f70e6470c02aba4cf18e4bece1fa1d24bcebcb6c7b9e105a67cbe3e4fabf7ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page