A micro web-framework using asyncio coroutines and chained middleware.

Related tags

Web FrameworksGrowler
Overview

Growler

master
Testing Report (Master Branch) Coverage Report (Master Branch) ' Latest PyPI version
dev
Testing Report (Development Branch) Coverage Report (Development Branch)

Growler is a web framework built atop asyncio, the asynchronous library described in PEP 3156 and added to the standard library in python 3.4. It takes a cue from the Connect & Express frameworks in the nodejs ecosystem, using a single application object and series of middleware to process HTTP requests. The custom chain of middleware provides an easy way to implement complex applications.

Installation

Growler is installable via pip:

$ pip install growler

The source can be downloaded/cloned from github at http://github.com/pyGrowler/Growler.

Extras

The pip utility allows packages to provide optional requirements, so features may be installed only upon request. This meshes well with the minimal nature of the Growler project: don't install anything the user doesn't need. That being said, there are (will be) community packages that are blessed by the growler developers (after ensuring they work as expected and are well tested with each version of growler) that will be available as extras directly from the growler package.

For example, if you want to use the popular mako html template engine, you can add support easily by adding it to the list of optionals:

$ pip install growler[mako]

This will automatically install the mako-growler packge, or growler-mako, or whatever it is named - you don't care, it's right there, and it works! Very easy!

The goal here is to provide a super simple method for adding middleware packages that the user can be sure works with that version of growler (i.e. has been tested), and has the blessing of the growler developer(s).

The coolest thing would be to describe your web stack via this command, so if you want mako, coffeescript, and some postgres ORM, your install command would look like growler[mako,coffee,pgorm]; anybody could look at that string and get the birds-eye view of your project.

When multiple extras are available, they will be listed here.

Usage

The core of the framework is the growler.App class, which links the asyncio server to your project's middleware. Middeware can be any callable or coroutine. The App object creates a request and a response object when a client connects and passes the pair to this middleware chain. Note: The middleware are processed in the same order they are specified - this could cause unexpected behavior (errors) if a developer is not careful, so be careful! The middleware can manipulate the request and response, adding features or checking state. If any respond to the client, the middleware chain is finished. This stream/filter model makes it very easy to modularize and extend web applications with many features, backed by the power of python.

Example Usage

import asyncio

from growler import App
from growler.middleware import (Logger, Static, StringRenderer)

loop = asyncio.get_event_loop()

# Construct our application with name GrowlerServer
app = App('GrowlerServer', loop=loop)

# Add some growler middleware to the application
app.use(Logger())
app.use(Static(path='public'))
app.use(StringRenderer("views/"))

# Add some routes to the application
@app.get('/')
def index(req, res):
    res.render("home")

@app.get('/hello')
def hello_world(req, res):
    res.send_text("Hello World!!")

# Create the server - this automatically adds it to the asyncio event loop
Server = app.create_server(host='127.0.0.1', port=8000)

# Tell the event loop to run forever - this will listen to the server's
# socket and wake up the growler application upon each connection
loop.run_forever()

This code creates an application which is identified by 'GrowlerServer' (this name does nothing at this point), and a reference to the event loop. Requests are passed to some middleware provided by the Grower package: Logger, Static, and StringRenderer. Logger simply prints the ip address of the connecting client to stdout. Static will check a request url path against files in views/, if one of the files match, the file type is determined, proper content-type header is set, and the file content is sent. Renderer adds the 'render' method to the response object, allowing any following function to call res.render('/filename'), where filename exists in the "views" directory.

Decorators are used to add endpoints to the application, so requests with path matching '/' will call index(req, res) and requests matching '/hello' will call hello_world(req, res). Because 'app.get' is used, only HTTP GET requests will match these endpoints. Other HTTP 'verbs' (post, put, delete, etc) are available as well as 'all', which matches any method. Verb methods must match a path in full.

The 'use' method takes an optional path parameter (e.g. app.use(Static("public"), '/static')), which calls the middleware anytime the request path begins with the parameter.

The asyncio package provides a Server class which does the low-level socket handling for the developer, this is how your application should be hosted. Calling app.create_server(...) creates an asyncio Server object with the event loop given in app's constructor, and the app as the target for incomming connections; this is the recommended way to setup a server. You can't do much with the server directly, so after creation the event loop must be given control of the thread The easiest way to do this is to use loop.run_forever() after app.create_server(...). Or do it in one line with app.create_server_and_run_forever(...).

Extensions

Growler introduces the virtual namespace growler_ext to which other projects may add their own growler-specific code. Of course, these packages may be imported in the standard way, but Growler provides an autoloading feature via the growler.ext module (note the '.' in place of '_') which will automatically import any packages found in the growler_ext namespace. This not only provides a standard interface for extensions, but allows for different implementations of an interface to be chosen by the environment, rather than hard-coded in. It also can reduce the number of import statements at the beginning of the file. This specialized importer may be imported as a standalone module:

from growler import App, ext

app = App()
app.use(ext.MyGrowlerExtension())
...

or a module to import 'from':

from growler import App
from growler.ext import MyGrowlerExtension

app = App()
app.use(MyGrowlerExtension())
...

This works by replacing the 'real' ext module with an object that will import submodules in the growler_ext namespace automatically. Perhaps unfortunately, because of this there is no way I know of to allow the import growler.ext.my_extension syntax, as this skips the importer object and raises an import error. Users must use the from growler.ext import ... syntax instead.

