# SDKs

The official TypeScript and Python SDKs, generated from the API itself.

Both are generated from [openapi.json](/openapi.json) at each release, so every endpoint in the [API reference](/api) is a typed method, with its sample on its page.

<Tabs items={["TypeScript", "Python"]} groupId="language">
<Tab value="TypeScript">

```bash
npm install rizamo
```

</Tab>
<Tab value="Python">

```bash
pip install rizamo
```

</Tab>
</Tabs>

## Set up the client [#set-up-the-client]

It reads your API key from `RIZAMO_API_KEY` ([Authentication](/authentication)), or takes it as `apiKey` (`api_key` in Python).

<Tabs items={["TypeScript", "Python"]} groupId="language">
<Tab value="TypeScript">

```ts
import { RizamoClient } from "rizamo";

const rizamo = new RizamoClient();
```

</Tab>
<Tab value="Python">

```python
from rizamo import Rizamo

rizamo = Rizamo()
```

`AsyncRizamo` takes the same calls with `await`.

</Tab>
</Tabs>

## Schedule a post [#schedule-a-post]

An endpoint is a method named after it: [Create a post](/api/posts/create) is `rizamo.posts.create`. Fields keep the API's names in TypeScript and are snake_case in Python.

<Tabs items={["TypeScript", "Python"]} groupId="language">
<Tab value="TypeScript">

```ts
const post = await rizamo.posts.create({
  profileId: "prof_...",
  targets: [{ accountId: "acc_..." }],
  text: "Hello from the Rizamo API",
  mediaIds: ["med_..."],
  status: "scheduled",
  scheduledAt: "2027-06-01T09:00:00Z",
});
console.log(post.id);
```

</Tab>
<Tab value="Python">

```python
import datetime

post = rizamo.posts.create(
    profile_id="prof_...",
    targets=[{"account_id": "acc_..."}],
    text="Hello from the Rizamo API",
    media_ids=["med_..."],
    status="scheduled",
    scheduled_at=datetime.datetime.fromisoformat("2027-06-01T09:00:00+00:00"),
)
print(post.id)
```

A local time, which Rizamo reads in the profile's time zone ([Dates and time zones](/conventions#dates-and-time-zones)), goes as a string such as `"2027-06-01T09:00"`: a `datetime` without a time zone is sent in your machine's.

</Tab>
</Tabs>

## Lists [#lists]

Loop over a list and the SDK asks for the next page as you go ([Pages](/conventions#pages)).

<Tabs items={["TypeScript", "Python"]} groupId="language">
<Tab value="TypeScript">

```ts
for await (const post of await rizamo.posts.list({ status: "scheduled" })) {
  console.log(post.id);
}
```

</Tab>
<Tab value="Python">

```python
for post in rizamo.posts.list(status="scheduled"):
    print(post.id)
```

</Tab>
</Tabs>

## Errors and retries [#errors-and-retries]

An error answer is thrown with its status and Rizamo's [error body](/errors). Calls other than `POST` retry by themselves on a timeout, a rate limit or a server error, twice, waiting `Retry-After` when there is one. A `POST` never retries by itself: send an idempotency key and retry it yourself ([Retries](/errors#retries)).

<Tabs items={["TypeScript", "Python"]} groupId="language">
<Tab value="TypeScript">

```ts
import { RizamoError } from "rizamo";

try {
  await rizamo.posts.publish({ id: "post_..." }, { idempotencyKey: crypto.randomUUID() });
} catch (error) {
  if (error instanceof RizamoError) console.log(error.statusCode, error.body);
}
```

</Tab>
<Tab value="Python">

```python
import uuid
from rizamo.core.api_error import ApiError

try:
    rizamo.posts.publish(id="post_...", idempotency_key=str(uuid.uuid4()))
except ApiError as error:
    print(error.status_code, error.body)
```

</Tab>
</Tabs>

## Versions [#versions]

Rizamo adds fields and values within v1 ([Versions](/conventions#versions)), and both SDKs let the ones they do not know through, so an older release keeps working. Update it to get their types.

- TypeScript: [`rizamo` on npm](https://www.npmjs.com/package/rizamo), code at [rizamohq/rizamo-node](https://github.com/rizamohq/rizamo-node).
- Python: [`rizamo` on PyPI](https://pypi.org/project/rizamo/), code at [rizamohq/rizamo-python](https://github.com/rizamohq/rizamo-python).
