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:

from statelydb import key_path
kp = key_path("/movie-{id}/actor-{actor_id}",
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.

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

UUIDs

UUIDs are represented as the uuid.UUID type.