Skip to main content

Python interface to the Janrain Capture API.

Project description

[![Build Status](https://travis-ci.org/janrain/janrain-python-api.png?branch=master)](https://travis-ci.org/janrain/janrain-python-api)

Python interface to the Janrain Capture API.

Install

Download and install the most recent stable version using pip:

pip install janrain-python-api

To use the unstable developement version, download the package by cloning the git repository:

git clone https://github.com/janrain/janrain-python-api.git
cd janrain-python-api
python setup.py install

Basic Usage

Low-Level API Calls

Use janrain.capture.Api to make low-level calls to the API.

from janrain.capture import Api

defaults = {
    'client_id': "YOUR_CLIENT_ID",
    'client_secret': "YOUR_CLIENT_SECRET"
}

api = Api("https://YOUR_APP.janraincapture.com", defaults)
result = api.call("entity.count", type_name="user")
print(result)

Exceptions

Exceptions are derived from JanrainApiException which includes error responses from the API. A try/catch bock should wrap any functions or methods that call the Janrain API.

from janrain.capture import Api, ApiResponseError
from requests import HTTPError

defaults = {
    'client_id': "YOUR_CLIENT_ID",
    'client_secret': "YOUR_CLIENT_SECRET"
}

api = Api("https://YOUR_APP.janraincapture.com", defaults)

try:
    result = api.call("entity.find", type_name="user")
except janrain.capture.ApiResponseError as error:
    # Janrain API returned an error response
    sys.exit(str(error))
except HTTPError as error:
    # Python 'requests' library returned an error
    sys.exit(str(error))

Argument Parser

The library includes a subclass of the Python argparse configured to accept credentials for authenticating with the Janrain API. This can be used to simplify passing in credentials in custom command-line scripts.

from janrain.capture import cli

parser = cli.ApiArgumentParser()
args = parser.parse_args()
api = parser.init_api()

Which can then invoke from the command-line as follows:

python myscript.py  --api-url=[YOUR_CAPTURE_URL] \
                    --client-id=[YOUR_CLIENT_ID] \
                    --client-secret=[YOUR_CLIENT_SECRET] \

Command-Line Utility

The package installs an executable named capture-api for making API calls from the command-line.

Authenticate with the API by passing --api-url, --client-id, and --client-secret, then pass the API call, and then any parameters to send to the API as key=value pairs after the --parameters argument.

Examples

Passing the authentication credentials:

capture-api --api-url=[YOUR_CAPTURE_URL] \
            --client-id=[YOUR_CLIENT_ID] \
            --client-secret=[YOUR_CLIENT_SECRET] \
            entity.count --parameters type_name=user

Enclose JSON values in single outer-quotes and double inner-quotes:

capture-api --api-url=[YOUR_CAPTURE_URL] \
            --client-id=[YOUR_CLIENT_ID] \
            --client-secret=[YOUR_CLIENT_SECRET] \
            entity.find --parameters type_name=user \
            attributes='["displayName","email"]'

Enclose filters in double outer-quotes and single inner-quotes:

capture-api --api-url=[YOUR_CAPTURE_URL] \
            --client-id=[YOUR_CLIENT_ID] \
            --client-secret=[YOUR_CLIENT_SECRET] \
            entity.find --parameters type_name=user \
            filter="email = 'demo@janrain.com' and birthday is null"

Versioning

This software follows Semantic Versioning convention. http://semver.org/

Copyright © 2014 Janrain, Inc. All Rights Reserved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

janrain-python-api-0.3.1.tar.gz (16.5 kB view details)

Uploaded Source

janrain-python-api-0.3.0.tar.gz (15.3 kB view details)

Uploaded Source

File details

Details for the file janrain-python-api-0.3.1.tar.gz.

File metadata

File hashes

Hashes for janrain-python-api-0.3.1.tar.gz
Algorithm Hash digest
SHA256 3b62569889e4dffb4b1631a02435b00ec574b882f1ef5d02f7e99b55d7146cfb
MD5 d46133da5cc9225464a045b734b549f3
BLAKE2b-256 6bedea77fa88526ad1b66188b2962d48684bb5c0c0ac0b00ef0fac2ebfb0c927

See more details on using hashes here.

File details

Details for the file janrain-python-api-0.3.0.tar.gz.

File metadata

File hashes

Hashes for janrain-python-api-0.3.0.tar.gz
Algorithm Hash digest
SHA256 960d6a1d535dce4c917b5e26979176c1abe0414d53b90d8856f5df9315f4effc
MD5 89aa1ab9525924960351cc218b7c220a
BLAKE2b-256 b747e0f6d0ef28fdffa2ea1154417bc337e1d98f9194741e180dd9d83fee3f36

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page