Skip to main content

A very micro http framework.

Project description Requirements Status

A very micro HTTP framework.


  • 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.
  • Use -w/–watch to observe the changes in your project directory and reload the development server if desired.
  • A very flexible configuration system: pymlconf


The road map is to keep it simple. no built-in template engine and or ORM will be included.



$ pip install --pre nanohttp


$ cd path/to/nanohttp
$ pip install -e .

Quick Start

from os.path import dirname, abspath
from nanohttp import Controller, html, context, Static, HttpFound, settings

class Root(Controller):
    static = Static(abspath(dirname(__file__)))

    def index(self):
        yield '<html><head><title>nanohttp demo</title></head><body>'
        yield '<h1>nanohttp demo page</h1>'
        yield '<h2>debug flag is: %s</h2>' % settings.debug
        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>'
        yield '</body></html>'

    @html(methods=['post', 'put'])
    def contact(self):
        yield '<h1>Thanks: %s</h1>' % context.form['name'] if context.form else 'Please send a name.'

    def google(self):
        raise HttpFound('')

    def error(self):
        raise Exception()
$ nanohttp demo


from nanohttp import quickstart


Are you need a WSGI application?

app = Root().load_app()
# Pass the ``app`` to every ``WSGI`` server you want.


$ pip install -r requirements-optional.txt
$ nanohttp -w

Config File

Create a demo.yaml file.

debug: false

Use the nanohttp.settings anywhere to access the config values.

from nanohttp import Controller, html, settings

class Root(Controller):

    def index(self):
        yield '<html><head><title>nanohttp demo</title></head><body>'
        yield '<h2>debug flag is: %s</h2>' % settings.debug
        yield '</body></html>'

Passing the config file(s) using command line:

$ nanohttp -c demo.yaml [-c another.yaml] demo

Passing the config file(s) Using python:

from nanohttp import quickstart

quickstart(Root(), config_files=['file1', 'file2'])

Command Line Interface

$ nanohttp -h

usage: nanohttp [-h] [-c CONFIG_FILE] [-b {HOST:}PORT] [-d DIRECTORY] [-w]

positional arguments:
  MODULE{.py}{: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: `.`
  -w, --watch           If given, tries to watch the `--directory` and reload the app
                        on changes.
  -V, --version         Show the version.

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for nanohttp, version 0.1.0.dev5
Filename, size File type Python version Upload date Hashes
Filename, size nanohttp-0.1.0.dev5.tar.gz (9.1 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page