Skip to content

Latest commit

History

History
39 lines (29 loc) · 923 Bytes

File metadata and controls

39 lines (29 loc) · 923 Bytes
layoutdefault
titlePython SDK

Python SDK

Use Api.create_draft_from_markdown for the same draft-only workflow as the CLI:

importosfromdotenvimportload_dotenvfromsubstackimportApiload_dotenv()
api=Api(
cookies_path=os.getenv("COOKIES_PATH"),
publication_url=os.getenv("PUBLICATION_URL"),
)
result=api.create_draft_from_markdown(
title="Shipping with Python",
subtitle="A draft created from a script",
markdown="# Hello\n\nThis is **Markdown**.",
tags=["python", "automation"],
)
print(result["draft"]["id"])

The method creates an unpublished draft by default. It publishes only when publish=True is passed. It can also set audience, comment permissions, SEO metadata, slug, section, and tags.

For supported syntax, see the Markdown reference. For direct editor-node construction, see the low-level Python API.