Skip to content



Adapted from the Prisma Client Go documentation

In this page, you will learn how to send queries to an SQLite database using Prisma Client Python and run static type checks.


1) Set up a Python project with a virtual environment

mkdir demo && cd demo
python3 -m venv .venv

2) Activate the virtual environment

Note that you will have to run the activation command on every new shell instance.

Platform Shell Activation Command
POSIX bash/zsh $ source .venv/bin/activate
fish $ source .venv/bin/
csh/tcsh $ source .venv/bin/activate.csh
PowerShell Core $ .venv/bin/Activate.ps1
Windows cmd.exe C:\> .venv\Scripts\activate.bat
PowerShell PS C:\> .venv\Scripts\Activate.ps1

3) Install Prisma Client Python

pip install prisma

4) Prepare your database schema in a schema.prisma file.

For example, a simple schema with an sqlite database and one model would look like this:

datasource db {
  // could be postgresql or mysql
  provider = "sqlite"
  url      = "file:dev.db"

generator db {
  provider             = "prisma-client-py"
  interface            = "asyncio"
  recursive_type_depth = 5

model Post {
  id         String   @id @default(cuid())
  created_at DateTime @default(now())
  updated_at DateTime @updatedAt
  title      String
  published  Boolean
  desc       String?

To get this up and running in your database, we use the Prisma migration tool db push to create and migrate our database:

prisma db push

If you make changes to your prisma schema, you need to run this command again.


The db push command also generates the client for you. If you want to generate the client without modifying your database, use the following command:

prisma generate


You can add the --watch flag to re-generate the client whenever you modify the schema.prisma file:

prisma generate --watch


Create a file

import asyncio

from prisma import Prisma

async def main() -> None:
    db = Prisma()
    await db.connect()

    post = await
            'title': 'Hello from prisma!',
            'desc': 'Prisma is a database toolkit and makes databases easy.',
            'published': True,
    print(f'created post: {post.json(indent=2, sort_keys=True)}')

    found = await{'id':})
    assert found is not None
    print(f'found post: {found.json(indent=2, sort_keys=True)}')

    await db.disconnect()

if __name__ == '__main__':

and run it:

created post: {
  "created_at": "2021-01-04T00:30:35.921000+00:00",
  "desc": "Prisma is a database toolkit and makes databases easy.",
  "id": "ckjhtv79t0000y1uicwrgt605",
  "published": true,
  "title": "Hello from prisma!",
  "updated_at": "2021-01-04T00:30:35.921000+00:00"
found post: {
  "created_at": "2021-01-04T00:30:35.921000+00:00",
  "desc": "Prisma is a database toolkit and makes databases easy.",
  "id": "ckjhtv79t0000y1uicwrgt605",
  "published": true,
  "title": "Hello from prisma!",
  "updated_at": "2021-01-04T00:30:35.921000+00:00"

Static type checking



I am the maintainer of the pyright PyPI package which is a wrapper over the official version which is maintained by Microsoft.

1) Install pyright

pip install pyright

2) Create a pyproject.toml file

include = [

typeCheckingMode = "strict"


Found 1 source file
0 errors, 0 warnings, 0 infos
Completed in 1.322sec

Error reporting

For example, add the following line to the end of the main() function

async def main() -> None:
    print(f'Invalid field: {post.invalid_field}')

Running pyright will now output errors

Found 1 source file
  /prisma-py-quickstart/ - error: Cannot access member "invalid_field" for type "Post"
    Member "invalid_field" is unknown (reportGeneralTypeIssues)
  /prisma-py-quickstart/ - error: Type of "invalid_field" is unknown (reportUnknownMemberType)
2 errors, 0 warnings, 0 infos
Completed in 1.947sec

Pyright will also error whenever you try to query by a non-existent field, for example

async def main() -> None:
    found = await{'unknown_field':})

Found 1 source file
  /programming/prisma-py-quickstart/ - error: Argument of type "dict[str, str]" cannot be assigned to parameter "where" of type "PostWhereUniqueInput" in function "find_unique"
    "unknown_field" is an undefined field in type "PostWhereUniqueInput" (reportGeneralTypeIssues)
1 error, 0 warnings, 0 infos
Completed in 1.884sec

Next steps

We just scratched the surface of what you can do. Read our advanced tutorial to learn about more complex queries and how you can query for relations.