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
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
  • Synchronous DPAPI-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 Client

async def main():
    # create and connect client to the picodata cluster
    client = Client(dsn="postgresql://admin:pass@localhost:5432")
    await client.connect()

    # execute DDL operations
    await client.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 client.execute('INSERT INTO "warehouse" VALUES ($1::int, $2::varchar)', 1, "test")
    rows = await client.fetch('SELECT * FROM "warehouse"')
    print(rows)

    await client.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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

picopyn-2.0.0.tar.gz (473.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

picopyn-2.0.0-py3-none-any.whl (68.0 kB view details)

Uploaded Python 3

File details

Details for the file picopyn-2.0.0.tar.gz.

File metadata

  • Download URL: picopyn-2.0.0.tar.gz
  • Upload date:
  • Size: 473.0 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for picopyn-2.0.0.tar.gz
Algorithm Hash digest
SHA256 e9a2bf05b88ae5d67deef8fbbaa52c6956df81e9cac09ca78051e37962b30767
MD5 4c4faa7c687781798f29ee0076046d4e
BLAKE2b-256 053fc0538b285f70c3cdb8ffd1846b42ca02c43f33d8a4909e0608518522e81c

See more details on using hashes here.

File details

Details for the file picopyn-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: picopyn-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 68.0 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for picopyn-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e3e8b5d9381913679db0cf5d882e069df74a0ad7bdeeadf2e147c77b576e483
MD5 4516c81e6212d893a64a847ad872b0f1
BLAKE2b-256 c47721b42a93e749521c167060994353b1a1726e44a430227985f32f705d59ce

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 files

1.0.0

2 files

0.2.0

2 files

0.1.1

2 files

0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page