Codelist

from ocdsextensionregistry import Codelist

Create a new codelist:

codelist = Codelist('+partyRole.csv')

Add codes to the codelist (you can provide any iterable, including a csv.DictReader):

codelist.extend([
    {'Code': 'publicAuthority', 'Title': 'Public authority', 'Description': ''},
    {'Code': 'bidder', 'Title': 'Bidder', 'Description': ''}
])

Iterate over the codes in the codelist:

[code['Title'] for code in codelist]  # ['Public authority', 'Bidder']

Read the codelists’ codes and fieldnames:

codelist.codes  # ['publicAuthority', 'bidder']
codelist.fieldnames  # ['Code', 'Title', 'Description']

Determine whether the codelist adds or removes codes from another codelist:

codelist.patch  # True
codelist.addend  # True
codelist.subtrahend  # False

Get the name of the codelist it modifies:

codelist.basename  # 'partyRole.csv'
class ocdsextensionregistry.codelist.Codelist(name)[source]
__init__(name)[source]

Initialize self. See help(type(self)) for accurate signature.

__repr__()[source]

Return repr(self).

extend(rows, extension_name=None)[source]

Adds rows to the codelist.

add_extension_column(field_name)[source]

Adds a column for the name of the extension from which codes originate.

remove_deprecated_codes()[source]

Removes deprecated codes and the Deprecated column.

codes

Returns the codes in the codelist.

fieldnames

Returns all fieldnames used in any rows.

basename

If the codelist modifies another codelist, returns the latter’s name. Otherwise, returns its own name.

patch

Returns whether the codelist modifies another codelist.

addend

Returns whether the codelist adds codes to another codelist.

subtrahend

Returns whether the codelist removes codes from another codelist.