Package: reactant
Generate code formodels, views, and urlsbased on Python type annotations. Powered bypydantic. Influenced bySQLModel.reactantaims to give usable and sensible code defaults. It doesnot enforcea particular application structure. Instead, it follows the default/minimal/common structure of the supported frameworks, and the developer has the freedom of changing it (if necessary) to fit it to their application. Contributions are warmly welcomed if you believe a particular structure is widely used and can benefit from code generation.Supported Frameworksreactantcurrently generates code for the following:Django REST(Django 3+, DRF 3.12+)(in Django'sdefaultproject structure i.e. byapps)modelsviews (class-based API views, filename=views_class.py)views (function-based API views, filename=views_func.py)views (modelviewset, filename=views_modelviewset.py)serializersurls (using class-based API views, filename=urls_class.py)urls (using function-based API views, filename=urls_func.py)urls (using viewset, filename=urls_viewset.py)Flask(Flask 2+)(package structure, for building REST APIs)viewsSQLAlchemy(SQLAlchemy 1.4+)classes mapped by Declarative Mappingclasses mapped by Classical MappingPeewee(Peewee 3.14+)modelsInstallationpip install reactantNOTE:reactantisn't shipped with the supported frameworks. You MUST installdjango,sqlalchemy,peewee, orflaskseparately (be it in a virtual environment or globally).Get StartedCreatereactantmodels by inheriting fromReactantsubclasses:DjangoORM,SQLAlchemyORM,PeeweeORM. The example below usesDjangoORM. Your choice will determine what code and files will be generated.# generate.pyfromtypingimportOptionalfromreactantimportDjangoORM,Field,generatefromdatetimeimportdateclassRocketEngine(DjangoORM):name:str=Field(max_length=32,title="engine_name")# adding additional argumentsmanufacturer:Optional[str]power_cycle:Optional[str]="gas-generator"# setting a defaultthrust_weight_ratio:Optional[int]=NoneclassLaunchVehicle(DjangoORM):name:str=Field(max_length=32)country:str=Field("USA",max_length=32)# setting a default in the Field functionstatus:strtotal_launches:Optional[int]first_flight:Optional[date]engine:str=Field(foreign_key="RocketEngine")# specifying a relationship field# Don't forget this block.if__name__=="__main__":generate()You can give ORM-specific arguments to theFieldfunction. For more details, please read theThe Field functionsection.Don't forgetgenerate(). Run by specifying the file:reactant generate.pyTip: You can control what code and files will be generated by passing keyword arguments togenerate(). Read theThe generate functionsection for the details.$ reactant generate.py

Running generate.py
Found 2 Django reactants.
Django models.py finished rendering.
Django serializers.py finished rendering.
Django views_class.py finished rendering.
Django urls_class.py finished rendering.
Django views_func.py finished rendering.
Django urls_func.py finished rendering.
Success! Please check "reactant_products/django" directory.BOOM!With just the above code, the models, views, serializers, and urls (theproducts, for Django atleast) are generated. See images of the code below.Sample Code GeneratedDjango RESTThe Field functionThereactantFieldfunction comes from pydantic. It can be used to provide extra information about the field. Currently though,reactantFieldcan only support the following pydantic native arguments:default(the positional argument)max_lengthtitleOther than the listed native arguments,reactantFieldcan accept arguments that are specific to an ORM and filters out those that are not supported by the same ORM. For example if you are generating Django files, Django ORM model fields can accept anerror_messagesargument. You can give this argument to thereactantFieldand the generated Django models will include this argument. However, if you give made-up arguments or arguments that are only valid for other ORMs, the generated Django models will not include those.Specifying model relationshipsRelationship fields can be specified by giving thereactantFieldspecial arguments.foreign_key- identifies a foreign keymany_key- identifies a many-to-manyone_key- identifies a one-to-oneThese behave differently for each framework. TheGet Startedsection shows an example of specifying a relationship.Django REST: Models inheriting fromDjangoORMcan useforeign_key,many_key, andone_keyto establish relationships. TheGet Startedsection shows aDjangoORMexample.SQLAlchemy:reactantaims not to introduce anything new except having knowledge of type hints and pydantic. It was hard to capture and generate SQLAlchemy relationships without introducing newreactantconcepts due to SQLAlchemy's flexibility. Nevertheless, relationship code are still generated and you are given options as to what relationship you intend to build.Currently, only theforeign_keyparameter is available for establishing relationships. You may put theFieldfunction with this parameter to any of your classes since the generated code will provide options for your intended relationship: One-to-Many, Many-to-One, One-to-One. UsingSQLAlchemyORMfor the reactant models inGet Startedsection, the following code is generated:Peewee:reactantmodels withPeeweeORMcan useforeign_keyparameter.The generate functionThegeneratefunction can accept keyword arguments to control the behavior of generating code and files. Read below to learn what each supported framework accepts.Django RESTBy default, all of function-based, class-based, and viewset-based views are generated. To switch OFF any of them, passclass_based=Falseorfunction_based=Falseorviewset_based=FalseDevelopmentThe project uses Poetry to package and manage dependencies.(venv)$ poetry installRun tests.pytestDo linting.bash scripts/lint-check.shFix formatting.bash scripts/format.shLicenseMIT License. For more information and legal terms, see the LICENSE file.