Skip to main content

A production-grade Python Prisma client

Project description

Aprisma

A Python Prisma client backed by SQLAlchemy — no Node.js or Rust at runtime.

Aprisma reads a standard schema.prisma file and generates a fully-typed async Python client. All queries run through SQLAlchemy Core — SQLite, PostgreSQL, and any other SQLAlchemy dialect work out of the box.

db = Prisma()
await db.connect("sqlite+aiosqlite:///dev.db")

alice = await db.user.create(data={"email": "alice@example.com", "name": "Alice"})

posts = await db.post.find_many(
    where={"author": {"email": "alice@example.com"}, "published": True},
    include={"author": True},
    order={"createdAt": "desc"},
)

await db.disconnect()

Why Aprisma?

The original prisma-client-py is no longer maintained and requires a Rust query engine and a Node.js subprocess at every query. Aprisma replaces that with a pure-Python SQLAlchemy layer — the Prisma CLI is only used during development to manage migrations, never at runtime.

prisma-client-py Aprisma
Runtime dependency Rust engine + Node.js None
Query layer Prisma Query Engine SQLAlchemy Core
Schema format Prisma schema Prisma schema
Async support Yes Yes
Type safety Yes Yes (Pydantic v2)

Features

  • Pure Python runtime — no Node.js process, no Rust binary, no subprocess at query time
  • Async-first — every method is async; built for asyncio
  • Fully typed — Pydantic v2 models, TypedDict query inputs, typed relation attributes
  • Prisma v7 schema — use the standard schema format and the official Prisma CLI for migrations
  • SQLAlchemy backend — JOIN-based relation filtering, correlated EXISTS subqueries, connection pooling
  • Rich query API — filtering, ordering, pagination (offset and cursor), distinct, include, select, transactions, raw queries, group_by aggregations

Installation

pip install aprisma

For PostgreSQL:

pip install "aprisma[postgresql]"

Aprisma uses the Prisma CLI (a Node.js tool) for schema migrations. It is only needed during development — see Prisma CLI Setup for a one-time setup guide.


Quick start

1. Write a schema

# schema.prisma

generator client {
  provider  = "aprisma"
  output    = "./prisma"
  interface = "asyncio"
}

datasource db {
  provider = "sqlite"
}

model User {
  id    Int    @id @default(autoincrement())
  email String @unique
  name  String
  posts Post[]
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String
  published Boolean @default(false)
  authorId  Int
  author    User    @relation(fields: [authorId], references: [id])
}

2. Push the schema and generate the client

# Push schema to the database (creates tables)
npx prisma db push --url "file:./dev.db"

# Generate the Python client
aprisma generate --schema schema.prisma

3. Use it

import asyncio
from prisma import Prisma

async def main():
    db = Prisma()
    await db.connect("sqlite+aiosqlite:///dev.db")

    # Create a user
    alice = await db.user.create(
        data={"email": "alice@example.com", "name": "Alice"}
    )

    # Create a post linked to that user
    post = await db.post.create(
        data={"title": "Hello world", "content": "My first post.", "authorId": alice.id},
        include={"author": True},
    )
    print(post.author.name)  # Alice

    # Filter posts through a related model
    posts = await db.post.find_many(
        where={"author": {"email": "alice@example.com"}},
        include={"author": True},
        order={"title": "asc"},
    )

    # Update
    await db.post.update(
        where={"id": post.id},
        data={"published": True},
    )

    # Count
    n = await db.post.count(where={"published": True})
    print(f"{n} published post(s)")

    # Delete
    await db.post.delete(where={"id": post.id})

    await db.disconnect()

asyncio.run(main())

Database support

Database Driver Install
SQLite aiosqlite included
PostgreSQL asyncpg pip install "aprisma[postgresql]"
Any SQLAlchemy dialect bring your own pass the URL to connect()

Documentation

Full documentation: xlaszlo.github.io/aprisma


Contributing

Found a bug or have a feature idea? Please open an issue on GitHub Issues with a minimal reproducible description of the problem or feature. Please do not open pull requests — a clear issue description is more useful than a PR without prior discussion.

Project details


Download files

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

Source Distribution

aprisma-0.1.4.tar.gz (136.8 kB view details)

Uploaded Source

Built Distribution

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

aprisma-0.1.4-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file aprisma-0.1.4.tar.gz.

File metadata

  • Download URL: aprisma-0.1.4.tar.gz
  • Upload date:
  • Size: 136.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.2

File hashes

Hashes for aprisma-0.1.4.tar.gz
Algorithm Hash digest
SHA256 08e62e299164ebdac9b2ffa5b7fe6ab2348f2ff0b156bd7347d0e9f20b8b449c
MD5 53defcf1c1b9dad91560b105dc9488e1
BLAKE2b-256 2dacb5e01c3793482f85d189e0c633dd1b4b881d4b6b1c24c85f352128a31c62

See more details on using hashes here.

File details

Details for the file aprisma-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: aprisma-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.2

File hashes

Hashes for aprisma-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8f4996b0ccf4f306d7d7c9d07beff62cc2ab45269ddf399db69bf6839517b79b
MD5 02854e40df7020b72743bc0d8182abf9
BLAKE2b-256 c72a54bd8674618e3952de7099a9a86102f034fcdeda854a2f919561ed170139

See more details on using hashes here.

Supported by

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