Python
gel-python is the official Gel driver for Python. It provides both blocking IO and asyncio implementations.
Installation
Install the client package from PyPI using your package manager of choice.
$
pip install gel$
uv add gelBasic Usage
To start using Gel in Python, create an gel.Client instance using gel.create_client() or gel.create_async_client() for AsyncIO. This client instance manages a pool of connections to the database which it discovers automatically from either being in a gel project init directory or being provided connection details via Environment Variables. See the environment section of the connection reference for more details and options.
If you're using Gel Cloud to host your development instance, you can use the gel cloud login command to authenticate with Gel Cloud and then use the gel project init --server-instance <instance-name> command to create a local project-linked instance that is linked to an Gel Cloud instance. For more details, see the Gel Cloud guide.
import datetime
import gel
client = gel.create_client()
client.query("""
INSERT User {
name := <str>$name,
dob := <cal::local_date>$dob
}
""", name="Bob", dob=datetime.date(1984, 3, 1))
user_set = client.query(
"SELECT User {name, dob} FILTER .name = <str>$name", name="Bob")
# *user_set* now contains
# Set{Object{name := 'Bob', dob := datetime.date(1984, 3, 1)}}
client.close()import asyncio
import datetime
import gel
client = gel.create_async_client()
async def main():
await client.query("""
INSERT User {
name := <str>$name,
dob := <cal::local_date>$dob
}
""", name="Bob", dob=datetime.date(1984, 3, 1))
user_set = await client.query(
"SELECT User {name, dob} FILTER .name = <str>$name", name="Bob")
# *user_set* now contains
# Set{Object{name := 'Bob', dob := datetime.date(1984, 3, 1)}}
await client.aclose()
asyncio.run(main())Client connection pools
For server-type applications that handle frequent requests and need the database connection for a short period of time while handling a request, you will want to use a connection pool. Both gel.Client and gel.AsyncIOClient come with such a pool.
For gel.Client, all methods are thread-safe. You can share the same client instance safely across multiple threads, and run queries concurrently. Likewise, AsyncIOClient is designed to be shared among different asyncio.Task/coroutines for concurrency.
Below is an example of a web API server running fastapi:
import asyncio
import gel
from fastapi import FastAPI, Query
app = FastAPI()
@app.on_event("startup")
async def startup_event():