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):

    {'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:  # ['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]

Return self<value.


Return repr(self).

extend(rows, extension_name=None)[source]

Adds rows to the codelist.


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


Removes deprecated codes and the Deprecated column.


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.