Code Monkey home page Code Monkey logo

api_generator's Introduction

api generator

  • this tool automatically generates python code for a rest api and corresponding api doc using swagger ui, all you've to do is provide connection string to the database and verify configuration settings

  • it leverages fastapi, which uses and ASGI server uvicorn

  • currently only postgres is supported

setup

required : python3.6+, pip3

  • git clone https://github.com/nsingla/api_generator.git
  • cd api_generator
  • install pre-requisite for psycopg2 and requirements:
sudo apt-get install libpq-dev python3-dev
pip3 install -r requirements.txt
  • update connection string and schema for which api is to be generated in the settings.conf

  • generate configuration file for the api generator, the api and the model will be generated based on the settings in this conf file in next steps. this will create a file named api_gen.conf

python3 conf_generator.py
  • go through the settings in the api_gen.conf, top of the file contains the description of each setting

  • run script to generate api code and model inside the src folder

python3 api_generator.py
  • cd src (you can also move and rename the src to any location)

  • the src folder has all the api code, first install library requirements:

pip3 install -r requirements.txt
  • run the api app:
uvicorn app:app --reload

notes

  • support for tables with composite keys as primary key will be added soon

  • currently table names or column names with spaces in your db are not supported by this tool, it will potentially break the code

  • all fields are set to be required by default, you can modify the class files inside the model folder to set default value of fields to None, this will make those fields optional

  • http://127.0.0.1/ redirects to /docs by default, /docs are the swagger ui docs using which you can test all the api calls and /redoc is an alternate documentation

sample project

if you want to look at an already generated api project, a sample project is included,

follow the readme inside it if you want to try that to see how a generated api will look like

api_generator's People

Watchers

 avatar  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.