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:
release_schema_patch()
to get the profile’s patch ofrelease-schema.json
patched_release_schema()
to get the patched version ofrelease-schema.json
extension_codelists()
to get the profile’s codelistspatched_codelists()
to get the patched codelistsextensions()
to iterate over the profile’s versions of extensions
- 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'
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 afile://
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/'
- release_schema_patch(*, extension_field=None, extension_value='name', language='en')[source]¶
Return the consolidated release schema patch.
Use
extension_field
andextension_value
to annotate each definition and field with the extension that defined or patched it.- Parameters:
- 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
andextension_value
to annotate each definition and field with the extension that defined or patched it.- Parameters:
schema (dict) – the release schema
language (str) – see
release_schema_patch()
andget_standard_file_contents()
kwargs – see
release_schema_patch()
- 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:
schema (dict) – the base release package schema
patched (dict) – the patched release schema
embed (bool) – whether to embed or
$ref
’erence the patched release schemaproxies (bool) – whether to replace references with proxy objects
language (str) – see
release_schema_patch()
andget_standard_file_contents()
kwargs – see
release_schema_patch()
- 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:
schema (dict) – the base record package schema
patched (dict) – the patched release schema
proxies (bool) – whether to replace references with proxy objects
embed (bool) – whether to embed or
$ref
’erence the patched release schemalanguage (str) – see
release_schema_patch()
andget_standard_file_contents()
kwargs – see
release_schema_patch()
- 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.
- 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