Skip to main content

This is a simple http server, use MVC like design.

Project description

Naja Atra ASGI

This ia a ASGI proxy that proxies requests to Naja Atra.

Usage

Take uvicorn as an example.

import uvicorn
There is a legacy application
from naja_atra import route
from naja_atra_asgi import app

@route("/hello")
def hello(name: str):
    return {"messag": f"Hello, {name}!"}

if __name__ == '__main__':
    uvicon_conf = uvicorn.Config(
        app, host="0.0.0.0", port=9090, log_level="info")
    asgi_server = uvicorn.Server(uvicon_conf)
    asgi_server.run()

You can use server.scan() to import routes from other modules. And also you can use naja_atra_asgi.config() to function to sepecify the static resources routes.

import os
import uvicorn
import naja_atra.server as server

from naja_atra import route
from naja_atra_asgi import config, app

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

if __name__ == '__main__':
    server.scan(base_dir="tests/ctrls", regx=r'.*controllers.*',
                project_dir=PROJECT_ROOT)
    config(
        resources={"/public/*": f"{PROJECT_ROOT}/tests/static",
                   "/*": f"{PROJECT_ROOT}/tests/static"})
    uvicon_conf = uvicorn.Config(
        app, host="0.0.0.0", port=9090, log_level="info")
    asgi_server = uvicorn.Server(uvicon_conf)
    asgi_server.run()

Legacy Applications

You can use the legacy ASGI (V2) application function app_v2 if your server does not support ASGI V3.

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

naja-atra-asgi-1.0.1.tar.gz (7.2 kB view hashes)

Uploaded Source

Built Distribution

naja_atra_asgi-1.0.1-py3-none-any.whl (8.7 kB view hashes)

Uploaded Python 3

Supported by

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