Prisma Client Python
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
- breaking The Prisma Client Python project has been officially abandoned by its maintainer as of April 15, 2025, and its GitHub repository is now read-only. No further development, bug fixes, or new features will be added. Users should consider alternative ORMs or be prepared to maintain a fork.
- breaking Support for Python 3.7 was dropped in version 0.14.0, as Python 3.7 reached its End-of-Life.
- gotcha The Prisma Client Python is auto-generated based on your `schema.prisma` file. You must run `prisma generate` or `prisma db push` (which also generates the client) every time you modify your `schema.prisma` file for changes to be reflected in your Python code. Ensure your `generator client` block in `schema.prisma` specifies `provider = "prisma-client-py"`.
- gotcha When upgrading to Pydantic v2 (or using it alongside v1), there might be compatibility issues with `prisma.validate`. Specifically, errors raised by `prisma.validate` might need to be caught using `pydantic.v1.ValidationError` due to internal implementation details in v0.10.0.
- gotcha Prisma Client Python's static type checking has limitations, especially when using `mypy`. It is highly recommended to use `pyright` as your type checker for Prisma Client Python applications to achieve the most accurate and comprehensive type safety.
Install
-
pip install prisma
Imports
- Prisma
from prisma import Prisma
Quickstart
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())