Profile Builder

Build an OCDS profile.

from ocdsextensionregistry import ProfileBuilder

builder = ProfileBuilder('1__1__4', {
    'lots': 'v1.1.4',
    'bids': 'v1.1.4',
})

This initializes a profile of OCDS 1.1.4 with two extensions. Alternately, you can pass a list of extensions’ metadata URLs, base URLs, download URLs, and/or absolute paths to local directories, for example:

builder = ProfileBuilder('1__1__4', [
  'https://raw.githubusercontent.com/open-contracting-extensions/ocds_coveredBy_extension/master/extension.json',
  'https://raw.githubusercontent.com/open-contracting-extensions/ocds_options_extension/master/',
  'https://github.com/open-contracting-extensions/ocds_techniques_extension/archive/master.zip',
])

After initializing the profile, you can then:

class ocdsextensionregistry.profile_builder.ProfileBuilder(standard_tag, extension_versions, registry_base_url=None, standard_base_url=None, schema_base_url=None)[source]
__init__(standard_tag, extension_versions, registry_base_url=None, standard_base_url=None, schema_base_url=None)[source]

Accept an OCDS version and either a dictionary of extension identifiers and versions, or a list of extensions’ metadata URLs, base URLs and/or download URLs, and initialize a reader of the extension registry.

Attention

This method is vulnerable to server-side request forgery (SSRF). A user can create a release package or record package whose extension URLs point to internal resources, which would receive a GET request.

Parameters:
  • standard_tag (str) – the OCDS version tag, e.g. '1__1__4'

  • extension_versions (dict or list) – the extension versions

  • registry_base_url (str) – the registry’s base URL, defaults to 'https://raw.githubusercontent.com/open-contracting/extension_registry/main/'

  • standard_base_url (str or bytes) – the standard’s base URL, defaults to f'https://codeload.github.com/open-contracting/standard/zip/{standard_tag}' (can be a file:// URL to a directory or a ZIP file, or the bytes of a ZIP file)

  • schema_base_url (str) – the schema’s base URL, e.g. 'https://standard.open-contracting.org/profiles/ppp/schema/1__0__0__beta/'

extensions()[source]

Return the matching extension versions from the registry.

release_schema_patch(*, extension_field=None, extension_value='name', language='en')[source]

Return the consolidated release schema patch.

Use extension_field and extension_value to annotate each definition and field with the extension that defined or patched it.

Parameters:
  • extension_field (str) – the name of the property to add to each definition and field in the extension

  • extension_value (str) – the value of the property to add to each definition and field in the extension, either the ‘name’ or ‘url’

  • language (str) – the language to use for the name of the extension

Warns ExtensionWarning:

if the release schema patch’s URL is not a supported scheme, if the request fails, if the bulk file is not a ZIP file, or if the release schema patch is not UTF-8 or not JSON

Raises:

NotImplementedError – if the extension_value is not recognized

patched_release_schema(*, schema=None, language='en', **kwargs)[source]

Return the patched release schema.

Use extension_field and extension_value to annotate each definition and field with the extension that defined or patched it.

Parameters:
release_package_schema(*, schema=None, patched=None, embed=False, proxies=False, language='en', **kwargs)[source]

Return a release package schema.

If the profile builder was initialized with schema_base_url, update schema URLs.

Parameters:
record_package_schema(*, schema=None, patched=None, embed=False, proxies=False, language='en', **kwargs)[source]

Return a record package schema.

If the profile builder was initialized with schema_base_url, update schema URLs.

Parameters:
standard_codelists()[source]

Return the standard’s codelists as Codelist objects.

extension_codelists()[source]

Return the extensions’ codelists as Codelist objects.

The extensions’ codelists may be new, or may add codes to (+name.csv), remove codes from (-name.csv) or replace (name.csv) the codelists of the standard or other extensions.

Codelist additions and removals are merged across extensions. If new codelists or codelist replacements differ across extensions, an error is raised.

patched_codelists()[source]

Return patched and new codelists as Codelist objects.

get_standard_file_contents(basename, language='en')[source]

Return the contents of the file within the standard.

Download the given version of the standard, and cache the contents of files in the schema/ directory.

Replace the {{lang}} and {{version}} placeholders in files.

Parameters:

language (str) – the string with which to replace {{lang}} placeholders