gel-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 gel-python library.
For legacy EdgeDB <v6 support, check the last edgedb-pydantic-codegen release and its PyPI page.
Usage
In an Gel initialized project, simply run
uvx gel-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 gel 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 gel-pydantic-codegen 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gel_pydantic_codegen-1.2.0.tar.gz | 37.1 kB | Without provenance | Details for gel_pydantic_codegen-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gel_pydantic_codegen-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for gel_pydantic_codegen-1.2.0-py3-none-any.whl |
Total release size: 46.4 kB
Release files / gel_pydantic_codegen-1.2.0.tar.gz
| Download URL | gel_pydantic_codegen-1.2.0.tar.gz |
|---|---|
| Size | 37.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f7d790be411dd47d9cbfbf06ef46340317a105280961fd93036525eb47aa0e3
|
|
BLAKE2b-256 checksum How to use checksums |
26a5fa25ab80bac5d18236c55272f59c4689681bf871e4d7267c0b14bd9c5021
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / gel_pydantic_codegen-1.2.0-py3-none-any.whl
| Download URL | gel_pydantic_codegen-1.2.0-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d81e49171d5575e1612507e16689bb41b6030b7ec26774bb9233ebd3bee8194f
|
|
BLAKE2b-256 checksum How to use checksums |
c68a608f0d53fefd1cebccb775050d11d1f5b8c70d07aadd18048540496f0eb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for gel-pydantic-codegen 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.