Skip to main content

Simple Event-Driven IO for Python

Project description

Thor

CI Coverage Status

About Thor

Thor is yet another Python 3 library for evented IO.

There are many such libraries for Python already available. Thor focuses on making it easy to build high-performance HTTP intermediaries like proxies, load balancers, content transformation engines and service aggregators. Of course, you can use it just as a client or server too.

It aims to be as fast as possible, to implement the protocols correctly, and to be simple. You can help meet these goals by contributing issues, patches and tests.

Thor’s EventEmitter API is influenced by^H^H^H copied from NodeJS; if you’re familiar with Node, it shouldn’t be too hard to use Thor. However, Thor is nothing like Twisted; this is considered a feature.

Currently, Thor has an event loop as well as TCP, UDP and HTTP APIs (client and server). New APIs (e.g., DNS) and capabilities should be arriving soon, along with a framework for intermediation.

Requirements

Thor just requires Python 3.8 or greater.

Currently, it will run on most Posix platforms; specifically, those that offer one of poll, epoll or kqueue.

Installation

If you have setuptools, you can install from the repository:

easy_install thor

or using pip:

pip install thor

On some operating systems, that might be pip3. Otherwise, download a tarball and install using:

python setup.py install

Using Thor

The documentation is a good starting point; see also the docstrings for the various modules, as well as the tests, to give an idea of how to use Thor.

For example, a very simple HTTP server looks like this:

import thor, thor.http
def test_handler(exch):
    @thor.events.on(exch)
    def request_start(*args):
        exch.response_start(200, "OK", [('Content-Type', 'text/plain')])
        exch.response_body('Hello, world!')
        exch.response_done([])

if __name__ == "__main__":
    demo_server = thor.http.HttpServer('127.0.0.1', 8000)
    demo_server.on('exchange', test_handler)
    thor.run()

Support and Contributions

See Thor's GitHub to give feedback, view and report issues, and contribute code.

All helpful input is welcome, particularly code contributions via a pull request (with test cases).

Why Thor?

Thor is not only “a hammer-wielding god associated with thunder, lightning, storms, oak trees, strength, destruction, fertility, healing, and the protection of mankind”, he’s also my Norwegian Forest Cat.

Thor (the software program) grew out of nbhttp, which itself came from earlier work on evented Python in redbot.

Thor (the cat) now rules our house with a firm but benevolent paw. He gets sick if we give him any milk, though.

Thor, the cat

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

thor-0.11.5.tar.gz (47.1 kB view details)

Uploaded Source

Built Distribution

thor-0.11.5-py3-none-any.whl (56.8 kB view details)

Uploaded Python 3

File details

Details for the file thor-0.11.5.tar.gz.

File metadata

  • Download URL: thor-0.11.5.tar.gz
  • Upload date:
  • Size: 47.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for thor-0.11.5.tar.gz
Algorithm Hash digest
SHA256 a4afe8c4a64c96ccf0e6f6bee013a6e3502fe7ce379f4ebf75789ff529960291
MD5 a44c8be008e816849ecb3018bfbb1f83
BLAKE2b-256 d6f719573a1cdf7c6396b61bfc67329bd4ca5c8ca7657ce0936b99e0e967210a

See more details on using hashes here.

Provenance

File details

Details for the file thor-0.11.5-py3-none-any.whl.

File metadata

  • Download URL: thor-0.11.5-py3-none-any.whl
  • Upload date:
  • Size: 56.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for thor-0.11.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9550db69ba8454d9f5419c654a9e41e6deff9b14dbef2367de2b1fcbcf8cf696
MD5 7a75a535a45795d407eee52e356c52af
BLAKE2b-256 7967e3e6df099ebff0c5b70461dca48708b05f32c31544ee19b2c93482270ff0

See more details on using hashes here.

Provenance

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