Skip to main content

Usage

openregister_client.registers.OpenRegister is the base class that accesses a single register and ignores field data typing information. openregister_client.registers.Register and openregister_client.registers.AlphaRegister use the “register” register to discover available registers and the field data types their items should contain. Records, entries and items (the actual data contained in records) returned are dict subclasses that provide typed attributes to access the register data more easily.

Currently, only compatible with Python 3.6+.

Install using pip install openregister-client.

Usage samples:

# direct register usage; field types will not have correct types, but data can be loaded more simply
from openregister_client.registers import OpenRegister

country_register = OpenRegister(name='country')
country_record = country_register.get_record('GB')
print('The official name for GB is %s' % country_record.item.official_name)
if not country_record.item.is_current:
    print('This country is not currently recognised')

# using register auto-discovery to process fields and datatypes
from openregister_client.registers import Register

register = Register()
territory_register = register.get_register('territory')
territory_items = sorted(map(lambda record: record.item, territory_register.get_records()), key=lambda item: item.territory)
for territory in territory_items:
    print('The official name for territory %s is %s' % (territory.territory, territory.official_name))

# make a Django model class; works best when using auto-discovery
from openregister_client.django_compat.model_factory import ModelFactory
from openregister_client.registers import Register

country_register = Register().get_register('country')
with open('models.py', 'wt') as f:
    f.write(ModelFactory(country_register).get_model_code())

# an API key can be provided when instantiating a register class
country_register = OpenRegister(name='country', api_key='YOUR API KEY')

Caching is not implemented. Users of the library can store results of queries or subclass OpenRegister.request to add caching.

Consuming non-json input formats is not supported and probably not necessary.

Development

https://github.com/ministryofjustice/openregister-client/workflows/Run%20tests/badge.svg?branch=master

Please report bugs and open pull requests on GitHub.

Use python setup.py test to run all tests.

Distribute a new version by updating the VERSION tuple in openregister_client/__init__.py and publishing a release in GitHub (this triggers a GitHub Actions workflow to automatically upload it). Alternatively, run python setup.py sdist bdist_wheel upload locally.

To-do

  • Do not paginate past the end since numbers of entries and records are known

  • Perhaps lower minimum Python version to 3.4 or 3.5; use typing module

References

Metadata

Release files for openregister-client 0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openregister-client 0.4
File Size Uploaded
openregister-client-0.4.tar.gz 14.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openregister-client 0.4
File Interpreter ABI Platform
openregister_client-0.4-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 29.3 kB

Release files / openregister-client-0.4.tar.gz

Download URL openregister-client-0.4.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4c90b101364e0465590b922441fd7e6daa406bf192160cf5cb2e6efb8bf8690f
BLAKE2b-256 checksum
How to use checksums
50bb162fb85dd400fc8f28249505a733b6918bf1e9efcc880f1983222d3ce120
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

Release files / openregister_client-0.4-py2.py3-none-any.whl

Download URL openregister_client-0.4-py2.py3-none-any.whl
Size 14.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
4f0fc7b4d986b471ea3539c0f1c06dd55bf28135ce782ad62a148c767c713339
BLAKE2b-256 checksum
How to use checksums
f61ed235cb4c5744b83a953ff8cc93c191ca08c27699f7ae2a64e8516398ed7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

Release history Release notifications | RSS feed

This release

0.4 This release

2 release files

0.3

2 release files

0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page