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 the release build

This release is not published to PyPI yet. Build a wheel with python -m build from this directory and install the resulting particledb-0.2.0-py3-none-any.whl in your application. Optional extras are arrow, pandas, polars, sqlalchemy and grpc. 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.0

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.0
File Size Uploaded Provenance
particledb-0.2.0.tar.gz 228.9 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 416.6 kB

Release files / particledb-0.2.0.tar.gz

Download URL particledb-0.2.0.tar.gz
Size 228.9 kB
Tags Source
SHA-256 checksum
How to use checksums
21dc513a2bb86e990a16e29669b423cacf34b90f4648a1b346d0c8f8061b9b77
BLAKE2b-256 checksum
How to use checksums
4e4ce5cb32244010ce82b3e8941c62febbb2c65a9ff56711b0d4633858b8a499
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.0-py3-none-any.whl

Download URL particledb-0.2.0-py3-none-any.whl
Size 187.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c833c3f0398c206da7ef308ca5c7af984a5873aadd86d661709fe0e3129a3756
BLAKE2b-256 checksum
How to use checksums
e67303a362b451cd7a2fbd63c5266dfc04bc7eff6f45c3b7a8038e30000f6c19
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.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.

Release history Release notifications | RSS feed

This release

0.2.0 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