Package: openalchemy
OpenAlchemyTranslates an OpenAPI schema to SQLAlchemy models.Supports OpenAPI 3.0 and 3.1.Get started with the online editor that will guide you through using your
existing OpenAPI specification to define your database schema and offers
installing your models usingpip:Online EditorInstallationpython-mpipinstallOpenAlchemy# To be able to load YAML filepython-mpipinstallOpenAlchemy[yaml]ExampleFor example, given the following OpenAPI specification:# ./examples/simple/example-spec.ymlopenapi:"3.0.0"info:title:Test Schemadescription:API to illustrate OpenAlchemy MVP.version:"0.1"paths:/employee:get:summary:Used to retrieve all employees.responses:200:description:Return all employees from the database.content:application/json:schema:type:arrayitems:"$ref":"#/components/schemas/Employee"components:schemas:Employee:description:Person that works for a company.type:objectx-tablename:employeeproperties:id:type:integerdescription:Unique identifier for the employee.example:0x-primary-key:truex-autoincrement:truename:type:stringdescription:The name of the employee.example:David Anderssonx-index:truedivision:type:stringdescription:The part of the company the employee works in.example:Engineeringx-index:truesalary:type:numberdescription:The amount of money the employee is paid.example:1000000.00required:-id-name-divisionThe SQLALchemy models file then becomes:# models.pyfromopen_alchemyimportinit_yamlinit_yaml("./examples/simple/example-spec.yml")TheBaseandEmployeeobjects can be accessed:fromopen_alchemy.modelsimportBasefromopen_alchemy.modelsimportEmployeeWith themodels_filenameparameter a file is auto generated with type hints
for the SQLAlchemy models at the specified location, for example:type hinted models example. This adds support
for IDE auto complete, for example for the model initialization:and for properties and methods available on an instance:An extensive set of examples with a range of features is here:examples for main featuresAn example API has been defined using connexion and Flask here:example connexion appDocumentationRead the DocsBuy me a coffeeFeaturesinitializing from JSON,initializing from YAML,build a package with the models for distribution, packaged as sdist or wheel,automatically generate a models file,integer(32 and 64 bit),number(float only),boolean,string,password,byte,binary,date,date-time,generic JSON data,$refreferences for columns and models,remote$refto other files on the same file system
(not supported on Windows),remote$refto other files at a URL,primary keys,auto incrementing,indexes,composite indexes,unique constraints,composite unique constraints,column nullability,foreign keys,default values for columns (both application and database side),many to one relationships,one to one relationships,one to many relationships,many to many relationships,many to many relationships with custom association tables,custom foreign keys for relationships,back references for relationships,allOfinheritance for columns and models,joined and single table inheritance,from_strmodel methods to construct from JSON string,from_dictmodel methods to construct from dictionaries,to_strmodel methods to convert instances to JSON string,__str__model methods to support the pythonstrfunction,__repr__model methods to support the pythonreprfunction,to_dictmodel methods to convert instances to dictionaries,readOnlyandwriteOnlyfor influence the conversion to and from
dictionaries,exposing created models underopen_alchemy.modelsremoving the need formodels.pyfiles,ability to mix in arbitrary classes into a model,can use the shortx-prefix or a namespacedx-open-alchemy-prefix for
extension properties andgrouping models into schemas.ContributingFork and checkout the repository. To install:poetryinstallTo run tests:poetryrunpytestMake your changes and raise a pull request.Compiling Docspoetryshellcddocs
makehtmlThis creates theindex.htmlfile indocs/build/html/index.html.Release Commandsrm-rdist/*
poetrybuild
poetrypublish