How to look up codes and names
Browse a packaged codelist or resolve one code or name to its packaged value with tossd_reader.codes, then pass the result straight to get_tossd.
Steps
-
Browse a dimension's codelist.
tossd.codes.browse(dimension)returns the packaged codelist frame for one of ten dimensions:provider,recipient,pillar,sector,purpose,channel,modality,finance_instrument,financing_arrangement,framework_of_collaboration.import tossd_reader as tossd m = tossd.codes.browse("modality") print(m.head(4).to_string(index=False))code name tossd_only in_published_data A Budget support True False A00 Budget support True True B Core contributions and pooled programmes and funds True False B01 Core support to NGOs, other private bodies, PPPs and research institutes True TrueEvery codelist above carries an
in_published_databool exceptpillar, recording whether the code actually occurs in the published data across the packaged vintages. A codelist can carry entries that published data does not include.modality's one-letter group codes,AandB, readFalsehere, while the detail codes actually filed,A00andB01, readTrue.sectorruns the other way. Its group code700(VIII. Humanitarian Aid) occurs in the data, while the sub-codes beneath it,720,730, and740, fold into the group and readFalse.sectoralone also carries asourcecolumn,codelistfor the OECD-fetched rows anddac-sector-classificationfor the one supplemental row.get_available_filters()returns all ten codelists at once, plus a syntheticyearsentry (eleven keys total), to retrieve all dimensions in a single dictionary. -
Resolve a code or name with
lookup().tossd.codes.lookup(dimension, token)takes a code, a digit-string code, or a name (case-folded), and returns the resolved code. The return type follows the column:provider,recipient,sector,purpose,channel, andfinance_instrumentgive backint;modality,financing_arrangement, andframework_of_collaborationgive backstr. -
Apply the resolved code in a filter.
codes.lookup()resolves a token through the same matching pathfilters=,providers=, andrecipients=use, so the codelookup()returns is exactly what a filter built from that same token matches. A resolvable code can still match zero rows in the published data (sector sub-codes, for example, fold into their top-level group before publishing). See How to filter by sector for the full story.Entities reporting as both providers and recipients
A provider name resolves against the
recipientdimension when the country acts in both roles. Twenty-two entities, including Brazil, Argentina, and Indonesia, are both official providers and official recipients in the TOSSD standard. The lookup raises an error only for provider-only names such as Japan. -
Handle dimensions unsupported by
lookup().browse()accepts all ten packaged dimensions, includingpillar.lookup()covers nine dimensions: every dimension accepted byfilters=, alongsideproviderandrecipient. Pillar tokens such as"II.A"do not map to flat numeric or group codes, solookup()raisesValueErrorand directs queries topillars=. -
Handle unrecognised codes or names. An unresolved token raises
UnknownCodeError, naming the closest matches from the packaged codelist.
Verify it worked
Pass a lookup() result straight to get_tossd and confirm it resolves to matching rows.
import tossd_reader as tossd
code = tossd.codes.lookup("provider", "France")
df = tossd.get_tossd(years=2024, providers=code, columns="minimal")
print(df.shape[0] > 0)
Troubleshooting
UnknownCodeErroron a token expected to resolve. Check the exact packaged spelling withbrowse(dimension)first; the suggestions in the error list the closest packaged names.- A filter built from a
lookup()result matches zero rows. The code resolved, but published data does not carry that granularity. See How to filter by sector. ValueError: Unknown lookup() dimension 'pillar'. Pillar tokens bypasscodes.lookup(). Pass the token directly toget_tossd(pillars=...). See About pillars and aggregate rows.
See also
- Query reference for the full resolution rules behind
providers=,recipients=, andfilters=. - How to filter by sector for applying a resolved code as a filter and the sub-sector granularity story.