Skip to content

picopyn

picopyn is a Python connector for working with the distributed Picodata database.

Version compatibility:

Picodata version Status
>=25.4.x, < 26.2.x ✅ Fully supported
26.2.x ⚠️ Not yet tested

Features

  • Connection pooling with configurable pool size
  • Optional automatic node discovery
  • Pluggable load-balancing strategies
  • Asynchronous API based on asyncpg
  • Synchronous DPAPI-compatible API based on psycopg

Quick start

pip install picopyn

Async:

import asyncio
from picopyn.asynchronous import Client

async def main():
    client = Client(dsn="postgresql://admin:pass@localhost:5432")
    await client.connect()

    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);
    ''')

    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

conn = connect("postgresql://admin:pass@localhost:5432")
cur = conn.cursor()

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);
''')

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

conn.close()

See Installation for all install options.