Porc is an effortless, asynchronous interface for Orchestrate that handles common headers, authorization, and other settings so you can focus on building apps.

Let’s take it for a spin.

Build Passing

Coverage

Pypr Package.png

Install

pip is a Python package installer which pulls packages from PyPI and installs them in your current Python environment. If you don’t already have it, get it! It’s neat :D.

To install porc, just do:

pip install porc

Usage

Let’s create an authenticated client, which we’ll use to make requests:

import porc

YOUR_API_KEY = '...'
client = porc.Client(YOUR_API_KEY)

By default, Porc makes asynchronous requests. To make synchronous requests instead, initialize your client with async=False, like this:

client = Client(YOUR_API_KEY, async=False)

Synchronous requests, rather than returning futures, will block until they complete, before returning the same response objects as resolved promises.

Now then, how’s about we create a key, yeah?

import porc

client = porc.Client(YOUR_API_KEY)
collection = client.collection('newcollection')
key = collection.key('derp')
future = key.put({"hello": "world"})
response = future.result()
print response.status_code
# 201

The synchronous equivalent:

import porc

client = porc.Client(YOUR_API_KEY, async=False)
collection = client.collection('newcollection')
key = collection.key('derp')
response = key.put({"hello": "world"})
print response.status_code
# 201

Porc lightly wraps the REST API, returning Requests objects from any methods that talk with Orchestrate, and exposing path parameters both on responses and on Porc clients:

import porc

client = porc.Client(API_KEY)
collection = client.collection('hello')
key = collection.key('world')
print key.path
# {"collection": "hello", "key": "world"}
response = key.get().result()
# throw an error if we get a status code in the 400s or 500s
response.raise_for_status()
print response.path
# {"collection": "hello", "key": "world", "ref": "cbb48f9464612f20"}

Porc treats search results as iterables, so you can loop over collection contents, lists of events, graph searches, etc.:

import porc

client = porc.Client(API_KEY)
collection = client.collection(COLLECTION)
# get every request going
futures = [future for future in collection.list()]
# resolve every request
responses = [future.result() for future in futures]
results = []
[results.extend(response.json()['results']) for response in responses]
# now you have the whole collection in `results` :O

This is only the tip of the iceberg. Jump into the source for more information, read the API reference, or pip install porc and start playing around. If there are features you want added, post an issue and we’ll get right on it.

Happy coding!