edgedb-pydantic-codegen
This tool generates Python typesafe async code for EdgeQL queries using Pydantic V2.
The generated models can be directly used with other libraries such as FastAPI.
This is an alternative to the built-in code generator of the official edgedb-python library.
Usage
In an EdgeDB initialized project, simply run
uvx edgedb-pydantic-codegen <directory>
All *.edgeql files in <directory> and its subdirectories will be processed and the generated code saved next to them.
Generated code example
from enum import StrEnum
from edgedb import AsyncIOExecutor
from pydantic import BaseModel, TypeAdapter
EDGEQL_QUERY = r"""
with
discord_id := <int64>$discord_id,
moecoins := <optional int32>$moecoins,
blood_shards := <optional int32>$blood_shards,
updated := (
update waicolle::Player
filter .client = global client and .user.discord_id = discord_id
set {
moecoins := .moecoins + (moecoins ?? 0),
blood_shards := .blood_shards + (blood_shards ?? 0),
}
)
select updated {
game_mode,
moecoins,
blood_shards,
user: {
discord_id,
discord_id_str,
},
}
"""
class WaicolleGameMode(StrEnum):
WAIFU = "WAIFU"
HUSBANDO = "HUSBANDO"
ALL = "ALL"
class PlayerAddCoinsResultUser(BaseModel):
discord_id: int
discord_id_str: str
class PlayerAddCoinsResult(BaseModel):
game_mode: WaicolleGameMode
moecoins: int
blood_shards: int
user: PlayerAddCoinsResultUser
adapter = TypeAdapter(PlayerAddCoinsResult | None)
async def player_add_coins(
executor: AsyncIOExecutor,
*,
discord_id: int,
moecoins: int | None = None,
blood_shards: int | None = None,
) -> PlayerAddCoinsResult | None:
resp = await executor.query_single_json(
EDGEQL_QUERY,
discord_id=discord_id,
moecoins=moecoins,
blood_shards=blood_shards,
)
return adapter.validate_json(resp, strict=False)
Caveats
Currently this tool does not support:
TupleType,RangeTypeandMultiRangeTypecollectionsstd::duration,cal::relative_duration,cal::date_duration,cfg::memoryandext::pgvector::vectorobjects
Metadata
Release files for edgedb-pydantic-codegen 2025.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| edgedb_pydantic_codegen-2025.3.1.tar.gz | 26.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| edgedb_pydantic_codegen-2025.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.2 kB
Release files / edgedb_pydantic_codegen-2025.3.1.tar.gz
| Download URL | edgedb_pydantic_codegen-2025.3.1.tar.gz |
|---|---|
| Size | 26.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7330e1e8b34d73dd9c752ba9071487831ebc893910daf2dbb4df13eaf445c2a2
|
|
BLAKE2b-256 checksum How to use checksums |
0e9bae9a54d617c463430f0100b21df165e24eea4279386804558e32807537a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.6.3
|
Release files / edgedb_pydantic_codegen-2025.3.1-py3-none-any.whl
| Download URL | edgedb_pydantic_codegen-2025.3.1-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
021b4fbdbdd279ccab79875fdfe9af40b9d6c573261d143c547666d05f4feeaa
|
|
BLAKE2b-256 checksum How to use checksums |
199aa5e065e17581c6b4dfe9e771f8e0f58d0e3a2feb4b49b88c6c88de014ba6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.6.3
|