medium-sdk-python

Python SDK for Medium's OAuth2 API

  • Owner: Medium/medium-sdk-python
  • Platform:
  • License:: Other
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Warning: This code is no longer supported or maintained by Medium.

Medium SDK for Python

This repository contains the open source SDK for integrating
Medium's OAuth2 REST API with your Python app.

For full API documentation, see our developer docs.

Installing dependencies

To install dependencies using pip:

pip install -r requirements.txt

Usage

from medium import Client

# Go to http://medium.com/me/applications to get your application_id and application_secret.
client = Client(application_id="MY_APPLICATION_ID", application_secret="MY_APPLICATION_SECRET")

# Build the URL where you can send the user to obtain an authorization code.
auth_url = client.get_authorization_url("secretstate", "https://yoursite.com/callback/medium",
                                        ["basicProfile", "publishPost"])

# (Send the user to the authorization URL to obtain an authorization code.)

# Exchange the authorization code for an access token.
auth = client.exchange_authorization_code("YOUR_AUTHORIZATION_CODE",
                                          "https://yoursite.com/callback/medium")

# The access token is automatically set on the client for you after
# a successful exchange, but if you already have a token, you can set it
# directly.
client.access_token = auth["access_token"]

# Get profile details of the user identified by the access token.
user = client.get_current_user()

# Create a draft post.
post = client.create_post(user_id=user["id"], title="Title", content="<h2>Title</h2><p>Content</p>",
                          content_format="html", publish_status="draft")

# When your access token expires, use the refresh token to get a new one.
client.exchange_refresh_token(auth["refresh_token"])

# Confirm everything went ok. post["url"] has the location of the created post.
print "My new post!", post["url"]

Running tests

To run tests against this package, first install the test requirements and make
sure that the medium package is exportable. (We recommend using virtualenv.)

$ pip install -r tests/requirements.txt
$ pip install -e .

Then run the primary test file:

$ python tests/test.py

Contributing

Questions, comments, bug reports, and pull requests are all welcomed. If you
haven't contributed to a Medium project before please head over to the Open
Source Project

and fill out an OCLA (it should be pretty painless).

Authors

License

Copyright 2015 A Medium Corporation

Licensed under Apache License Version 2.0. Details in the attached LICENSE file.

Overview

Name With OwnerMedium/medium-sdk-python
Primary LanguagePython
Program languagePython (Language Count: 1)
Platform
License:Other
Release Count3
Last Release Namev0.3.0 (Posted on )
First Release Namev0.1 (Posted on )
Created At2015-10-01 20:45:29
Pushed At2023-04-06 23:33:10
Last Commit At2018-10-30 11:21:02
Stargazers Count187
Watchers Count143
Fork Count27
Commits Count20
Has Issues Enabled
Issues Count0
Issue Open Count0
Pull Requests Count6
Pull Requests Open Count2
Pull Requests Close Count1
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private
To the top