Connect the requests library to your WSGI app without using sockets.
Project description
Linking the Requests and WebTest libraries together, pyriform allows you to use the requests library to interact your WSGI app without needing to have it running on the network; it bonds these two web components together.
It’s useful for testing purposes, handles all standard HTTP methods (as well as custom ones), supports request timeouts. and is both Python 2 and 3 compatible.
Example Usage
Here’s an example with a small WSGI app (in this case, using CherryPy), and how we can use Pyriform to connect to it:
>>> # Create the WSGI app. >>> >>> import cherrypy >>> >>> class SayHello(object): ... ... @cherrypy.expose ... def default(self, word): ... return "Hello %s from %s!" % (word, cherrypy.request.headers['X-Location']) ... >>> cherrypy.config.update({'environment': 'embedded'}) # Suppress logging output. >>> app = cherrypy.tree.mount(SayHello(), '/') >>> >>> # Now use Pyriform to map requests from a particular URL to this app. >>> >>> import pyriform >>> import requests >>> adapter = pyriform.WSGIAdapter(app) >>> session = requests.Session() >>> session.mount('http://helloapp/', adapter) >>> resp = session.get('http://helloapp/World', headers={'X-Location': 'London'}) >>> print (resp.text) Hello World from London!
Full documentation can be found here.
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
pyriform-0.3.tar.gz
(4.7 kB
view hashes)
Built Distribution
Close
Hashes for pyriform-0.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8baf92cebfa900cf0483ab2b81ab3c36d831c997e97b8795644009738cd4ac31 |
|
MD5 | a0a9da42254ad846348c81a6f1dea783 |
|
BLAKE2b-256 | dd6c06a3b1ffd020e5c8bb766bf3de09dbc391c94ea6bd4f45571d5f2206dd6f |