GithubHelp home page GithubHelp logo

sample-python-api's Introduction

Python sample api

Sample python API to generate database query from known input format.
Currently, only SQL query is managed but we can image managing mongo queries later.
How we can warn the api which query type is requested ? I imagine to have a specific HTTP HEADER [ONGOING]

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

To run this sample, we are going to create an image with Docker. Make sure you have latest stable version of Docker installed. Please checkout the following official guide

Otherwise, we recommend using the latest version of Python in order to use Flask which supports Python 3.6 and newer.

Installing

A step by step series of examples that tell you how to get a development env running

Please install requirements:

pip3 install -r requirements.txt

Then you will be able to run it locally:

python3 -m flask run

Or

Use Docker to have all in container:

docker build -t MY_FAMOUS_NAME .

Then run it

docker run -d -p 5000:5000 --name MY_FAMOUS_CONTAINER MY_FAMOUS_NAME

You will be able to do a CURL request in order to test it:

curl -X POST 'http://127.0.0.1:5000/generate' -H 'Content-Type: application/json' -d '{"fields": ["name"],"filters":{"field":"name","value":1,"predicate":"contains"}}'

You should receive:

SELECT name FROM tows WHERE name LIKE "%1%"

Running the tests

python3 -m unittest test_app.py
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s
OK

Built With

  • Flask - Flask is a micro web framework written in Python
  • Cerberus - powerful, simple and lightweight data validation

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

sample-python-api's People

Contributors

royalsspirit avatar

Watchers

 avatar

sample-python-api's Issues

Validation schema

Improve the input validation by a custom func and a dict which contains a key:value of fields and its type

Define CI/CD

Create a lint job
Create a test job
Create a deployment job in order to deploy on heroku

README

Update the see last tag in versionning section to redirect to current project

HTTP code

Manage http code regarding the case (error request, success request)

Currently, we use only http code 200

Split behaviors

For better consistency, create a file for each functionality

Ex: move the sql management to its own file, in order to prepare futur database management

Error format

Create an common error format

Currently, we return the validation error as a raw data

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.