prompy.networkio package

prompy.networkio.call_factory module

call_factory

Meta web api wrapper.

Usage:

from prompy.networkio.call_factory import CallRoute, Caller
from prompy.threadio.promise_queue import PromiseQueuePool


class Api(Caller):
    def call_home(self, **kwargs):
        return CallRoute('/')

    def call_data(self, **kwargs):
        return CallRoute('/data', method='POST')


pool = PromiseQueuePool(start=True)
api = Api(base_url='http://localhost:5000', promise_container=pool)
api.call_data(data={'num': 6}).then(print).catch(print)
class prompy.networkio.call_factory.CallRoute(route, method='GET', content_type='application/json')[source]

Bases: object

Route object used by Caller

__init__(route, method='GET', content_type='application/json')[source]

Route data object with format methods.

Parameters:
  • route (str) – url to call, with optional templating.
  • method (str) – http method
  • content_type (str) –
format_data(data, encoding='utf-8')[source]

Serialize the data according to content-type.

Parameters:
Returns:

format_route_params(*args)[source]

Format the route params.

Example:
route = CallRoute('/user/<user>')
r = route.format_route_params(user='bob')
Returns:
class prompy.networkio.call_factory.Caller(base_url='', promise_container=None, prom_type=prompy.promise.Promise, prom_args=None)[source]

Bases: object

Wraps all method starting with call_ with a call.

route methods must:

  • return a CallRoute object.
  • kwargs must be there if you want Caller.call and route params kwargs.
__init__(base_url='', promise_container=None, prom_type=prompy.promise.Promise, prom_args=None)[source]
Parameters:
after_call(route, route_params, params, result, error)[source]

global after call callback

Parameters:
  • route (CallRoute) – The route that was called.
  • route_params (list) – The params of the route if any
  • params (dict) – The url params
  • result (Any) – The result of the call if any
  • error (Any) – The error of the call if any
Returns:

before_call(route, route_params, params)[source]

global before call callback.

Parameters:
  • route (CallRoute) – The route that was called.
  • route_params (list) – The params of the route if any
  • params (dict) – The url params
Returns:

call(route, route_params=None, params=None, headers=None, origin_req_host=None, unverifiable=False, data=None, **kwargs)[source]

Call a route, used by the wrapped route methods.

Parameters:
Return type:

Promise[~PromiseReturnType]

Returns:

prompy.networkio.urlcall module

prompy.networkio.urlcall.get(url, params=None, prom_type=prompy.promise.Promise, **kwargs)[source]
Return type:Promise[]
prompy.networkio.urlcall.json_call(url, payload=None, encoding='UTF-8', prom_type=prompy.promise.Promise, headers=None, **kwargs)[source]

Auto encode payload and decode response in json.

Return type:Promise[]
prompy.networkio.urlcall.post(url, data=None, prom_type=prompy.promise.Promise, **kwargs)[source]
Return type:Promise[]
prompy.networkio.urlcall.put(url, data, prom_type=prompy.promise.Promise, **kwargs)[source]
Return type:Promise[]
prompy.networkio.urlcall.url_call(url, data=None, headers=None, origin_req_host=None, unverifiable=False, method=None, content_mapper=<function default_content_mapper>, prom_type=prompy.promise.Promise, **kwargs)[source]

Base http call using urllib.

Parameters:
  • url
  • data
  • headers
  • origin_req_host
  • unverifiable
  • method
  • content_mapper (Callable[[str, str, str], Any]) –
  • prom_type
  • kwargs
Return type:

Promise[]

Returns:

A promise to resolve with a response.