All Projects → Patreon → Patreon Python

Patreon / Patreon Python

Licence: apache-2.0
Interact with the Patreon API via OAuth

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Patreon Python

Starling Api Web Starter Kit
Starter kit and example app for using the Starling API.
Stars: ✭ 46 (-36.11%)
Mutual labels:  oauth
L Passport
Koa middleware and api sdk for wechat oauth, qq oauth, baidu oauth and weibo oauth
Stars: ✭ 52 (-27.78%)
Mutual labels:  oauth
Mailchimp Api 3.0 Php
A feature rich object-oriented PHP library for interacting with MailChimp's API v3 💌🐵
Stars: ✭ 61 (-15.28%)
Mutual labels:  oauth
Fxa Oauth Server
OAuth server for Firefox Accounts
Stars: ✭ 48 (-33.33%)
Mutual labels:  oauth
Visa
Easy third party authentication (OAuth 2.0) for Flutter apps.
Stars: ✭ 50 (-30.56%)
Mutual labels:  oauth
Idtoken Verifier
Lightweight RSA JWT verification
Stars: ✭ 52 (-27.78%)
Mutual labels:  oauth
Socialite
Socialite is an OAuth2 Authentication tool. It is inspired by laravel/socialite, you can easily use it without Laravel.
Stars: ✭ 1,026 (+1325%)
Mutual labels:  oauth
Ohloh api
Ohloh API examples
Stars: ✭ 64 (-11.11%)
Mutual labels:  oauth
Api server boilerplate
typescript express board boilerplate using routing controller
Stars: ✭ 52 (-27.78%)
Mutual labels:  oauth
React Native Learning Resources
Collection of some good resources for react-native ✨ 🔥 💥
Stars: ✭ 61 (-15.28%)
Mutual labels:  oauth
Wikibase Edit
a lib to edit Wikibase from NodeJS
Stars: ✭ 48 (-33.33%)
Mutual labels:  oauth
Qq
[READ ONLY] Subtree split of the SocialiteProviders/QQ Provider (see SocialiteProviders/Providers)
Stars: ✭ 50 (-30.56%)
Mutual labels:  oauth
Netcore Postgres Oauth Boiler
A basic .NET Core website boilerplate using PostgreSQL for storage, Adminer for db management, Let's Encrypt for SSL certificates and NGINX for routing.
Stars: ✭ 57 (-20.83%)
Mutual labels:  oauth
Twittex
Twitter client library for Elixir.
Stars: ✭ 46 (-36.11%)
Mutual labels:  oauth
Oauth
OAuth 2.0 Authorization Server & Authorization Middleware for Gin-Gonic
Stars: ✭ 61 (-15.28%)
Mutual labels:  oauth
Nemiro.oauth.dll
Nemiro.OAuth is a class library for authorization via OAuth protocol in .NET Framework
Stars: ✭ 45 (-37.5%)
Mutual labels:  oauth
Laravel Oauth
Social OAuth authentication for Laravel 5 & 6. Drivers: Facebook, Twitter, Google, LinkedIn, Github, Bitbucket.
Stars: ✭ 52 (-27.78%)
Mutual labels:  oauth
Bigcommerce Api Ruby
Connect Ruby applications with the Bigcommerce Platform
Stars: ✭ 69 (-4.17%)
Mutual labels:  oauth
Ttrss To Wallabag V2
A Tiny Tiny RSS plugin to post to a Wallabg v2 instance
Stars: ✭ 64 (-11.11%)
Mutual labels:  oauth
Google Auth Library Nodejs
🔑 Google Auth Library for Node.js
Stars: ✭ 1,094 (+1419.44%)
Mutual labels:  oauth

patreon-python

Version License Python Version Build Status

Interact with the Patreon API via OAuth.

Get the egg from PyPI, typically via pip:

pip install patreon

or

echo "patreon" >> requirements.txt
pip install -r requirements.txt

Make sure that, however you install patreon, you install its dependencies as well

Step 1. Get your client_id and client_secret

Visit the OAuth Documentation Page while logged in as a Patreon creator to register your client.

This will provide you with a client_id and a client_secret.

Step 2. Use this library

e.g., in a Flask route

import patreon
from flask import request
...

client_id = None      # Replace with your data
client_secret = None  # Replace with your data
creator_id = None     # Replace with your data

@app.route('/oauth/redirect')
def oauth_redirect():
    oauth_client = patreon.OAuth(client_id, client_secret)
    tokens = oauth_client.get_tokens(request.args.get('code'), '/oauth/redirect')
    access_token = tokens['access_token']

    api_client = patreon.API(access_token)
    user_response = api_client.get_identity()
    user = user_response.data()
    memberships = user.relationship('memberships')
    membership = memberships[0] if memberships and len(memberships) > 0 else None

    # pass user and membership to your view to render as needed

You'll notice that the user_response does not return raw JSON data. Instead, it returns a JSON:API resource object, to simplify traversing the normalized graph data that the Patreon API returns. Some available methods are:

  • response.data() to get the main resource
  • response.data().attribute('full_name') to get the full_name attribute from the response data
  • response.data().relationship('campaign').attribute('pledge_sum') to get the pledge_sum attribute from the campaign resource related to the main response data
  • response.find_resource_by_type_and_id('user', '123') to find an arbitrary resource

Step 3. (Optional) Customize your usage

patreon.API instances have methods for interacting with the API based on the routes described in the docs. All methods include includes and fields parameters.

ie:

  • get_identity(includes=None, fields=None)

List methods take page_size and cursor methods as well, ie:

  • get_campaigns(page_size, cursor=None, includes=None, fields=None)

The includes and fields arguments to these methods specify the related resources and the resource attributes you want returned by our API, as per the JSON:API specification. The lists of valid includes and fields arguments are provided on patreon.schemas. For instance, if you wanted to request the total amount a patron has ever paid to your campaign, which is not included by default, you could do:

api_client = patreon.API(patron_access_token)
patron_response = api_client.get_identity(None, {
    'membership': patreon.schemas.member.Attributes.currently_entitled_amount_cents
})

patreon.API also has a utility method extract_cursor which you can use to extract pagination links from our json:api response documents:

api_client = patreon.API(creator_access_token)
campaign_id = api_client.get_campaigns().data()[0].id()
memberships = []
cursor = None
while True:
    members_response = api_client.get_campaigns_by_id_members(campaign_id, 10, cursor=cursor)
    members += members_response.data()
    cursor = api_client.extract_cursor(members_response)
    if not cursor:
        break
names_and_membershipss = [{
    'full_name': member.relationship('user').attribute('full_name'),
    'amount_cents': member.attribute('amount_cents'),
} for member in members]

Developing

  1. Clone this repo
  2. Install dependencies
    • If you're on Python 3:
      python -m venv venv && source venv/bin/activate && python setup.py develop
      
    • If you're on Python 2:
      virtualenv venv && source venv/bin/activate && pip install -e . && pip install -r dev-requirements.txt
      
  3. git checkout -b my-branch-name
  4. make your edits, writing tests for any new functionality
  5. make sure tests pass with python setup.py test
  6. git push
  7. Open a pull request, explaining your changes (both problem and solution) clearly
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].