Prisma to SQLModel
A tool to convert Prisma schema files to SQLModel models. This tool helps you migrate from Prisma to SQLModel while preserving your data model structure, relationships, and indexes.
Features
- Converts Prisma models to SQLModel classes
- Preserves relationships (one-to-one, one-to-many, many-to-many)
- Handles indexes and primary keys
- Supports vector fields with pgvector
- Maintains field types and constraints
- Generates proper SQLModel relationships with back_populates
Installation
pip install prisma-to-sqlmodel
Usage
Command Line Interface
prisma-to-sqlmodel schema.prisma output.py
Python API
from prisma_to_sqlmodel import PrismaConverter
converter = PrismaConverter("schema.prisma")
python_code = converter.convert()
# Write to file
with open("output.py", "w") as f:
f.write(python_code)
Example
Input (schema.prisma)
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Post {
id Int @id @default(autoincrement())
title String
content String @db.Text
author User @relation(fields: [authorId], references: [id])
authorId Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Output (output.py)
from datetime import datetime
from typing import Optional, List
from sqlmodel import Field, SQLModel, Relationship
class User(SQLModel, table=True):
__tablename__ = "User"
id: int = Field(primary_key=True)
email: str = Field(unique=True)
name: Optional[str] = None
posts: List["Post"] = Relationship(back_populates="author")
created_at: datetime = Field(default_factory=datetime.utcnow)
updated_at: datetime = Field(sa_column=Column(sql.func.now(), onupdate=sql.func.now()))
class Post(SQLModel, table=True):
__tablename__ = "Post"
id: int = Field(primary_key=True)
title: str
content: str = Field(sa_column=Column(Text))
author: User = Relationship(back_populates="posts")
author_id: int = Field(foreign_key="User.id")
created_at: datetime = Field(default_factory=datetime.utcnow)
updated_at: datetime = Field(sa_column=Column(sql.func.now(), onupdate=sql.func.now()))
Development
- Clone the repository
- Create a virtual environment:
python -m venv .venv - Activate the virtual environment:
- Windows:
.venv\Scripts\activate - Unix/MacOS:
source .venv/bin/activate
- Windows:
- Install dependencies:
pip install -e ".[dev]" - Run tests:
pytest
License
MIT License
Metadata
Release files for prisma-to-sqlmodel 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| prisma_to_sqlmodel-0.1.0.tar.gz | 9.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| prisma_to_sqlmodel-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.6 kB
Release files / prisma_to_sqlmodel-0.1.0.tar.gz
| Download URL | prisma_to_sqlmodel-0.1.0.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a268a8f7e76b94537d2d89fd98f90fb8f30f356b33c96ada948fb1d887c5d63
|
|
BLAKE2b-256 checksum How to use checksums |
0f8af27e70b4e3071ac46d4826bd8dac1ef97ad74c73545a34450999808a4721
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / prisma_to_sqlmodel-0.1.0-py3-none-any.whl
| Download URL | prisma_to_sqlmodel-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
de2142215dba234bd7877b2d3bcf84671ae95f41bd1a300c494f7684edb82b17
|
|
BLAKE2b-256 checksum How to use checksums |
b551327bb61681d5d3a1d89e4e44a67a77102a585f3342f36c22e864d394dfa7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for prisma-to-sqlmodel 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.