Skip to main content

Version Supported Versions Documentation

Picopyn - Picodata Python driver

Picopyn is a Python package for working with the distributed Picodata database.

Version compatibility:

Picodata version Picopyn version
>=25.2.1, <25.4.4 0.1.1
>=25.4.4, <25.5.1 0.2.0
>=25.5.1, <26.1.x 1.0.0
>=26.1.1, <26.2.x 2.0.0, 2.1.0
26.2.x ⚠️ Unreleased yet

Features

  • Connection pooling with configurable pool size
  • Optional automatic node discovery
  • Pluggable load-balancing strategies
  • Asynchronous API based on asyncpg
    • (async only) Shard-aware routing
    • (async only) Automatic pool membership reconciliation, including rebalancing a full pool across the nodes
  • Synchronous DB-API 2.0-compatible API based on psycopg

Navigation

Installation

pip install picopyn

Or from source:

git clone https://git.picodata.io/core/drivers/picopyn.git
cd picopyn
pip install -e .

Quickstart

Async:

import asyncio
from picopyn.asynchronous import Pool

async def main():
    # create and open pool to the picodata cluster
    pool = Pool(dsn="postgresql://admin:pass@localhost:5432", enable_discovery=True)
    await pool.open()

    # execute DDL operations
    await pool.execute('''
        CREATE TABLE "warehouse" (id INTEGER NOT NULL, item TEXT NOT NULL, PRIMARY KEY (id)) USING memtx DISTRIBUTED BY (id) OPTION (TIMEOUT = 3.0);
    ''')

    # execute DML/DQL operations
    await pool.execute('INSERT INTO "warehouse" VALUES ($1::int, $2::varchar)', 1, "test")
    rows = await pool.fetch('SELECT * FROM "warehouse"')
    print(rows)

    await pool.close()

asyncio.run(main())

Sync:

from picopyn.synchronous import connect

# create and connect to the picodata cluster
with connect("postgresql://admin:pass@localhost:5432") as conn:
    cur = conn.cursor()

    # execute DDL operations
    cur.execute('''
        CREATE TABLE "warehouse" (id INTEGER NOT NULL, item TEXT NOT NULL, PRIMARY KEY (id)) USING memtx DISTRIBUTED BY (id) OPTION (TIMEOUT = 3.0);
    ''')

    # execute DML/DQL operations
    cur.execute('INSERT INTO "warehouse" VALUES (%s, %s)', (1, "test"))
    cur.execute('SELECT * FROM "warehouse"')
    print(cur.fetchall())

Development

For development we use uv as package manager and docker compose for test environment.

To install development dependencies:

uv sync --extra test

Inside the test container, run the same command to keep dependencies up to date if the image is outdated:

make shell
# inside the container:
make install

Documentation

The documentation is written in Markdown and built with MkDocs using the Material theme. API reference is generated automatically from docstrings via mkdocstrings.

Published documentation is available at picopyn.readthedocs.io.

Source files are located in the docs/ directory. To work on docs locally, install the docs dependencies and start the live-reload server:

uv sync --extra docs
make doc

How to write code

We use several tools to ensure code style and type safety.

  • ruff — code style, lint checks and automatic lint fixing
  • mypy — static type checking
  • black — code formatting

To check code style and static types:

make lint

To automatically fix formatting and style issues:

make fmt

How to test

We use docker compose for test environment.

Run the general test suite:

make test

or run SSL tests:

make test-ssl

This will:

  1. Start required test containers (Picodata cluster and test-runner) using Docker Compose

  2. Execute tests using pytest

How to debug

Do not forget to run the environment via make env

For debugging purposes:

  1. Open a bash shell in the test container:
make shell
  1. For interactive Python (with asyncio support) run inside of container:
python -m asyncio
  1. To connect directly to Picodata:
picodata admin tmp/data/picodata-1-1/admin.sock

Benchmark

Benchmark instructions and usage examples are available here.

Release files for picopyn 2.1.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 picopyn 2.1.0
File Size Uploaded
picopyn-2.1.0.tar.gz 484.3 kB Details

Built distribution (wheel)

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

Total release size: 562.5 kB

Release files / picopyn-2.1.0.tar.gz

Download URL picopyn-2.1.0.tar.gz
Size 484.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2aa66d1942b7d35a3f35a41d1b8734b253f4e128dea8fae1e52a1c048762e983
BLAKE2b-256 checksum
How to use checksums
02be3338985abfc8e829b5933e31d0597d529891977af959004bc31f08982bd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / picopyn-2.1.0-py3-none-any.whl

Download URL picopyn-2.1.0-py3-none-any.whl
Size 78.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30ce80f419f0b3d0b3817f6edd0e4e01a4299d0958dff84ef9fccd40341f14f3
BLAKE2b-256 checksum
How to use checksums
ecdc0b52d37b9a672a874be238ae30a9b5821f53f6eb2915adb604ed0d7d227a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

3.0.0

2 release files

This release

2.1.0 This release

2 release files

2.0.0

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1

2 release files

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