Code Monkey home page Code Monkey logo

pyriform's Introduction

pyriform

Connect the requests library to your WSGI app without using sockets.

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!

Docs Release Version Python Version License Build Status Coverage Code Climate

You can browse the source code and file bug reports at the project repository. Full documentation can be found here.

pyriform's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.