Safe Substack draft automation from Markdown with Python, CLI, and MCP.
python-substack accepts email and password credentials, a cookies JSON file, or a browser cookie header string.
EMAIL=
PASSWORD=
PUBLICATION_URL=
COOKIES_PATH=
COOKIES_STRING=
Use either EMAIL and PASSWORD, or one cookie method. When both cookie
methods and email credentials are present, cookie authentication takes
precedence.
import os
from substack import Api
api = Api(
cookies_path=os.getenv("COOKIES_PATH"),
publication_url=os.getenv("PUBLICATION_URL"),
)
Export the active session for later use:
api.export_cookies("cookies.json")
Set COOKIES_PATH=cookies.json or pass the file to the CLI:
substack --cookies cookies.json status
cookie request header value into COOKIES_STRING.api = Api(
cookies_string=os.getenv("COOKIES_STRING"),
publication_url=os.getenv("PUBLICATION_URL"),
)
Never commit .env, cookie files, passwords, or copied request headers.
Some accounts use magic-link sign-in by default. To configure a password, sign out of Substack, choose “Sign in with password”, and then choose “Set a new password”.
Set PUBLICATION_URL for the default publication or override it for one
unified CLI invocation:
substack --publication-url https://example.substack.com status
List the publications available to the authenticated account:
substack publications list