Skip to main content

Aeros web server, based on Quart/Flask

Project description

Aeros Documentation

Aeros is a production-grade ASGI (Asynchronous Server Gateway Interface) package containing wrappers for widely used Web and API functions.

Features

  • High-performance web server
    • Async request handling
    • Supports multi-threading
  • Production-grade ASGI (async WSGI)
  • In-Python code API
  • Can be run in a separate thread
  • Easy Framework based on Flask/Quart

Why use Aeros over Flask and Quart?

While Flask is one of the most popular and frequently used frameworks, it doesn't come with a full WSGI server. Therefore, you will need an additional module like Waitress or Gunicorn. Quart shares the same features as Flask, but you can get more performance out of it, since it supports asynchronous request handling. But as for Flask, you will need a WSGI (an ASGI in this case) to deploy your Quart app into production. The most popular ASGI at the moment is called Hypercorn and is installed together with Quart.

But Hypercorn does only support deployment from console. Meaning, you will have to invoke a start command like: hypercorn <file>:<app_variable_name> to start your server. This makes it hard to deploy a multi-thread web server.

Aeros combines all the benefits from Quart and Hypercorn, while maintaining the in-Python API, making it easy to create an application that can be run from custom code, not by shell.

A more detailed overview of pros and cons can be found here:

Framework Async Production-grade Easy to use In-Python API Callable from thread
Flask No No Yes Yes ?
Flask + Waitress No Yes Yes Yes ?
Flask + Gunicorn Yes Yes No Yes ?
Quart Yes No Yes Yes ?
Quart + Hypercorn Yes Yes Yes No No
Aeros Yes Yes Yes Yes Yes

Getting started

This basic code snippet should get you ready for more. Remember that routed methods (the ones that are called on an HTTP endpoint) must be defined with async def, not def!

from Aeros import WebServer
from Aeros.misc import jsonify

app = WebServer(__name__, host="0.0.0.0", port=80)


@app.route("/")
async def home():
    return jsonify({"response": "ok"})


if __name__ == '__main__':
    app.start("-w 2")  # worker threads (for more arguments see hypercorn documentation)

Full Documentation

Using sync methods in async methods

If you need to execute a synchronous method in an HTTP request handler and need to wait for its response, you should use sync_to_async from asgiref.sync. This method can also be imported from Aeros.misc:

from Aeros.misc import sync_to_async
import time

@sync_to_async
def sync_method():
    time.sleep(2)
    return "ok"

@app.route("/")
async def home():
    status = sync_method()
    return jsonify({"response": status})

Starting a server in a separate thread

Quart and Hypercorn don't allow server instances to be started from a non __main__ thread. Aeros however does. This code shows how:

from Aeros import WebServer
from Aeros.threading import AdvancedThread
from threading import Thread
import time

app = WebServer(__name__, host="0.0.0.0", port=80, worker_threads=2)

...

if __name__ == '__main__':
    t = AdvancedThread(target=lambda: app.run_server(), daemon=True) # you need a lambda here
    # OR
    t = Thread(target=lambda: app.run_server(), daemon=True)

    t.start()
    time.sleep(120)
    t.stop() # only available in AdvancedThread, not in Thread

Please notice that you must invoke thread=lambda: app.run_server() into the Thread()/AdvancedThread() constructor and not thread=app.run_server! The function passed into Thread()/AdvancedThread() must be defined in the same file that app is defined.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Aeros-0.1.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Aeros-0.1.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file Aeros-0.1.1.tar.gz.

File metadata

  • Download URL: Aeros-0.1.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6

File hashes

Hashes for Aeros-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d02046aa94e590db7240fa1d588ca24aadbe431ddb1997965579db8cab0cee04
MD5 4372d7eee05a0040c8c514c8a10c4403
BLAKE2b-256 e11b1ec9f9069fa5f12e0ad5f5ce870643e823463dc5564e3d7e8f222c9a692b

See more details on using hashes here.

File details

Details for the file Aeros-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: Aeros-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6

File hashes

Hashes for Aeros-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f1d483ffb367d3e40e5fcdeae70763aef92fd8ab44114c0a473828e7be6fc771
MD5 653417e5b09356dee0fc5416e2ed6c40
BLAKE2b-256 257ee2e38fa831e67ae3d1fc2e8cb2b0d6579d61a174c2d739993f38a815efd3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page