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, <4.0.0
26.2.x ⚠️ Unreleased yet

Features

  • Connection pooling with configurable pool size
  • Optional automatic node discovery
  • Pluggable load-balancing strategies
  • Shard-aware routing
  • Automatic pool membership reconciliation, including rebalancing a full pool across the nodes
  • Restricting pool connections to replicaset leaders or replicas (instance_role)
  • Temporary ejection of failing instances from pool selection
  • Changing pool settings at runtime (e.g. max_size, topology_update_interval)
  • Asynchronous API based on asyncpg
  • 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.

Metadata

Release files for picopyn 3.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 3.1.0
File Size Uploaded
picopyn-3.1.0.tar.gz 534.3 kB Details

Built distribution (wheel)

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

Total release size: 664.8 kB

Release files / picopyn-3.1.0.tar.gz

Download URL picopyn-3.1.0.tar.gz
Size 534.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b2572966b5d496e4982ec1eef721d2e870f699158299fdd380384e655238423b
BLAKE2b-256 checksum
How to use checksums
bebf8bbbebe7393f339c980c27bedd05b5f6dc37d30352c58dcad1f741f477d1
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-3.1.0-py3-none-any.whl

Download URL picopyn-3.1.0-py3-none-any.whl
Size 130.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67399e9bfdc0b8ba89a17c0a7976f242d1dd5869dc4b49c20b1d898ae5b5f33c
BLAKE2b-256 checksum
How to use checksums
3fe1cec55a5e4001934a1cf6c4d1a1ce3ce746fead837a0a931ee54f948e20df
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

This release

3.1.0 This release

2 release files

3.0.0

2 release files

2.1.0

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