Python SPDY library on top of Spdylay C library
Project description
Python-spdylay is a Python SPDY library on top of Spdylay C library. It supports SPDY/2 and SPDY/3 protocol.
It does not perform any I/O operations. When the library needs them, it calls the callback functions provided by the application. It also does not include any event polling mechanism, so the application can freely choose the way of handling events.
It provides almost all API Spdylay provides with Pythonic fashion.
The core library API works with Python 2 and 3. But ThreadedSPDYServer requires Python 3.3 because it uses TLS NPN extension.
Installation
First install Spdylay library. You can grab a source distribution from sf.net download page or clone git repository.
See Spdylay documentation for the required packages and how to build Spdylay from git repository.
After Spdylay is installed, run build_ext command to build extension module:
$ python setup.py build_ext
If you installed Spdylay library in other than standard location, use --include-dirs and --library-dirs to specify header file and library locations respectively.
Documentation
Samples
Here is a simple SPDY server:
#!/usr/bin/env python # The example SPDY server. Python 3.3 or later is required because TLS # NPN is used in spdylay.ThreadedSPDYServer. Put private key and # certificate file in the current working directory. import spdylay # private key file KEY_FILE='server.key' # certificate file CERT_FILE='server.crt' class MySPDYRequestHandler(spdylay.BaseSPDYRequestHandler): def do_GET(self): self.send_response(200) self.send_header('content-type', 'text/html; charset=UTF-8') content = '''\ <html> <head><title>SPDY FTW</title></head> <body> <h1>SPDY FTW</h1> <p>The age of HTTP/1.1 is over. The time of SPDY has come.</p> </body> </html>'''.encode('UTF-8') self.wfile.write(content) if __name__ == "__main__": HOST, PORT = "localhost", 3000 server = spdylay.ThreadedSPDYServer((HOST, PORT), MySPDYRequestHandler, cert_file=CERT_FILE, key_file=KEY_FILE) server.start()
Here is a simple SPDY client:
#!/usr/bin/env python # The example SPDY client. You need Python 3.3 or later because we # use TLS NPN. # # Usage: spdyclient.py URL... # import sys import spdylay class MyStreamHandler(spdylay.BaseSPDYStreamHandler): def on_header(self, nv): sys.stdout.write('Stream#{}\n'.format(self.stream_id)) for k, v in nv: sys.stdout.write('{}: {}\n'.format(k, v)) def on_data(self, data): sys.stdout.write('Stream#{}\n'.format(self.stream_id)) sys.stdout.buffer.write(data) def on_close(self, status_code): sys.stdout.write('Stream#{} closed\n'.format(self.stream_id)) if __name__ == '__main__': uris = sys.argv[1:] spdylay.urlfetch(uris, MyStreamHandler)
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
File details
Details for the file python-spdylay-0.1.2.tar.gz
.
File metadata
- Download URL: python-spdylay-0.1.2.tar.gz
- Upload date:
- Size: 152.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 019c4d32588edf3ed915d7c053bca607665cefd3fffcabb1b656da0c20625dd5 |
|
MD5 | af3be8ea01d74c495f8d5918962ef54d |
|
BLAKE2b-256 | 730bad7143c051e8a0085f8823f12bb6a20daf5539c188a4f479109c089c80c6 |