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/master/extensions.csv'
extension_versions_url = 'https://raw.githubusercontent.com/open-contracting/extension_registry/master/extension_versions.csv'

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

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.3/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.