Packager#

ocdskit.packager.adapt_json(data)[source]#
ocdskit.packager.convert_json(string)[source]#
class ocdskit.packager.Packager[source]#

The Packager context manager helps to build a single record package, or a stream of compiled releases or merged releases. Release packages and/or individual releases can be added to the packager. All releases should use the same version of OCDS.

add(data)[source]#

Adds release packages and/or individual releases to be merged.

Parameters

data – an iterable of release packages and individual releases

Raises

InconsistentVersionError – if the versions are inconsistent across packages to merge

output_package(merger, return_versioned_release=False, use_linked_releases=False, streaming=False)[source]#

Yields a record package.

Parameters
  • merger (ocdsmerge.merge.Merger) – a merger

  • return_versioned_release (bool) – whether to include a versioned release in each record

  • use_linked_releases (bool) – whether to use linked releases instead of full releases, if possible

  • streaming (bool) – whether to set the package’s records to a generator instead of a list

output_records(merger, return_versioned_release=False, use_linked_releases=False)[source]#

Yields records, ordered by OCID.

Parameters
  • merger (ocdsmerge.merge.Merger) – a merger

  • return_versioned_release (bool) – whether to include a versioned release in the record

  • use_linked_releases (bool) – whether to use linked releases instead of full releases, if possible

output_releases(merger, return_versioned_release=False)[source]#

Yields compiled releases or versioned releases, ordered by OCID.

Parameters
  • merger (ocdsmerge.merge.Merger) – a merger

  • return_versioned_release (bool) – whether to yield versioned releases instead of compiled releases

class ocdskit.packager.AbstractBackend[source]#
add_release(release, package_uri)[source]#

Adds a release to the backend. (The release might be added to an internal buffer.)

Raises

MissingOcidKeyError – if the release is missing an ocid field

abstract get_releases_by_ocid()[source]#

Yields an OCIDs and an iterable of tuples of (ocid, package_uri, release).

OCIDs are yielded in alphabetical order. The iterable is in any order.

flush()[source]#

Flushes the internal buffer of releases. This may be a no-op on some backends.

close()[source]#

Tidies up any resources used by the backend. This may be a no-op on some backends.

class ocdskit.packager.PythonBackend[source]#
get_releases_by_ocid()[source]#

Yields an OCIDs and an iterable of tuples of (ocid, package_uri, release).

OCIDs are yielded in alphabetical order. The iterable is in any order.

class ocdskit.packager.SQLiteBackend[source]#
flush()[source]#

Flushes the internal buffer of releases. This may be a no-op on some backends.

get_releases_by_ocid()[source]#

Yields an OCIDs and an iterable of tuples of (ocid, package_uri, release).

OCIDs are yielded in alphabetical order. The iterable is in any order.

close()[source]#

Tidies up any resources used by the backend. This may be a no-op on some backends.