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]
__lt__(other)[source]

Return self<value.

__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.

to_csv()[source]

Returns the codelist as CSV content.

property codes

Returns the codes in the codelist.

property fieldnames

Returns all fieldnames used in any rows.

property basename

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

property patch

Returns whether the codelist modifies another codelist.

property addend

Returns whether the codelist adds codes to another codelist.

property subtrahend

Returns whether the codelist removes codes from another codelist.