Skip to main content

A Python wrapper around the Substack API.

Project description

Python Substack

This is an unofficial library providing a Python interface for Substack. I am in no way affiliated with Substack.

Python Downloads Release Build

Installation

You can install python-substack using:

$ pip install python-substack

Setup

Set the following environment variables by creating a .env file:

PUBLICATION_URL=https://ma2za.substack.com
EMAIL=
PASSWORD=
USER_ID=

To discover the USER_ID go to your public profile page, in the URL bar of the browser you find the substack address followed by your USER_ID and your username: https://substack.com/profile/[USER_ID]-[username]

The .env file will be ignored by git but always be careful.


Usage

Check out the examples folder for some examples 😃 🚀

import os

from substack import Api
from substack.post import Post

api = Api(
    email=os.getenv("EMAIL"),
    password=os.getenv("PASSWORD"),
    publication_url=os.getenv("PUBLICATION_URL"),
)

post = Post(
    title="How to publish a Substack post using the Python API",
    subtitle="This post was published using the Python API",
    user_id=os.getenv("USER_ID")
)

post.add({'type': 'paragraph', 'content': 'This is how you add a new paragraph to your post!'})

#bolden text
post.add({'type': "paragraph",'content':[{'content': "This is how you "},{'content': "bolden ",'marks':[{'type': "strong"}]},{'content': "a word."}]})

#add hyperlink to text
post.add({'type':'paragraph','content':[{'content': "View Link",'marks':[{'type': "link",'href':'https://whoraised.substack.com/'}]}]})

#add image
post.add({'type':'captionedImage','src': "https://media.tenor.com/7B4jMa-a7bsAAAAC/i-am-batman.gif"})

draft = api.post_draft(post.get_draft())

api.prepublish_draft(draft.get("id"))

api.publish_draft(draft.get("id"))

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

python_substack-0.1.12.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

python_substack-0.1.12-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file python_substack-0.1.12.tar.gz.

File metadata

  • Download URL: python_substack-0.1.12.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.11.0 Linux/6.2.0-1015-azure

File hashes

Hashes for python_substack-0.1.12.tar.gz
Algorithm Hash digest
SHA256 350a986ce0ab3708f91c9144853dda98a9abd045c1943fdc9ed25e56bb8c0513
MD5 b42a012049ca022bad28abf4a489ac69
BLAKE2b-256 398c13bd5c61f9b3fd92a6985b226ad2d560392e1ab44ab05cfcc0df46b84a5d

See more details on using hashes here.

Provenance

File details

Details for the file python_substack-0.1.12-py3-none-any.whl.

File metadata

  • Download URL: python_substack-0.1.12-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.11.0 Linux/6.2.0-1015-azure

File hashes

Hashes for python_substack-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 2c076d27b653c52fea2c34b0fc8c3657e88a32b21fa370f4f7b23386d4694a4b
MD5 e4a547021b348b87f7a4bd79d7cf9226
BLAKE2b-256 f8bb136d8b7dacd608f54c35960f8d7c4026cecfa0bd9a31aa1f47b10d63609e

See more details on using hashes here.

Provenance

Supported by

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