Skip to content

Instantly share code, notes, and snippets.

Last active November 5, 2022 10:37
Show Gist options
  • Save jbwhaley/126ddcd807bf5ff95909a78d863e1e6d to your computer and use it in GitHub Desktop.
Save jbwhaley/126ddcd807bf5ff95909a78d863e1e6d to your computer and use it in GitHub Desktop.
This script facilitates posting to on iOS with Drafts (using Pythonista).
import requests
import sys
import webbrowser
# Replace the 'API_KEY' value below with your API key;
# get one at
# Grab input from Drafts
content = str(sys.argv[1])
def send_request(content):
# Request
response =
"Authorization": HEADER_VALUE,
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
"h": "entry",
"content": content,
print('Response HTTP Status Code: {status_code}'.format(
print('Response HTTP Response Body: {content}'.format(
# Set Drafts URL, then open it when post successful.
drafts_url = 'drafts4://x-callback-url/create?text=' + ''
except requests.exceptions.RequestException:
print('HTTP Request failed')
if __name__ == "__main__":
Copy link

jbwhaley commented Nov 23, 2017

How to Use

This script enables easy posting to on iOS directly from Drafts by way of Pythonista. Setting it up is easy.

  • Head over to your account page at and create a new App Token: click on "Edit Apps", enter the name of this script ("") in the "App Name" field, and generate a new token.
  • Copy the Python script and paste it into a new file in Pythonista 3; be sure to call the file "".
  • Replace the "XXXXXX..." on line 8 with the API token you generated earlier.
  • In Drafts, create a new URL action that sends text to this URL: pythonista://MicroBlogger?action=run&argv=%5B%5Bdraft%5D%5D
  • Now just type your post into Drafts, fire the action, and there you go.


  • Note that if you are using the current beta of Pythonista, you may need to add a "root" parameter to the Drafts URL action, if you are using an alternative root folder in Pythonista.
  • You can find me on at @jbwhaley if you have any questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment