Skip to main content

Identity Lib

This Python package contains shared code related to Identity systems within UIS. It's primary purpose is to encourage code-reuse and to allow for client systems to make use of the same data structures and logic that is contained within our emergent identity APIs.

Use

Install ucam-identitylib using pip:

pip install ucam-identitylib

The module can then be used as identitylib:

from identitylib.identifiers import Identifier

identifier = Identifier.from_string('wgd23@v1.person.identifiers.cam.ac.uk')
print(identifier)

Developer quickstart

This project depends on poetry & poe:

pipx install poetry
pipx inject poetry poethepoet[poetry_plugin]

This project contains a dockerized testing environment which wraps tox.

Tests can be run using the tox poe command:

# Run all PyTest tests and Flake8 checks
$ poetry poe tox

# Run PyTest and Flake8 and recreate test environments
$ poetry poe tox --recreate

# Run just PyTest
$ poetry poe tox -e py3

# Run a single test file within PyTest
$ poetry poe tox -e py3 -- tests/test_identifiers.py

# Run a single test file within PyTest with verbose logging
$ poetry poe tox -e py3 -- tests/test_identifiers.py -vvv

Pulling latest specs from source repositories

Local copies of the OpenAPI specs used to generate the library should be pulled in to this repo so the specific specs used in each build are under revision control. This can be done using the provided poe command:

$ poetry poe pull-specs

# If an access token required for https clones from gitlab repositories
# then this can be specified using:
$ poetry poe pull-specs --token "ACCESS_TOKEN_HERE"

# You may need to first set the $USER environment variable to match the GitLab account name.

Generating the identitylib

The identitylib is generated during the docker build process. To create a local copy of the identitylib distribution use the poe command:

$ poetry poe build-local

This will create a new folder /dist in the current directory with the wheel and tar package for identitylib.

Interactive testing

An interactive testing environment is provided to smoke-test any changes to the identitylib against staging or local instances of the APIs. Note that to test local instance you will need to set the URL in the config file to host.docker.internal:<PORT NUMBER> on linux.

To set up the interactive testing environment, copy the scripts/api-loader-config.yaml.example file to scripts/api-loader-config.yaml and populate with valid API key/secret pairs for any of the APIs you wish to test.

Run the interactive test environment against the latest test release (i.e. uploaded to test.pypi.org) of the library using the poe command:

$ poetry poe interactive-test

To run the interactive tests using a local copy of identitylib from the dist directory:

$ poetry poe interactive-test:local --source dist/ucam_identitylib-1.7.0-py3-none-any.whl

will build the interactive environment from a local wheel stored in the dist directory.

Once the environment is active you can load up test instances and manipulate them using the python interactive console. The LOADER global variable contains a helper class which reads the config file and generates clients based off it:

# Docker build output...
>>> config, client, inst = LOADER.load_card()
>>> inst.v1beta1_cards_list()
... # Output printed to the screen

Use the builtin help command to view info on the LOADER, and the returned api_inst objects that can be used to make requests.

You can view the structure of the generated identitylib package using the get_module_structure function:

>>> import identitylib
>>> from pprint import pprint
>>> pprint(get_module_structure(identitylib))
...

Release files for ucam-identitylib 3.4.1

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

Source distribution (sdist)

Source distribution for ucam-identitylib 3.4.1
File Size Uploaded
ucam_identitylib-3.4.1.tar.gz 239.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ucam-identitylib 3.4.1
File Interpreter ABI Platform
ucam_identitylib-3.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 1.1 MB

Release files / ucam_identitylib-3.4.1.tar.gz

Download URL ucam_identitylib-3.4.1.tar.gz
Size 239.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d1a01d84ad3662e10ef740a8da53252811b0e653aacc9540ccd50f9ca387aff0
BLAKE2b-256 checksum
How to use checksums
2496c6fc98db0991b8af5548f07cfcaf470f018fb9f0f946a314a4258e2c2bc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / ucam_identitylib-3.4.1-py3-none-any.whl

Download URL ucam_identitylib-3.4.1-py3-none-any.whl
Size 857.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc1998d6843d3bebaff6b1518050e605600d2dd0cc0cbebb7139e83d61a1b064
BLAKE2b-256 checksum
How to use checksums
e5b40ad020daeabe0611b59da565f77fbfd02e99cfb7dde5aaf8c7ed49e560e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release history Release notifications | RSS feed

This release

3.4.1 This release

2 release files

3.4.0

2 release files

3.3.2

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.18

2 release files

1.0.16

2 release files

1.0.15

2 release files

1.0.14

2 release files

1.0.13

2 release files

1.0.12

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.0.5

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