Skip to main content

A web framework based on ASGI

Project description

Nardis

A web framework based on ASGI. This is inspired by the Express framework for node.js.

Current status

This API is extremely experimental, and is subject to change at any time.

I do not recommend using it for production purposes, but I would love to get feedback.

Requirements

Written with Python 3.7, no guarantee it will work on earlier versions (although I think 3.6 would work fine).

Installation

Via pip

Run the following:

$ pip install nardis

From source

To build from source, clone this repo, and then:

$ python setup.py install

Example

Here's a quick example you can use. Create an application.py and copy and paste this:

from nardis.asgi import main
from nardis.routing import Get, Post
import asyncio


template_start = """
<!doctype html>
<head><title>example</title></head>
<body>
  <h1>He's down!</h1>
"""

template_end = """
</body>
"""

async def index(req, res):
    await res.send(template_start, more=True)
    for x in range(10, 0, -1):
        await res.send(f"<p>{x}!</p>", more=True)
        await asyncio.sleep(1)
    await res.send("<p>It's over. TKO!</p>", more=True)
    await res.send(template_end)


routes = [
    Get(r"^/?$", index),
]

app = main(routes)  # this is the ASGI application

if __name__ == '__main__':
    from uvicorn.run import run
    run(app, '127.0.0.1', 8000)

And then:

$ python application.py

This should start a server on http://127.0.0.1

Using other web servers

Uvicorn is currently a dependency of Nargis for local development.

Nargis should also work with other ASGI-based web servers, like Daphne.

To get Daphne working with the example code above, you could do the following:

$ daphne application:app

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

nardis-0.0.6.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

nardis-0.0.6-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file nardis-0.0.6.tar.gz.

File metadata

  • Download URL: nardis-0.0.6.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for nardis-0.0.6.tar.gz
Algorithm Hash digest
SHA256 c6ecdbd064cd43c607154f8195a7a581c0d95a3f77e166de5fbf19c75a091276
MD5 c1744bc7c473d21cd32e85a3a54f2d1c
BLAKE2b-256 a808a33ac5fc1d14c9acecbbe771d55ddf2ccc9fbdf65f00188de8bb034d7457

See more details on using hashes here.

File details

Details for the file nardis-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for nardis-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2475194e907641128330898350e7c87d7a29ae2d9216ce5685d8792812d7046f
MD5 5d4075c8783ffc8da610c423e4aeee11
BLAKE2b-256 cc41d2274522511713114643427d780bfd38942c8b322c5030fb02958ff8a79f

See more details on using hashes here.

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