prisma-to-python
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

Prisma to Python

npm version

Parse prisma.schema files and output enums, types and models as Python classes.

⚠️ prisma-to-python only supports a subset of the prisma schema syntax - feel free to contribute any other features you need!

This was built to set up models for use with pymongo, but could be applicable to other use cases.

prisma-to-python works by using the getDMMF function of @prisma/internals, which effectively parses the schema to an AST in JSON. This AST is then used to write Python code for the defined enums, types and models.

Usage

npx prisma-to-python --input ./example/schema.prisma --output ./example/models.py

Example

Input

// https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

enum FruitName {
  apple
  banana
  orange
}

type Fruit {
  fruit       FruitName
  price       Int
  description String?
  dateSold    DateTime
  received    Boolean
}

model FruitOrders {
  id    String  @id @default(auto()) @map("_id") @db.ObjectId
  fruit Fruit[]
}

Output

# Generated by prisma-to-python - https://github.com/jmsv/prisma-to-python#readme
# Do not edit this file directly!

from enum import Enum
from typing import TypedDict, Optional
from datetime import datetime

# Enums

class FruitName(str, Enum):
    APPLE = "apple"
    BANANA = "banana"
    ORANGE = "orange"

# Types

class Fruit(TypedDict):
    fruit: FruitName
    price: int
    description: Optional[str]
    dateSold: datetime
    received: bool

# Models

class FruitOrders(TypedDict):
    _id: str
    fruit: list[Fruit]

Readme

Keywords

Package Sidebar

Install

npm i prisma-to-python

Weekly Downloads

0

Version

0.1.4

License

MIT

Unpacked Size

17.7 kB

Total Files

11

Last publish

Collaborators

  • jmsv