Prisma Client Python

0.15.0 · abandoned · verified Sun Apr 12

Prisma Client Python is an auto-generated and fully type-safe database client, offering a modern ORM experience built on top of the Rust-based Prisma Query Engine. It is known for strong type safety and excellent autocompletion features. The library is currently at version 0.15.0. **Important Note:** As of April 15, 2025, active development on Prisma Client Python has officially ceased due to the maintainer's lack of time and significant architectural changes in Prisma's core (rewriting from Rust to TypeScript). The repository was archived on April 15, 2025, and is now read-only, effectively abandoning the project.

Warnings

Install

Imports

Quickstart

To use Prisma Client Python, you must first define your database schema in a `schema.prisma` file and then run `prisma db push` (or `prisma generate`) from your terminal. This command generates the Python client code based on your schema. Afterwards, you can import and use the `Prisma` client to interact with your database. The example demonstrates an asynchronous client, connecting, creating a user, and finding a user.

import asyncio
import os
from prisma import Prisma

# --- First, define your schema in a file named `schema.prisma` ---
# datasource db {
#   provider = "sqlite"
#   url      = "file:./dev.db"
# }
#
# generator client {
#   provider = "prisma-client-py"
#   interface = "asyncio" # or "sync"
# }
#
# model User {
#   id    Int     @id @default(autoincrement())
#   email String  @unique
#   name  String?
# }
# ------------------------------------------------------------------

# --- Second, run `prisma db push` in your terminal to generate the client and apply schema ---
# You might need to set DATABASE_URL environment variable if using a remote DB
# os.environ['DATABASE_URL'] = os.environ.get('DATABASE_URL', 'sqlite:///dev.db')
# Run: `prisma db push`

# --- Third, use the generated client in your Python code ---
async def main():
    db = Prisma()
    await db.connect()

    # Create a user
    user = await db.user.create(
        data={
            'email': 'test@example.com',
            'name': 'Test User'
        }
    )
    print(f"Created user: {user.email}")

    # Find the user
    found_user = await db.user.find_unique(
        where={'email': 'test@example.com'}
    )
    if found_user:
        print(f"Found user: {found_user.name}")
    else:
        print("User not found.")

    await db.disconnect()

if __name__ == '__main__':
    # Example of setting DATABASE_URL if you're not using file:./dev.db in schema
    # os.environ['DATABASE_URL'] = os.environ.get('DATABASE_URL', 'sqlite:///dev.db')
    asyncio.run(main())

view raw JSON →