The best practice for developers to add their middleware to growler is now to put their code in the python module growler_ext/my_extension. This will allow your code to be imported by others via from growler.ext import my_extension or the combination of from growler import ext and ext.my_extension.

An example of an extension is the indexer packge, which hosts an automatically generated index of a filesystem directory. It should implement the best practices of how to write extensions.

More

As it stands, Growler is single threaded, partially implemented, and not fully tested. Any submissions, comments, and issues are greatly appreciated, but I request that you please follow the Growler contributing guide.

The name Growler comes from the beer bottle keeping in line with the theme of giving python micro-web-frameworks fluid container names.

License

Growler is licensed under Apache 2.0.

Swagger/OpenAPI First framework for Python on top of Flask with automatic endpoint validation & OAuth2 support

Connexion Connexion is a framework that automagically handles HTTP requests based on OpenAPI Specification (formerly known as Swagger Spec) of your AP

Zalando SE 4.2k Jan 07, 2023
REST API framework designed for human beings

Eve Eve is an open source Python REST API framework designed for human beings. It allows to effortlessly build and deploy highly customizable, fully f

eve 6.6k Jan 07, 2023
Klein - A micro-framework for developing production-ready web services with Python

Klein, a Web Micro-Framework Klein is a micro-framework for developing production-ready web services with Python. It is 'micro' in that it has an incr

Twisted Matrix Labs 814 Jan 08, 2023
Python Wrapper for interacting with the Flutterwave API

Python Flutterwave Description Python Wrapper for interacting with the Flutterwa

William Otieno 32 Dec 14, 2022
A high-level framework for building GitHub applications in Python.

A high-level framework for building GitHub applications in Python. Core Features Async Proper ratelimit handling Handles interactions for you (

Vish M 3 Apr 12, 2022
A Flask API REST to access words' definition

A Flask API to access words' definitions

Pablo Emídio S.S 9 Jul 22, 2022
Bionic is Python Framework for crafting beautiful, fast user experiences for web and is free and open source

Bionic is fast. It's powered core python without any extra dependencies. Bionic offers stateful hot reload, allowing you to make changes to your code and see the results instantly without restarting

⚓ 0 Mar 05, 2022
Free & open source Rest API for YTDislike

RestAPI Free & open source Rest API for YTDislike, read docs.ytdislike.com for implementing. Todo Add websockets Installation Git clone git clone http

1 Nov 25, 2021
Restful API framework wrapped around MongoEngine

Flask-MongoRest A Restful API framework wrapped around MongoEngine. Setup from flask import Flask from flask_mongoengine import MongoEngine from flask

Close 525 Jan 01, 2023
Pyrin is an application framework built on top of Flask micro-framework to make life easier for developers who want to develop an enterprise application using Flask

Pyrin A rich, fast, performant and easy to use application framework to build apps using Flask on top of it. Pyrin is an application framework built o

Mohamad Nobakht 10 Jan 25, 2022
Otter is framework for creating microservices in Flask like fassion using RPC communication via message queue.

Otter Framework for microservices. Overview Otter is framework for creating microservices in Flask like fassion using RPC communication via message qu

Volodymyr Biloshytskyi 4 Mar 23, 2022
Python implementation of the Javascript Object Signing and Encryption (JOSE) framework

Python implementation of the Javascript Object Signing and Encryption (JOSE) framework

Demonware 94 Nov 20, 2022
A boilerplate Flask API for a Fullstack Project with some additional packages and configuration prebuilt. ⚙

Flask Boilerplate to quickly get started with production grade flask application with some additional packages and configuration prebuilt.

Yasser Tahiri 32 Dec 24, 2022
An alternative serializer implementation for REST framework written in cython built for speed.

drf-turbo An alternative serializer implementation for REST framework written in cython built for speed. Free software: MIT license Documentation: htt

Mng 74 Dec 30, 2022
Online Boutique is a cloud-native microservices demo application

Online Boutique is a cloud-native microservices demo application. Online Boutique consists of a 10-tier microservices application. The application is

Matt Reider 1 Oct 22, 2021
Flask-Potion is a RESTful API framework for Flask and SQLAlchemy, Peewee or MongoEngine

Flask-Potion Description Flask-Potion is a powerful Flask extension for building RESTful JSON APIs. Potion features include validation, model resource

DTU Biosustain 491 Dec 08, 2022
A python application to log QSOs directly to QRZ.com from the command line

qrzlogger This script is a QRZ.com command line QSO logger. It does the following: asks the user for a call sign displays available call sign info pul

Michael Clemens 15 Jul 16, 2021
A micro web-framework using asyncio coroutines and chained middleware.

Growler master ' dev Growler is a web framework built atop asyncio, the asynchronous library described in PEP 3156 and added to the standard library i

687 Nov 27, 2022
A simple todo app using flask and sqlachemy

TODO app This is a simple TODO app made using Flask. Packages used: DoodleCSS Special thanks to Chris McCormick (@mccrmx) :) Flask Flask-SQLAlchemy Fl

Lenin 1 Dec 26, 2021
A framework that let's you compose websites in Python with ease!

Perry Perry = A framework that let's you compose websites in Python with ease! Perry works similar to Qt and Flutter, allowing you to create componen

Linkus 13 Oct 09, 2022