• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    Python
  • License
    Other
  • Created over 13 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easy Evented Intermediation

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.6 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

More Repositories

1

htracr

HTTP sniffing and low-level visualisation
JavaScript
531
star
2

redbot

REDbot is lint for HTTP resources.
Python
531
star
3

hinclude

declarative client-side inclusion for the Web
JavaScript
307
star
4

nbhttp

non-blocking HTTP. All further development will be at mnot/thor.
Python
231
star
5

rfc.fyi

Browseable, searchable RFC index
JavaScript
118
star
6

I-D

My Internet-Drafts
HTML
98
star
7

wadl_stylesheets

XSLT stylesheets to create HTML documentation from WADL files
77
star
8

avoiding-internet-centralization

Internet-Draft about avoiding internet centralization
Makefile
42
star
9

sparta

a Simple API for RDF
Python
29
star
10

web_caching_tutorial

The Caching Tutorial for Web Authors and Webmasters
HTML
17
star
11

sweet

Interoperable Content-Disposistion headers for Node.JS
JavaScript
15
star
12

http_sfv

Parse and serialise HTTP structured field values
Python
13
star
13

squid-director

Squid helper to canonicalise and rewrite URLs
Python
13
star
14

squid-channels

Cache Channels for Squid
Python
10
star
15

squidpeek

Per-URL Squid logfile statistics and sparklines
Python
9
star
16

squid-lci

Linked Cache Invalidation for Squid
Python
8
star
17

isitrestful

Source for isitrestful.com
Python
6
star
18

photoweb

Templated HTML galleries based on in-photo metadata
Python
6
star
19

httplint

Python library to lint HTTP messages
Python
5
star
20

http-test

Tests for HTTP implementations
JavaScript
5
star
21

pipeline-surveyor

Check to see if HTTP pipelining is safe
JavaScript
5
star
22

http-sf

HTTP Structured Fields for Python
Python
5
star
23

tarawa

Tarawa is a Toolkit for RESTful Webapps; a set of Python libraries for server-side, client-side and intermediary HTTP communications, with an emphasis on conformance to RFC2616 and the principles of REST.
Python
5
star
24

variants-toy

Proving the algorithms in draft-nottingham-variants
Python
4
star
25

ietf-comments

Automating IETF comment handling
Python
4
star
26

rfc-http-validate

Validate HTTP messages in XML2RFC documents
Python
4
star
27

xhr-test

xmlhttprequest tests
Assembly
3
star
28

hdrgrab

Grab HTTP headers
JavaScript
3
star
29

header-explorer

Rummaging around HTTP Archive dumps to see what's interesting
Python
3
star
30

meetingbot

XMPP / Jabber bot to help run a meeting
Python
3
star
31

RFCbootstrap

Bootstrap-based XML2RFC stylesheet
XSLT
2
star
32

v3grammar

Tracking evolution of the XML2RFCv3 grammar
2
star
33

friends2feeds

Taking Feeds Back from Social Media
Python
2
star
34

dotfiles

just my dot files
Shell
1
star
35

conn-sniff

basic TCP connection sniffing
JavaScript
1
star
36

theme

Theme for GitHub Pages
HTML
1
star
37

book-club

Discussion of papers and books about Internet governance, regulation, privacy, and law
1
star
38

rfc-refs

References between RFCs in JSON format
Python
1
star
39

pyproject-tmpl

Template for Python projects
Python
1
star
40

w3c-community

Visualisation of W3C community groups
HTML
1
star