Giter Club home page Giter Club logo

nardis's Introduction

Nardis

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

Current status

Still not production-ready.

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

As such, please don't use this for production applications yet.

However, please do play around with it. Any feedback at this stage is welcome as the API becomes more stable.

Requirements

Python 3.6+

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 as get, Post as post
import asyncio


template_start = """
<!doctype html>
<head><title>example</title></head>
<body>
"""

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

async def index(req, res):
    """
    This just demonstrates that you can write async code. Don't actually write this in production.
    """
    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>liftoff!</p>", more=True)
    await res.send(template_end)


async def hello(req, res):
    """
    Try going to http://127.0.0.1:8000/hello/your_name/

    You'll see "Hello, your_name!"
    """
    name = req.params.get('name', 'world')
    await res.send(f"<h1>Hello, {name}!</h1>")


routes = [
    get(r"^/?$", index),
    get(r"^/hello/(?P<name>\w+)/?$", hello),
]

config = {
    'routes': routes,
}

app = main(config)  # 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

Alternatively, you could also do the following:

$ uvicorn application:app

This should start a server on http://127.0.0.1:8000

Using other web servers

Currently, Uvicorn is a dependency of Nardis.

The codebase doesn't actually use Uvicorn, but this dependency allows you to run your application quickly (see above example). This dependency might be removed in the future.

Nardis 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

nardis's People

Contributors

yoongkang avatar

Stargazers

Kaloyan Ivanov avatar Shiladitya Bose avatar Alex Bsk avatar  avatar Hotah Ma avatar Ioan Rîpan avatar Chojan Shang avatar briancaffey avatar Azim Khakulov avatar Adiyat Mubarak avatar Tom Christie avatar  avatar Nikolaus Schlemm avatar Erick Navarro avatar Roberto Prevato avatar Jordan Eremieff avatar

Watchers

James Cloos avatar  avatar

nardis's Issues

Allow simple way to replace Request/Response or Receiver/Sender classes

Users may want to supply their own class and we might want to allow them to configure this (like Flask). This would allow them to use, e.g Starlette.

Might have challenges due to a different interface, but shouldn't be a huge problem. The protocol handler needs to be decoupled from the receiver/sender objects, so that we're not locked in to a particular class.

Investigate allowing ASGI middleware

Some investigation is needed to enable other people (or myself) to write custom middleware.

This should preferably be ASGI-compatible middleware which should work for any ASGI application, rather than a custom Nardis middleware format.

WebSockets support

Figure out what API to provide for WebSockets support.

An experimental API is being explored in #1
(currently incomplete). We might also want to think about how Redis fits in.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.