A very micro http framework.
Project description
A very micro HTTP framework.
Features
Very simple, less-code & fast
Using object dispatcher instead of regex route dispatcher.
Url-Encoded & Multipart form parsing.
No request or response objects are available, everything is combined in nanohttp.context.
Roadmap
The road map is to keep it simple. no built-in template engine and or ORM will be included.
Install
PyPI
$ pip install --pre nanohttp
Source
$ cd path/to/nanohttp
$ pip install -e .
Quick Start
demo.py
from os.path import dirname, abspath
from nanohttp import Controller, html, context, Static
class Root(Controller):
static = Static(abspath(dirname(__file__)))
@html
def index(self):
yield '<img src="/static/cat.jpg" />'
yield '<ul>'
yield from ('<li><b>%s:</b> %s</li>' % i for i in context.environ.items())
yield '</ul>'
@html(methods=['post', 'put'])
def contact(self):
yield '<h1>Thanks: %s</h1>' % context.form['name'] if context.form else 'Please send a name.'
$ nanohttp demo
Or
from nanohttp import quickstart
quickstart(Root())
Are you need a WSGI application?
app = Root().load_app()
# Pass the ``app`` to every ``WSGI`` server you want.
Command Line Interface
$ nanohttp -h
usage: nanohttp [-h] [-c CONFIG_FILE] [-b {HOST:}PORT] [-d DIRECTORY] [-V]
[MODULE{:CLASS}]
positional arguments:
MODULE{:CLASS} The python module and controller class to launch.
default: `nanohttp:Demo`, And the default value for
`:CLASS` is `:Root` if omitted.
optional arguments:
-h, --help show this help message and exit
-c CONFIG_FILE, --config-file CONFIG_FILE
Default: nanohttp.yaml
-b {HOST:}PORT, --bind {HOST:}PORT
Bind Address. default: 8080
-d DIRECTORY, --directory DIRECTORY
The path to search for the python module, which
contains the controller class. default is: `.`
-V, --version Show the version.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nanohttp-0.1.0.dev1.tar.gz
(6.6 kB
view hashes)
Built Distribution
Close
Hashes for nanohttp-0.1.0.dev1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 607e311161c738e428b5ea189a7e32086b1baddbc88dc34c24799e51057ae5d2 |
|
MD5 | d6f9a25096d681449300524d09d1bb84 |
|
BLAKE2b-256 | fbc5e5786f57591f16d85361d4214c6e7cae2ff804b90f946020f7438606159a |