D1py
A modern, async Python client for the Cloudflare D1 REST API.
D1 is Cloudflare's serverless SQLite-based database. D1py gives you full programmatic access to manage databases, run queries, import/export data, and use time-travel — all from Python with first-class async support.
Highlights
- Async-first — built on
httpx.AsyncClientwith HTTP/2 and connection pooling for high throughput - Full D1 API — every endpoint covered: database CRUD, queries, batches, export/import, time travel
- Type-safe — Pydantic v2 models for all request params and responses, full IDE autocomplete
- Sync fallback — every method has a
*_sync()variant for scripts and notebooks - Automatic retries — exponential backoff on 5xx and network errors, configurable
- Context manager — clean resource lifecycle with
async with
Install
pip install cfd1py
From source:
git clone https://github.com/Suleman-Elahi/D1py && cd D1py
pip install .
Requires Python 3.10+. Dependencies: httpx, pydantic.
Quick Example
import asyncio
from D1py import D1py
async def main():
async with D1py(account_id="xxx", api_token="xxx") as d1:
db = await d1.create_database("my-app")
await d1.query(db.uuid, "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)")
await d1.query(db.uuid, "INSERT INTO users (name) VALUES (?)", params=["Alice"])
results = await d1.query(db.uuid, "SELECT * FROM users")
print(results[0].results)
asyncio.run(main())
Documentation
| Guide | What it covers |
|---|---|
| Getting Started | Installation, authentication, first query |
| Database Management | Create, list, get, update, delete databases |
| Queries | Single queries, parameterized queries, batch queries, raw queries |
| Export & Import | Export databases to SQL, import SQL files |
| Time Travel | Bookmarks, restore to point-in-time |
| Configuration | Client options, timeouts, retries, connection pooling |
| Error Handling | Exception types, error codes, retry behavior |
| Async vs Sync | When to use async, sync wrappers, patterns |
API At a Glance
Database management: list_databases, create_database, get_database, update_database, patch_database, delete_database
Queries: query, query_batch, raw_query, raw_query_batch
Data ops: export_database, import_database
Time travel: get_bookmark, restore
Every async method has a sync counterpart (e.g. query_sync, create_database_sync).
License
MIT
Metadata
Release files for cfd1py 2.0.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 |
|---|---|---|---|---|
| cfd1py-2.0.0.tar.gz | 48.3 kB | Without provenance | Details for cfd1py-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cfd1py-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for cfd1py-2.0.0-py3-none-any.whl |
Total release size: 57.2 kB
Release files / cfd1py-2.0.0.tar.gz
| Download URL | cfd1py-2.0.0.tar.gz |
|---|---|
| Size | 48.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6bcd843643c448ce6e81841bdcd6e2b5743d78355ad13de9affa78054ae3b38
|
|
BLAKE2b-256 checksum How to use checksums |
b5fe962c5865a5f04c419be936a256d84afef2a9e8074e400ea3311564eec4ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / cfd1py-2.0.0-py3-none-any.whl
| Download URL | cfd1py-2.0.0-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5c5069326da341d27a65196e34c6ff2ca766a21f3109b24a521d472df252db41
|
|
BLAKE2b-256 checksum How to use checksums |
9a567e82e686777e65864bebc55b622680505ec5f65d5cc0857f0fa6f8028486
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for cfd1py 2.0.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.