GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • python-substack
  • View the Project on GitHub ma2za/python-substack

This view

  • Original page
  • New address

GeezerVison is showing ma2za.github.io — Low-level Python API

Low-level Python API

Most callers should use Api.create_draft_from_markdown. The Post builder is available for direct construction of Substack editor nodes.

import os

from dotenv import load_dotenv
from substack import Api
from substack.post import Post

load_dotenv()

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 Python",
    subtitle="Created with python-substack",
    user_id=api.get_user_id(),
    audience="everyone",
    write_comment_permissions="everyone",
)

post.paragraph("This is a paragraph.")
post.add(
    {
        "type": "paragraph",
        "content": [
            {"content": "A link to "},
            {
                "content": "Substack",
                "marks": [{"type": "link", "href": "https://substack.com"}],
            },
        ],
    }
)
post.add({"type": "paywall"})
post.add({"type": "captionedImage", "src": "https://example.com/image.png"})

draft = api.post_draft(post.get_draft())
api.prepublish_draft(draft["id"])
api.publish_draft(draft["id"])

The final three calls write to Substack. post_draft creates an unpublished draft. publish_draft publishes it and should be called only after review.

The node schema is undocumented upstream and may change. Prefer the Markdown renderer when it supports the content being authored.

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.