Extension Registry#

Filter the versions of extensions in the registry, and access information about matching versions:

from ocdsextensionregistry import ExtensionRegistry

extensions_url = 'https://raw.githubusercontent.com/open-contracting/extension_registry/main/extensions.csv'
extension_versions_url = 'https://raw.githubusercontent.com/open-contracting/extension_registry/main/extension_versions.csv'

registry = ExtensionRegistry(extension_versions_url, extensions_url)
for version in registry.filter(core=True, version='v1.1.4', category='tender'):
    print(f'The {version.metadata[name][en]} extension ("{version.id}") is maintained at {version.repository_html_page}')
    print(f'Run `git clone {version.repository_url}` to make a local copy in a {version.repository_name} directory')
    print(f'Get its patch at {version.base_url}release-schema.json\n')

Output:

The Enquiries extension ("enquiries") is maintained at https://github.com/open-contracting-extensions/ocds_enquiry_extension
Run `git clone git@github.com:open-contracting-extensions/ocds_enquiry_extension.git` to make a local copy in a ocds_enquiry_extension directory
Get its patch at https://raw.githubusercontent.com/open-contracting-extensions/ocds_enquiry_extension/v1.1.4/release-schema.json

To work with the files within a version of an extension:

  • metadata() parses and provides consistent access to the information in extension.json

  • schemas() returns the parsed contents of schema files

  • codelists() returns the parsed contents of codelist files (see more below)

  • files() returns the unparsed contents of all files

See additional details in Extension Version.

class ocdsextensionregistry.extension_registry.ExtensionRegistry(extension_versions_data, extensions_data=None)[source]#
__init__(extension_versions_data, extensions_data=None)[source]#

Accepts extension_versions.csv and, optionally, extensions.csv as either URLs or data (as string) and reads them into ExtensionVersion objects. If extensions_data is not provided, the extension versions will not have category or core properties. URLs starting with file:// will be read from the filesystem.

filter(**kwargs)[source]#

Returns the extension versions in the registry that match the keyword arguments.

Raises:

MissingExtensionMetadata – if the keyword arguments refer to extensions data, but the extension registry was not initialized with extensions data

get(**kwargs)[source]#

Returns the first extension version in the registry that matches the keyword arguments.

Raises:
  • DoesNotExist – if no extension version matches

  • MissingExtensionMetadata – if the keyword arguments refer to extensions data, but the extension registry was not initialized with extensions data

get_from_url(url)[source]#

Returns the first extension version in the registry whose base URL matches the given URL.

Raises:

DoesNotExist – if no extension version matches

__iter__()[source]#

Iterates over the extension versions in the registry.