Skip to content

Introduction

This document explains basic usage of spangle .

Installation

Python>=3.9 is required.

pip install spangle
pip install hypercorn # or your favorite ASGI server.

Hello World!

Let’s create a simple app that responses JSON.

# hello.py
from spangle import Api

api = Api()  # application instance.


# a view is defined as a class, and `api.route` decorates it.
@api.route("/")
class Hello:
    # view methods must be asynchronous.
    async def on_get(self, req, resp):
        resp.json.hello = "world"
        return resp # `return` is optional.
hypercorn hello:api

Now your first spangle app is running on your machine! Let’s open 127.0.0.1:8000 in your browser.

To config ASGI server, visit hypercorn’s repository .