Skip to main content

Version-agnostic core for brittle_wit package

Project description

https://travis-ci.org/jbn/brittle_wit_core.svg?branch=master https://ci.appveyor.com/api/projects/status/69kj3prrrieyp8q2/branch/master?svg=true https://coveralls.io/repos/github/jbn/brittle_wit_core/badge.svg?branch=master https://img.shields.io/pypi/dm/brittle_wit_core.svg https://img.shields.io/pypi/v/brittle_wit_core.svg https://img.shields.io/badge/license-MIT-blue.svg https://img.shields.io/pypi/pyversions/brittle_wit_core.svg

What is this?

This package contains the core of [brittle_wit](https://github.com/jbn/brittle_wit), a twitter lib for python. It works with Python 2.7, whereas brittle_wit does not. It’s extracted from the main library so that you can reuse this core code for authentication flows (e.g. on GAE).

Sample Authentication Flow with requests

from requests import request
from brittle_wit_core import (AppCredentials,
                              obtain_request_token,
                              extract_access_token,
                              redirect_url,
                              obtain_access_token,
                              extract_request_token)

# Loads via TWITTER_APP_KEY, TWITTER_APP_SECRET environmental variables.
APP_CRED = AppCredentials.load_from_env()

# Get an access token.
twitter_req, headers = obtain_request_token(APP_CRED)
resp = request(twitter_req.method,
               twitter_req.url,
               params=twitter_req.params,
               headers=headers)
oauth_token, oauth_secret = extract_request_token(resp.status_code,
                                                  resp.content.decode('utf8'))

# Redirect the user to a PIN page.
url = redirect_url(oauth_token)
print(url)
pin = input("PIN: ").strip()


# Turn their pin response into an access token.
twitter_req, headers = obtain_access_token(APP_CRED, oauth_token, pin)

resp = request(twitter_req.method,
               twitter_req.url,
               params=twitter_req.params,
               headers=headers)
d = extract_access_token(resp.status_code, resp.content.decode('utf8'))
print(d)

Project details


Download files

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

Source Distribution

brittle_wit_core-0.0.3.tar.gz (13.0 kB view details)

Uploaded Source

File details

Details for the file brittle_wit_core-0.0.3.tar.gz.

File metadata

File hashes

Hashes for brittle_wit_core-0.0.3.tar.gz
Algorithm Hash digest
SHA256 8b446a3be5475ae13ed6de2a9374ed91933479f1c25dfc1bf08c3266888b4fc2
MD5 b61259f06e9797961036038ff5134321
BLAKE2b-256 abfaeb33d4e123575fbf08a9498cf20e24ec31943305e8438feb28890fdec8b6

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