npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lexmata/prisma-python-generator

v0.1.2

Published

Prisma generator that produces Python Pydantic model classes from your Prisma schema

Readme

@lexmata/prisma-python-generator

A Prisma generator plugin that produces Python Pydantic v2 model classes from your Prisma schema.

Installation

npm install -D @lexmata/prisma-python-generator
# or
pnpm add -D @lexmata/prisma-python-generator

Setup

Add the generator to your schema.prisma:

generator python {
  provider = "prisma-python-generator"
  output   = "./generated/prisma_models"
}

Run the generator with the GENERATE_PYTHON environment variable enabled:

GENERATE_PYTHON=true npx prisma generate

The generator is disabled by default. If GENERATE_PYTHON is not set or is not "true", the generator will skip and print a message.

Output

Given a Prisma schema like this:

enum Role {
  USER
  ADMIN
}

model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String?
  role      Role     @default(USER)
  posts     Post[]
  createdAt DateTime @default(now())
}

The generator produces a Python package at the configured output path:

generated/prisma_models/
├── __init__.py
├── enums.py
├── user.py
├── post.py
└── py.typed

Enums

Prisma enums become Python str enums:

from enum import Enum

class Role(str, Enum):
    USER = "USER"
    ADMIN = "ADMIN"

Models

Prisma models become Pydantic BaseModel classes:

from __future__ import annotations

from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field
from .enums import Role

class User(BaseModel):
    """A user in the system"""

    id: int
    email: str
    name: str | None = Field(default=None)
    role: Role = Field(default="USER")
    posts: list["Post"] = Field(default_factory=list)
    created_at: datetime = Field(alias="createdAt")

    model_config = ConfigDict(
        from_attributes=True,
        populate_by_name=True,
    )

Imports

All models and enums are re-exported from __init__.py:

from generated.prisma_models import User, Post, Role

Features

| Feature | Detail | |---|---| | Type mapping | Stringstr, Intint, Floatfloat, Booleanbool, DateTimedatetime, DecimalDecimal, JsonAny, Bytesbytes, BigIntint | | Enums | Generated as class Name(str, Enum) with string values | | Relations | Forward-referenced as "ModelName" strings | | List fields | list[T] with default_factory=list | | Optional fields | T \| None with default=None | | Snake case | camelCase fields get alias="originalName" with populate_by_name=True | | Defaults | Static defaults (strings, numbers, booleans) carried over; auto-generated defaults (autoincrement, now, uuid) omitted | | Docstrings | Prisma /// comments become Python docstrings | | PEP 561 | py.typed marker included for type-checker support |

Environment Variable

| Variable | Values | Default | |---|---|---| | GENERATE_PYTHON | "true" to enable | Disabled (skips generation) |

This makes it safe to include the generator in a shared schema.prisma without it running on every prisma generate invocation. Only environments that explicitly opt in will produce output.

Development

# Install dependencies
pnpm install

# Build
pnpm build

# Run tests
pnpm test

# Generate from the example schema
GENERATE_PYTHON=true pnpm generate

License

MIT © Lexmata LLC