Coder Social home page Coder Social logo

sqlapydantic's Introduction

sqlapydantic

Generate Pydantic Model from SQLAlchemy Model

This package is helpful while building web apps with FastAPI and SQLAlchemy. It generates Pydantic Model from SQLAlchemy Model.

Installation

To install,

pip install sqlapydantic

Quickstart

You may use generate_models function directly to generate Pydantic Model from SQLAlchemy Model. It takes Generator's init arguments and init a Generator class.

Examples:

    from sqlapydantic import generate_model
    
    generate_model(models=[MyModel], base_model=CustomBaseModel)
from  sqlapydantic import Generator

generator = Generator(base_model=CustomBaseModel)
generator.generate_from_module(models=my_models_module, output_path="schemas.py")

Generator Class takes following init arguments

  • split_models: Whether to split models into Base, Create, Update and Read models. Default is Fakse.
  • base_model: Base model to inherit from. Default is BaseModel from pydantic.
  • restrict_fields: Which takes a set of fields to restrict. Default is None. This is useful when you want to restrict some fields to be readonly such as id, created_at, updated_at.
  • indentation: Indentation to use in generated code.

RoadMap

  • Strict typing, such as using conint for limiting Integer size and constr for String length.
  • Probably, generate relationships as well.

sqlapydantic's People

Contributors

maacck avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.