Skip to content

Python

Our API Reference has generic examples in every supported language, and we strive to make the experience of each SDK very similar. However, there are some things specific to the Python SDK that we want to call out here.

Types

All of the generated Python code includes type hints, which should help your editor get the most out of the code.

Async/Await

Python client SDK code uses async/await. You’ll need to use asyncio to run its methods.

Key Path Helper

The key_path function can be used to format an ID value (especially a UUID) correctly to include in a key path:

1
from statelydb import key_path
2
kp = key_path("/movie-{id}/actor-{actor_id}",
3
id=result.id, actor_id=actor_id)

Checking an Item’s Type

Many client APIs return a list of items, but you want to know exactly what type each item is.

1
if isinstance(item, Movie):
2
print(f"[Movie] title: {item.title}")
3
elif isinstance(item, Character):
4
print(f"[Character] name: {item.name}")

UUIDs

UUIDs are represented as the uuid.UUID type.