CrudGen is a CLI tool that allows you to generate & run a CRUD for FastApi framework. CrudGen goal is to make simple and fast the process of building SQL Tables and the associated crud, with only providing a json file describing SQL table attributes as input.
- SqlAlchemy model generation
- Pydantic schema generation
- Controller generation
- Router generation
- Swagger documentation
- Api automatic start
Developed under Python 3.8.2
Operating System | State |
---|---|
Mac OS | Tested |
Linux | Tested |
Windows | Not tested |
python -m crudgen.app \
--file example/example.json \
--output /Users/fsz/Development/ \
--start True
- --file: path of the json file describing the tables
- --output: absolute path of the generated api output directory
- --start: boolean, if set to true, the api will start after generation
- --name: name of the generated api
Input file content : example.json
{
"user":{
"key_identifier":{
"name":"username",
"type":"string"
},
"fields":[
{
"field_name":"id",
"field_type":"integer",
"unique":true,
"primary_key":true
},
{
"field_name":"username",
"field_type":"string",
"unique":true,
"primary_key":false
},
{
"field_name":"registration_date",
"field_type":"datetime",
"unique":false,
"primary_key":false
},
{
"field_name":"city",
"field_type":"string",
"unique":false,
"primary_key":false
}
]
},
"city":{
"key_identifier":{
"name":"zip",
"type":"integer"
},
"fields":[
{
"field_name":"id",
"field_type":"integer",
"unique":true,
"primary_key":true
},
{
"field_name":"zip",
"field_type":"integer",
"unique":true,
"primary_key":false
},
{
"field_name":"country",
"field_type":"string",
"unique":false,
"primary_key":false
}
]
}
}
According to example.json, a crud for two tables will be generated : user and city. With the previous command, the api will start automatically, swagger docs will be accessible at http://0.0.0.0:8080/docs You will find the following page which allows you to try out every endpoints:
- First field: table name (user & city in example.json)
- key_identifier: name of the sql attributes used to identify the sample and request database
- fields: list of the fields discribing sql table attributes
In v0.1-alpha, following types options are supported:
- integer
- string
- boolean
- float
- datetime
An attribute can be use as primary key and / or set as unique
- Relation between table fields
- CORS support
- Add more supported types
- Ability to generate routes for file uploads
- Fix update endpoint bug