Skip to main content

ParticleDB for Python

import particledb

with particledb.connect() as db:
    db.kv_set(b"session:123", b"active")
    assert db.kv_get(b"session:123") == b"active"

Start a local server

A server started without options requires authentication but has no password set, so start it in one of these two ways. For local development on a trusted machine, turn authentication off and keep every listener on loopback:

particledb start --no-auth --data-dir ./pdb-dev \
  --http-addr 127.0.0.1:7173 --pg-addr 127.0.0.1:5432

To require a password, create the login role from the command line. The password file holds only the password; keep it readable by you alone. SCRAM authenticates without TLS; use TLS for remote access.

particledb start --data-dir ./pdb-dev \
  --http-addr 127.0.0.1:7173 --pg-addr 127.0.0.1:5432 \
  --auth-method scram-sha-256 --pg-username app --pg-password-file ./pdb-password

The SDK connects to localhost:7173 by default. With authentication on, pass the same user and password:

import os
import particledb

with particledb.connect(user="app", password=os.environ["PARTICLEDB_PASSWORD"]) as db:
    assert db.scalar("SELECT 42") == 42

The default address is localhost:7173. Core queries, transactions and streaming use the standard library. Python 3.11 or newer is required.

Install

pip install particledb

The core package has no dependencies. Optional extras add integrations:

pip install "particledb[arrow]"       # query_arrow() and the pyarrow decoder
pip install "particledb[pandas]"      # fetch_df()
pip install "particledb[polars]"      # fetch_polars() and polars bulk_insert
pip install "particledb[sqlalchemy]"  # create_engine("particledb+native://...")
pip install "particledb[grpc]"        # gRPC client

See Python SDK documentation for the matching server.

Remote connections

import os
import particledb

with particledb.connect(
    host="db.example.com",
    user="app",
    password=os.environ["PARTICLEDB_PASSWORD"],
    sslmode="verify-full",
    sslrootcert="ca.pem",
) as db:
    print(db.scalar("SELECT 42"))

verify-full checks the certificate and hostname. Omit sslrootcert to use system roots. TLS uses TCP and refuses plaintext fallback. sslcert and sslkey accept PEM client certificate and key paths. require encrypts without hostname verification; use verify-full for verified remote access.

Queries and transactions

with particledb.connect() as db:
    db.execute("CREATE TABLE items (id BIGINT PRIMARY KEY, name TEXT)")
    db.execute("INSERT INTO items VALUES ($1, $2)", [1, "first"])
    assert db.query("SELECT name FROM items WHERE id = $1", [1]) == [{"name": "first"}]
    with db.transaction() as tx:
        tx.execute("UPDATE items SET name = $1 WHERE id = $2", ["updated", 1])

Parameters are bound separately from SQL. The transaction context commits on successful exit and rolls back on an exception. SQL failures include SQLSTATE; transport failures do not replay a request that may have run. Synchronous write_timeout defaults to 30 seconds and bounds socket writes and waits for another writer. A write timeout closes the connection because the request outcome may be unknown. Set it to None for an unlimited wait. statement_timeout separately bounds response waits and server cancellation.

Malformed connection URLs raise ValueError in the native API and InterfaceError in DB-API and asyncio. Error messages omit the connection string and do not chain the original URL parser exception.

Use stream(sql, parameters) for bounded row iteration and close an iterator early when abandoning a result.

Values decode to Python int, float, bool, str, bytes, Decimal, date, time, datetime, UUID, lists and dictionaries. SQL NULL is None. Decimals preserve their scale. Aware datetimes represent instants; naive datetimes represent timestamps without a time zone.

DB-API and asyncio

from particledb import dbapi

with dbapi.connect() as db:
    with db.cursor() as cursor:
        cursor.execute("SELECT %s AS answer", (42,))
        assert cursor.fetchone() == (42,)

The DB-API defaults to %s parameters. Its connection context manages a transaction. Use autocommit=True for one transaction per statement. Cursors provide fetchone, fetchmany, fetchall, description and executemany. A named cursor streams in bounded memory.

from particledb import aio

async def read_answer():
    async with await aio.connect() as db:
        async with db.cursor() as cursor:
            await cursor.execute("SELECT %s AS answer", (42,))
            return await cursor.fetchone()

The async API follows the DB-API shapes with awaited I/O and async context managers. Cancellation is sent to the server. A connection is reused only when the server confirms the statement's outcome; otherwise it is closed. Do not share an open transaction between unrelated tasks.

DataFrames and SQLAlchemy

Install the corresponding optional extra. DB-API cursors provide fetch_arrow, fetch_df, fetch_polars and fetch_numpy. bulk_insert(table, rows) accepts supported tuples, mappings, generators and DataFrames. Use a transaction for an all-or-nothing application operation.

from sqlalchemy import create_engine, text

engine = create_engine("particledb+native://localhost:7173")
with engine.connect() as db:
    assert db.execute(text("SELECT :answer"), {"answer": 42}).scalar() == 42
engine.dispose()

The dialect supports parameterized SQLAlchemy Core statements, transactions, reflection and streaming. See SUPPORT.md for tested behavior, server limitations and the separate compliance suite.

Validate

PDB_NATIVE_PORT=PORT PDB_TLS_PORT=TLS_PORT PDB_TLS_CA=ca.pem \
  PDB_PG_DSN=postgresql://user@localhost:PG_PORT/sdk_python \
  python -m pytest -q -ra

Use disposable databases. Live tests require the named listeners. SQLAlchemy compliance runs separately against a fresh server directory; it is not part of a plain pytest invocation. See Python SDK documentation.

MIT licensed. See LICENSE.

Metadata

Release files for particledb 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for particledb 0.2.1
File Size Uploaded Provenance
particledb-0.2.1.tar.gz 228.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for particledb 0.2.1
File Interpreter ABI Platform
particledb-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 416.6 kB

Release files / particledb-0.2.1.tar.gz

Download URL particledb-0.2.1.tar.gz
Size 228.9 kB
Tags Source
SHA-256 checksum
How to use checksums
24cd10e869e5557b0db0c3c7d30bb99f24b84aceda7c8c379aae64230ab90fff
BLAKE2b-256 checksum
How to use checksums
5a68f34ed7cce6cff39cd3266eecdcc597b2a0157ace94f67fa80fab8cf1334f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / particledb-0.2.1-py3-none-any.whl

Download URL particledb-0.2.1-py3-none-any.whl
Size 187.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36687d204f5931a212c23e262560f9eff8007e6a1bae0c712a5931aa9bc54b4e
BLAKE2b-256 checksum
How to use checksums
f379164f37bdfe2b67f95bc3407242db197dbc0396d3da9a86eeeed737b28aa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Security for particledb 0.2.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.

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.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page