Gwenlake Python Library
The Gwenlake Python library provides convenient access to the Gwenlake API
from applications written in Python. A single Gwenlake client gives you access
to your catalog — projects, datasets, files and SQL.
Installation
pip install -U gwenlake
Or install the latest development version straight from GitHub:
pip install -U git+https://github.com/gwenlake/gwenlake-python
Authentication
The client authenticates with a Bearer token, resolved in this order:
- an explicit
api_key/credentialspassed to the client, - a named
profile, - the
GWENLAKE_API_KEYenvironment variable, - the
defaultprofile in~/.gwenlake/credentials.
export GWENLAKE_API_KEY='sk-...'
from gwenlake import Gwenlake
# uses GWENLAKE_API_KEY, or the default ~/.gwenlake/credentials profile
client = Gwenlake()
# or pass the key explicitly
client = Gwenlake(api_key="sk-...")
# or pick a profile from ~/.gwenlake/credentials
client = Gwenlake(profile="myteam")
The ~/.gwenlake/credentials file is an INI file with one section per profile,
holding either a static token (API key) or OAuth2 client_id / client_secret.
Projects
projects = client.projects.list()
for p in projects:
print(p["alias"], p["id"])
project = client.projects.get("res.project.…")
Datasets
datasets = client.datasets.list()
for d in datasets:
print(d["alias"], d["id"])
dataset = client.datasets.get("res.dataset.…")
Files
Files live inside a dataset.
dataset_id = "res.dataset.…"
# list files
for f in client.files.list(dataset_id):
print(f["filename"], f["file_size"])
# upload a local file (optionally into a subdirectory with path=...)
client.files.upload(dataset_id, "report.pdf")
client.files.upload(dataset_id, "report.pdf", path="docs")
# download a file
content = client.files.download(dataset_id, "report.pdf")
# presigned URL / delete
url = client.files.presigned_url(dataset_id, "report.pdf")
client.files.delete(dataset_id, "report.pdf")
SQL
Run SQL against a dataset (DuckDB), referencing it as
'<project_alias>.<dataset_alias>'. With format="json" the rows are returned
under data:
result = client.statements.create(
statement="SELECT * FROM 'flights.flight-data' LIMIT 10",
format="json",
)
for row in result["data"]:
print(row)
Pass a connection_id to run the statement against a connection's native engine
(PostgreSQL, S3, …) instead of a dataset.
Transforms
A Palantir Foundry-style transforms layer (gwenlake.transforms) lets you write
dataset-to-dataset transformations as decorated functions. Datasets are
addressed as "<project_alias>.<dataset_alias>" — the same handle used in SQL.
transform_df — the function receives each Input as a pandas.DataFrame and
returns the DataFrame to write to the (single) Output. The result is
written automatically (snapshot/replace by default):
from gwenlake.transforms import transform_df, Input, Output
@transform_df(
raw_data=Input("Project_A.users"),
processed_data=Output("Project_A.users_filtered"),
)
def process(raw_data):
df = raw_data[raw_data["age"] >= 18].copy()
df["name_upper"] = df["name"].str.upper()
return df
process(client) # reads, computes, writes
transform — the lower-level form: the function receives TransformInput /
TransformOutput objects and reads/writes explicitly. Use it for non-tabular
data (images, PDFs, …) via .filesystem():
from gwenlake.transforms import transform, Input, Output
@transform(
my_input=Input("Project_A.users"),
my_output=Output("Project_A.users_distinct"),
)
def dedupe_users(my_input, my_output):
df = my_input.dataframe()
# mode="replace" (default) clears the dataset first; "append" keeps existing files
my_output.write_dataframe(df.drop_duplicates(), mode="replace")
@transform(
images=Input("Project_A.scans"),
thumbnails=Output("Project_A.scans_processed"),
)
def process_files(images, thumbnails):
src, dst = images.filesystem(), thumbnails.filesystem()
for entry in src.ls():
data = src.read(entry["filename"]) # raw bytes (PDF, image, …)
with dst.open(f"copy/{entry['filename']}", "wb") as f:
f.write(data)
Large datasets — page through with LIMIT/OFFSET instead of loading
everything at once. iter_dataframes() yields pandas.DataFrame chunks and
write_dataframes() streams them back out as part-00000.parquet, …:
@transform(
big_dataset=Input("Project_A.events"),
result=Output("Project_A.events_clean"),
)
def transform_in_chunks(big_dataset, result):
chunks = (
chunk[chunk["valid"]]
for chunk in big_dataset.iter_dataframes(chunk_size=50_000, order_by="id")
)
result.write_dataframes(chunks, mode="replace")
Pass order_by= for a deterministic page split. The transforms layer is
synchronous.
Async
Every resource is also available on AsyncGwenlake:
import asyncio
from gwenlake import AsyncGwenlake
async def main():
client = AsyncGwenlake()
print(await client.projects.list())
asyncio.run(main())
See examples/ for runnable scripts.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gwenlake-0.8.0.tar.gz.
File metadata
- Download URL: gwenlake-0.8.0.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13e3b08c6edfc4d714758f8eb69dd900853b5c4cdc35bb17d96784a564d3c3b5
|
|
| MD5 |
2a4c0f300cc5713b958be26034371ca7
|
|
| BLAKE2b-256 |
c0d5e4c70e2fb5bc3b3993603abeee0bae34d16c2e04a4b482876ce196bc7894
|
Provenance
The following attestation bundles were made for gwenlake-0.8.0.tar.gz:
Publisher:
python-publish.yml on gwenlake/gwenlake-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gwenlake-0.8.0.tar.gz -
Subject digest:
13e3b08c6edfc4d714758f8eb69dd900853b5c4cdc35bb17d96784a564d3c3b5 - Sigstore transparency entry: 2176564648
- Sigstore integration time:
-
Permalink:
gwenlake/gwenlake-python@b50721b510cd3e9a4396d1afa2d3054d4f807406 -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/gwenlake
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b50721b510cd3e9a4396d1afa2d3054d4f807406 -
Trigger Event:
release
-
Statement type:
File details
Details for the file gwenlake-0.8.0-py3-none-any.whl.
File metadata
- Download URL: gwenlake-0.8.0-py3-none-any.whl
- Upload date:
- Size: 24.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82edc9323003714f584c09087a4c72a45d67240551be0ebd007ccca27bab5727
|
|
| MD5 |
dc2346c9b7121a68641f2a5e1f26de31
|
|
| BLAKE2b-256 |
269acd2cd8138bbfb79347b54adfd1601f4726aeab20683056fc228defa299cb
|
Provenance
The following attestation bundles were made for gwenlake-0.8.0-py3-none-any.whl:
Publisher:
python-publish.yml on gwenlake/gwenlake-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gwenlake-0.8.0-py3-none-any.whl -
Subject digest:
82edc9323003714f584c09087a4c72a45d67240551be0ebd007ccca27bab5727 - Sigstore transparency entry: 2176564944
- Sigstore integration time:
-
Permalink:
gwenlake/gwenlake-python@b50721b510cd3e9a4396d1afa2d3054d4f807406 -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/gwenlake
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b50721b510cd3e9a4396d1afa2d3054d4f807406 -
Trigger Event:
release
-
Statement type: