kiarina-lib-cloudflare-d1
English | 日本語
Dependencies
| Package | Version | License |
|---|---|---|
| HTTPX | >=0.28.1 |
BSD-3-Clause |
| kiarina-lib-cloudflare | >=1.5.0 |
MIT |
| pydantic-settings | >=2.10.1 |
MIT |
| pydantic-settings-manager | >=3.2.0 |
MIT |
Installation
pip install kiarina-lib-cloudflare-d1
Features
- Database Configuration Manage D1 database IDs separately from Cloudflare credentials.
- Parameterized Queries Send SQL and positional parameters to the D1 REST API.
- Named Configurations Select among multiple databases and Cloudflare accounts by settings key.
- Synchronous and Asynchronous APIs Use the same operation through synchronous and asynchronous clients.
Configuring a Database
The D1 and Cloudflare authentication managers can each hold multiple named settings.
kiarina.lib.cloudflare_d1:
default: production
configs:
production:
database_id: "your-database-id"
kiarina.lib.cloudflare:
default: production
configs:
production:
account_id: "your-account-id"
api_token: "your-api-token"
Load the settings when the application starts.
import yaml
from pydantic_settings_manager import load_user_configs
with open("config.yaml", encoding="utf-8") as file:
load_user_configs(yaml.safe_load(file) or {})
A single default configuration can also be provided with environment variables.
export KIARINA_LIB_CLOUDFLARE_D1_DATABASE_ID="your-database-id"
export KIARINA_LIB_CLOUDFLARE_ACCOUNT_ID="your-account-id"
export KIARINA_LIB_CLOUDFLARE_API_TOKEN="your-api-token"
Using the Synchronous Client
query returns the D1 JSON response regardless of HTTP status. Check success or call raise_for_status.
from kiarina.lib.cloudflare_d1 import create_d1_client
client = create_d1_client()
result = client.query(
"SELECT * FROM users WHERE id = ?",
[1],
)
result.raise_for_status()
for row in result.first.rows:
print(row)
Using Named Configurations
D1 settings and authentication settings can be selected independently.
from kiarina.lib.cloudflare_d1 import create_d1_client
client = create_d1_client(
settings_key="production",
auth_settings_key="production",
)
Using the Asynchronous Client
Await query when using the asynchronous client.
from kiarina.lib.cloudflare_d1.asyncio import create_d1_client
client = create_d1_client()
result = await client.query(
"SELECT * FROM users WHERE id = ?",
[1],
)
result.raise_for_status()
API Reference
kiarina.lib.cloudflare_d1
from kiarina.lib.cloudflare_d1 import (
D1Client,
D1Settings,
create_d1_client,
settings_manager,
)
create_d1_client
def create_d1_client(
settings_key: str | None = None,
*,
auth_settings_key: str | None = None,
) -> D1Client: ...
Creates a synchronous client from D1 settings and Cloudflare authentication settings.
Parameters
settings_key(str | None): D1 settings key.Noneselects the default settings.auth_settings_key(str | None): Cloudflare authentication settings key.Noneselects the default settings.
D1Client
class D1Client:
def __init__(
self,
settings: D1Settings,
*,
auth_settings: CloudflareSettings,
) -> None: ...
def query(
self,
sql: str,
params: list[Any] | None = None,
) -> Result: ...
The query result provides these attributes and methods:
success(bool): Whether the overall API request succeeded.result(list[QueryResult]): Results for the SQL statements.errors(list[ResponseInfo]): Errors returned by the API.messages(list[ResponseInfo]): Messages returned by the API.first(QueryResult): The first result. RaisesValueErrorwhen no result is available.raise_for_status() -> None: RaisesRuntimeErrorwhensuccessisFalse.
Each QueryResult has success, meta, and results attributes. rows is an alias for results.
D1Settings
class D1Settings(BaseSettings):
database_id: str
Settings for a Cloudflare D1 database.
Fields
database_id(str): Cloudflare D1 database ID.
settings_manager
settings_manager: SettingsManager[D1Settings]
Manages multiple named D1 settings.
kiarina.lib.cloudflare_d1.asyncio
from kiarina.lib.cloudflare_d1.asyncio import (
D1Client,
D1Settings,
create_d1_client,
settings_manager,
)
create_d1_client
def create_d1_client(
settings_key: str | None = None,
*,
auth_settings_key: str | None = None,
) -> D1Client: ...
Creates an asynchronous client. Its parameters are the same as the synchronous API.
D1Client
class D1Client:
def __init__(
self,
settings: D1Settings,
*,
auth_settings: CloudflareSettings,
) -> None: ...
async def query(
self,
sql: str,
params: list[Any] | None = None,
) -> Result: ...
Its parameters and return values are the same as the synchronous client.
D1Settings and settings_manager are the same objects exported by the synchronous API.
Metadata
Release files for kiarina-lib-cloudflare-d1 2.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 | Provenance | Actions |
|---|---|---|---|---|
| kiarina_lib_cloudflare_d1-2.3.1.tar.gz | 10.1 kB | With provenance | Details for kiarina_lib_cloudflare_d1-2.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kiarina_lib_cloudflare_d1-2.3.1-py3-none-any.whl | Python 3 | none | any | Details for kiarina_lib_cloudflare_d1-2.3.1-py3-none-any.whl |
Total release size: 21.5 kB
Release files / kiarina_lib_cloudflare_d1-2.3.1.tar.gz
| Download URL | kiarina_lib_cloudflare_d1-2.3.1.tar.gz |
|---|---|
| Size | 10.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4c2a2812057589551f93fc9db261ccfac29932f8d8857d53770cd866e8347112
|
|
BLAKE2b-256 checksum How to use checksums |
0442f3afbaf19511188567306d6da9bd0bbe42d98a87b639f2000c2c918d5d78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 2, 2026.
Transparency logRelease files / kiarina_lib_cloudflare_d1-2.3.1-py3-none-any.whl
| Download URL | kiarina_lib_cloudflare_d1-2.3.1-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2395a5ae45ee42cc5dc1df51c0cc1f89776a385df5f1ce3e0c399a436b128b2
|
|
BLAKE2b-256 checksum How to use checksums |
4af8248acd47d53f82cee4b0e453c077cdfb590a1986c4b444a9ad9e06727f19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 2, 2026.
Transparency logSecurity for kiarina-lib-cloudflare-d1 2.3.1
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for kiarina_lib_cloudflare_d1-2.3.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 2, 2026.
Transparency logA 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.