# SDK quickstart

The Python and TypeScript clients for the Development Finance Observatory (DFO) call the DFO APIs from code. Use them to build analyses, pipelines, and applications.

You don't need an API key to get started. Guides and changelogs for both are in the [SDK repository](https://github.com/DevelopmentFinanceObservatory/sdk).

## Install

**Python**

`development-finance` imports as `dfo` and needs Python 3.12 or later. The `pandas` extra adds `to_pandas()`.

```bash
uv add "development-finance[pandas]"        # in a uv project
pip install "development-finance[pandas]"   # with pip
```

**TypeScript**

`@developmentfinance/client` is ESM-only and supports both browsers and Node 22.18 or later. The saving and loading steps below need Node.

```bash
npm install @developmentfinance/client
```

## Ask a question

Search interprets your question and returns its interpretation: the indicator, the places, the years, the unit, and the source. This step does not return rows, so you can check the interpretation before you download any.

**Python**

```python
import dfo

answer = dfo.search("ODA from Germany to Nigeria")
print(answer)
```

**TypeScript**

```ts
import { Client } from "@developmentfinance/client";

const client = new Client();
const answer = await client.search("ODA from Germany to Nigeria");
console.log(String(answer));
```

```text
Germany's net disbursements (bilateral flows) to Nigeria for official development assistance, 1960 to 2024. Current US dollars · OECD DAC2a.
  Fetch: answer.fetch()
```

Check the interpretation before you fetch the data. Here, search interpreted "ODA" as net bilateral disbursements in current US dollars. To get a different interpretation, reword the question, for example "gross ODA disbursements from Germany to Nigeria in constant prices". When a question has several interpretations, the answer lists them, numbered from 0. Call `answer.choose(0)` (`await answer.choose(0)` in TypeScript) to get a new answer for the first interpretation.

## Fetch and save the dataset

`answer.fetch()` builds the dataset on the DFO's servers and downloads it.

**Python**

```python
data = answer.fetch()
print(data)

df = data.to_pandas()
print(df.iloc[:, :4].tail(3))

data.save("german-oda.parquet")
```

```text
<Dataset Germany's net disbursements (bilateral flows) to Nigeria for official development assistance, 1960 to 2024. Current US dollars · OECD DAC2a.
  Source: OECD DAC2A
  Version: cv_b8706e8a1459d68a2b78114986e03b83 (exact), held until 16 December 2026, not pinned
  Rows: 65, time_period as integer years
  Keep: data.save(path) · newest later: dfo.fetch(data.ref, latest=True)>
    time_period financingProvider_label financingRecipient_label        value
62         2022                 Germany                  Nigeria  106367247.0
63         2023                 Germany                  Nigeria  118463280.0
64         2024                 Germany                  Nigeria   75121452.0
```

**TypeScript**

```ts
const data = await answer.fetch();
console.log(String(data));

const rows = await data.toRows();
console.log(rows.at(-1));

await data.save("german-oda.parquet");
```

```text
<Dataset Germany's net disbursements (bilateral flows) to Nigeria for official development assistance, 1960 to 2024. Current US dollars · OECD DAC2a.
  Source: OECD DAC2A
  Version: cv_b8706e8a1459d68a2b78114986e03b83 (exact), held until 16 December 2026, not pinned
  Rows: 65, time_period as integer years
  Keep: JSON.stringify(data.ref) · newest later: client.fetch(data.ref, { latest: true })>
{
  time_period: 2024,
  financingProvider_label: 'Germany',
  financingRecipient_label: 'Nigeria',
  value: 75121452,
  unit_label: 'Current US dollars',
  ...
}
```

`data.save()` writes the rows, the citation, and the version reference to one Parquet file.

Your output will differ. The DFO imports new releases of a source, so the `content_version`, the years, and the numbers change over time. The `cv_` id is the `content_version`. It identifies these exact rows.

## Check whether the data changed

`data.ref` identifies the exact version you fetched. Pass it to `fetch()` with `latest` set and compare the returned reference with the saved one. The two references are equal while the DFO serves the same rows.

**Python**

```python
import dfo

old = dfo.load("german-oda.parquet")
new = dfo.fetch(old.ref, latest=True)
if new.ref != old.ref:
    print("The DFO's data has changed since you saved it")
    new.save("german-oda.parquet")
```

`dfo.fetch(old.ref)` without `latest` returns the saved version's rows again, until the date printed after `held until` on the dataset.

**TypeScript**

```ts
import { Client, load } from "@developmentfinance/client";

const client = new Client();
const old = await load("german-oda.parquet");

const newest = await client.fetch(old.ref, { latest: true });
if (!newest.ref.equals(old.ref)) {
  console.log("The DFO's data has changed since you saved it");
  await newest.save("german-oda.parquet");
}
```

`client.fetch(old.ref)` without `latest` returns the saved version's rows again, until the date printed after `held until` on the dataset.

## Next

- Get a free API key in [Keys and limits](/docs/build/keys-and-limits). A script without a key gets 20 API calls a minute for its IP address, and a key gives your account 600.
- Read the [Python](https://github.com/DevelopmentFinanceObservatory/sdk/blob/main/python/README.md) and [TypeScript](https://github.com/DevelopmentFinanceObservatory/sdk/blob/main/typescript/README.md) SDK guides for multiple interpretations, narrowing a fetch, computing a number on the DFO, cards and shares, and pipelines.
- [Call the API directly](/docs/build/api) from any other language.
- Read [Updates and revisions](/docs/data/updates-and-revisions) for how long the DFO keeps a version and what a pinned version is.
