Giter Club home page Giter Club logo

redbull's Introduction

RedBull

Quickly develop JSON apis using Python type hints. Do not use in production

Minimal Example

from redbull import Manager

mg = Manager()

@mg.api()
def say_Hello(name: str='World'):
    "Says hello if you provide a name"
    return f'Hello {name}.'

mg.run()
  • APIs are live auto-documented at /<version>/docs
  • You can still code the way your framework of choice expects you to (Bottle, Flask, Django, Aiohttp ...)
  • Use python type hints to define json input keys.

The live page is minimal and looks like:

docs screenshot

A bigger example

from aiohttp import web
from redbull import Manager

mg = Manager(web.Application())  # You can use another framework if you want

# The function name say_hi becomes the api say/hi
# the args are treated as JSON keys. All args must by type annotated
# optional args are supported
# Simply return dict/string. Redbull wraps it for you in the appropriate object
@mg.api(pass_args=True)
async def say_hi(name: str,
                 please: bool,
                 lastname: str='Snow',  # A default is provided
                 __args__,  #     The original args passed to the function by Aiohttp
                 __kwargs__):  #  are added if pass_args is True in the decorator.
    "Says hi if you say please"
    if please:
        return 'hi ' + name
    return 'um hmm'

# ADD a generous CORS for all defined routes using the OPTIONS method
# The OPTIONS of the page also provides a documentation of the API
# Add a `/<version>/docs` GET Page
mg.run()

Notes

  • See if this is still possible with Flask / Django
  • DO NOT USE IN Production This is just a neat way of making life easier for the person who works on the UI and yourself. Security and other implications are not studies in any significant way.

redbull's People

Contributors

thesage21 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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