python-substack 0.1.25__tar.gz → 0.1.27__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-substack
3
- Version: 0.1.25
4
- Summary: A Python wrapper around the Substack API.
3
+ Version: 0.1.27
4
+ Summary: A Python SDK and CLI for managing Substack publications and drafts.
5
5
  License: MIT
6
6
  License-File: LICENSE
7
- Keywords: substack
7
+ Keywords: substack,substack-api,cli,newsletter,publishing,automation,mcp
8
8
  Author: Paolo Mazza
9
9
  Author-email: mazzapaolo2019@gmail.com
10
10
  Requires-Python: >=3.10,<4.0
@@ -24,7 +24,7 @@ Provides-Extra: mcp
24
24
  Requires-Dist: PyYAML (>=6.0,<7.0)
25
25
  Requires-Dist: fastmcp (>=3.1.1,<4.0.0) ; extra == "mcp"
26
26
  Requires-Dist: markdown-it-py (>=3.0,<4.0)
27
- Requires-Dist: mdit-py-plugins (>=0.4,<0.5)
27
+ Requires-Dist: mdit-py-plugins (>=0.5,<0.7)
28
28
  Requires-Dist: python-dotenv (>=1.2.1,<2.0.0)
29
29
  Requires-Dist: requests (>=2.32.0,<3.0.0)
30
30
  Project-URL: Changelog, https://github.com/ma2za/python-substack/blob/main/CHANGELOG.md
@@ -35,13 +35,20 @@ Description-Content-Type: text/markdown
35
35
 
36
36
  # Python Substack
37
37
 
38
- Unofficial Python tools for publishing to [Substack](https://substack.com/).
38
+ An unofficial Python SDK and CLI for managing [Substack](https://substack.com/) publications and drafts.
39
39
 
40
+ [![PyPI](https://img.shields.io/pypi/v/python-substack)](https://pypi.org/project/python-substack/)
41
+ [![Python](https://img.shields.io/pypi/pyversions/python-substack)](https://pypi.org/project/python-substack/)
42
+ [![Tests](https://github.com/ma2za/python-substack/actions/workflows/ci.yml/badge.svg)](https://github.com/ma2za/python-substack/actions/workflows/ci.yml)
43
+ [![Release](https://github.com/ma2za/python-substack/actions/workflows/ci_publish.yml/badge.svg)](https://github.com/ma2za/python-substack/actions/workflows/ci_publish.yml)
44
+ [![License](https://img.shields.io/pypi/l/python-substack)](LICENSE)
40
45
  [![Downloads](https://static.pepy.tech/badge/python-substack/month)](https://pepy.tech/project/python-substack)
41
- ![Release Build](https://github.com/ma2za/python-substack/actions/workflows/ci_publish.yml/badge.svg)
42
46
 
43
47
  ## Features
44
48
 
49
+ - Inspect authentication and publication status from the terminal.
50
+ - List publications and inspect, schedule, publish, or delete drafts.
51
+ - Use stable JSON output in scripts and automation.
45
52
  - Create drafts and publish posts from Python.
46
53
  - Convert Markdown into Substack's editor document format.
47
54
  - Upload local images while rendering Markdown.
@@ -78,6 +85,76 @@ Use either `EMAIL` and `PASSWORD`, or cookie-based authentication with `COOKIES_
78
85
 
79
86
  Newer Substack accounts may only have magic-link sign-in enabled. To set a password, sign out of Substack, choose "Sign in with password", then choose "Set a new password".
80
87
 
88
+ ## CLI Operations
89
+
90
+ Create a draft from Markdown without publishing it:
91
+
92
+ ```bash
93
+ substack drafts create post.md
94
+ ```
95
+
96
+ Set metadata and repeat `--tag` to attach multiple tags:
97
+
98
+ ```bash
99
+ substack --json drafts create post.md \
100
+ --title "My Post" \
101
+ --subtitle "Optional subtitle" \
102
+ --tag python \
103
+ --tag substack \
104
+ --slug my-post \
105
+ --search-engine-title "SEO title" \
106
+ --search-engine-description "SEO description"
107
+ ```
108
+
109
+ Creation and publishing are intentionally separate. Use the returned draft ID
110
+ when the draft is ready:
111
+
112
+ ```bash
113
+ substack drafts create post.md
114
+ substack drafts publish 12345 --no-send
115
+ ```
116
+
117
+ Check authentication, the selected publication, and subscriber count:
118
+
119
+ ```bash
120
+ substack status
121
+ ```
122
+
123
+ List available publications or target one without changing `.env`:
124
+
125
+ ```bash
126
+ substack publications list
127
+ substack --publication-url https://example.substack.com drafts list
128
+ ```
129
+
130
+ List and inspect drafts:
131
+
132
+ ```bash
133
+ substack drafts list --limit 10
134
+ substack drafts get 12345
135
+ ```
136
+
137
+ Schedule with a timezone-aware ISO 8601 timestamp, or remove a schedule:
138
+
139
+ ```bash
140
+ substack drafts schedule 12345 --at 2026-08-01T09:00:00+03:00
141
+ substack drafts unschedule 12345
142
+ ```
143
+
144
+ Publishing and deletion prompt for confirmation. Use `--yes` for intentional non-interactive execution:
145
+
146
+ ```bash
147
+ substack drafts publish 12345 --no-send
148
+ substack drafts delete 12345 --yes
149
+ ```
150
+
151
+ Global options must appear before the command. `--json` returns stable envelopes containing the raw Substack responses:
152
+
153
+ ```bash
154
+ substack --json drafts list
155
+ substack --cookies cookies.json --json status
156
+ ```
157
+
81
158
  ## Quickstart
82
159
 
83
160
  ```python
@@ -113,7 +190,9 @@ print(result["draft"]["id"])
113
190
 
114
191
  `create_draft_from_markdown` creates a draft by default. It only publishes when `publish=True` is passed.
115
192
 
116
- ## CLI
193
+ ## Legacy Content Publishing CLI
194
+
195
+ The existing standalone commands remain supported for compatibility.
117
196
 
118
197
  Check authentication without creating a draft:
119
198
 
@@ -290,7 +369,7 @@ Paragraph with **bold**, *italic*, `code`, [links](https://example.com), and foo
290
369
  )
291
370
  ```
292
371
 
293
- Supported Markdown includes headings, paragraphs, bold, italic, inline code, strikethrough, links, images, linked images, image captions, code blocks, blockquotes, ordered lists, unordered lists, horizontal rules, and footnotes.
372
+ Supported Markdown includes headings, paragraphs, bold, italic, inline code, strikethrough, superscript, subscript, links, images, linked images, image captions, code blocks, blockquotes, ordered lists, unordered lists, horizontal rules, footnotes, LaTeX math, pull quotes, and callouts. See [docs/markdown.md](docs/markdown.md) for the full reference with examples.
294
373
 
295
374
  When an `Api` instance is passed to `from_markdown`, local image paths are uploaded before the draft is created:
296
375
 
@@ -371,9 +450,28 @@ pre-commit install
371
450
  pytest
372
451
  ```
373
452
 
374
- Live Substack tests are opt-in. Set `RUN_SUBSTACK_E2E=1` and configure credentials before running them.
453
+ Run the offline suite with:
454
+
455
+ ```bash
456
+ pytest -m "not live"
457
+ ```
458
+
459
+ Live Substack tests are not part of normal CI. They are opt-in and require
460
+ configured credentials:
461
+
462
+ ```bash
463
+ RUN_SUBSTACK_E2E=1 pytest -m live
464
+ ```
465
+
466
+ The CLI operations smoke tests are separately opt-in. They create, inspect, and
467
+ delete disposable drafts but never publish them:
468
+
469
+ ```bash
470
+ RUN_SUBSTACK_CLI_E2E=1 pytest -m live tests/substack/test_cli_end_to_end.py
471
+ ```
375
472
 
376
473
  Release changes are tracked in [CHANGELOG.md](CHANGELOG.md).
474
+ The maintainer release process is documented in [docs/releasing.md](docs/releasing.md).
377
475
 
378
476
  ## Disclaimer
379
477
 
@@ -1,12 +1,19 @@
1
1
  # Python Substack
2
2
 
3
- Unofficial Python tools for publishing to [Substack](https://substack.com/).
3
+ An unofficial Python SDK and CLI for managing [Substack](https://substack.com/) publications and drafts.
4
4
 
5
+ [![PyPI](https://img.shields.io/pypi/v/python-substack)](https://pypi.org/project/python-substack/)
6
+ [![Python](https://img.shields.io/pypi/pyversions/python-substack)](https://pypi.org/project/python-substack/)
7
+ [![Tests](https://github.com/ma2za/python-substack/actions/workflows/ci.yml/badge.svg)](https://github.com/ma2za/python-substack/actions/workflows/ci.yml)
8
+ [![Release](https://github.com/ma2za/python-substack/actions/workflows/ci_publish.yml/badge.svg)](https://github.com/ma2za/python-substack/actions/workflows/ci_publish.yml)
9
+ [![License](https://img.shields.io/pypi/l/python-substack)](LICENSE)
5
10
  [![Downloads](https://static.pepy.tech/badge/python-substack/month)](https://pepy.tech/project/python-substack)
6
- ![Release Build](https://github.com/ma2za/python-substack/actions/workflows/ci_publish.yml/badge.svg)
7
11
 
8
12
  ## Features
9
13
 
14
+ - Inspect authentication and publication status from the terminal.
15
+ - List publications and inspect, schedule, publish, or delete drafts.
16
+ - Use stable JSON output in scripts and automation.
10
17
  - Create drafts and publish posts from Python.
11
18
  - Convert Markdown into Substack's editor document format.
12
19
  - Upload local images while rendering Markdown.
@@ -43,6 +50,76 @@ Use either `EMAIL` and `PASSWORD`, or cookie-based authentication with `COOKIES_
43
50
 
44
51
  Newer Substack accounts may only have magic-link sign-in enabled. To set a password, sign out of Substack, choose "Sign in with password", then choose "Set a new password".
45
52
 
53
+ ## CLI Operations
54
+
55
+ Create a draft from Markdown without publishing it:
56
+
57
+ ```bash
58
+ substack drafts create post.md
59
+ ```
60
+
61
+ Set metadata and repeat `--tag` to attach multiple tags:
62
+
63
+ ```bash
64
+ substack --json drafts create post.md \
65
+ --title "My Post" \
66
+ --subtitle "Optional subtitle" \
67
+ --tag python \
68
+ --tag substack \
69
+ --slug my-post \
70
+ --search-engine-title "SEO title" \
71
+ --search-engine-description "SEO description"
72
+ ```
73
+
74
+ Creation and publishing are intentionally separate. Use the returned draft ID
75
+ when the draft is ready:
76
+
77
+ ```bash
78
+ substack drafts create post.md
79
+ substack drafts publish 12345 --no-send
80
+ ```
81
+
82
+ Check authentication, the selected publication, and subscriber count:
83
+
84
+ ```bash
85
+ substack status
86
+ ```
87
+
88
+ List available publications or target one without changing `.env`:
89
+
90
+ ```bash
91
+ substack publications list
92
+ substack --publication-url https://example.substack.com drafts list
93
+ ```
94
+
95
+ List and inspect drafts:
96
+
97
+ ```bash
98
+ substack drafts list --limit 10
99
+ substack drafts get 12345
100
+ ```
101
+
102
+ Schedule with a timezone-aware ISO 8601 timestamp, or remove a schedule:
103
+
104
+ ```bash
105
+ substack drafts schedule 12345 --at 2026-08-01T09:00:00+03:00
106
+ substack drafts unschedule 12345
107
+ ```
108
+
109
+ Publishing and deletion prompt for confirmation. Use `--yes` for intentional non-interactive execution:
110
+
111
+ ```bash
112
+ substack drafts publish 12345 --no-send
113
+ substack drafts delete 12345 --yes
114
+ ```
115
+
116
+ Global options must appear before the command. `--json` returns stable envelopes containing the raw Substack responses:
117
+
118
+ ```bash
119
+ substack --json drafts list
120
+ substack --cookies cookies.json --json status
121
+ ```
122
+
46
123
  ## Quickstart
47
124
 
48
125
  ```python
@@ -78,7 +155,9 @@ print(result["draft"]["id"])
78
155
 
79
156
  `create_draft_from_markdown` creates a draft by default. It only publishes when `publish=True` is passed.
80
157
 
81
- ## CLI
158
+ ## Legacy Content Publishing CLI
159
+
160
+ The existing standalone commands remain supported for compatibility.
82
161
 
83
162
  Check authentication without creating a draft:
84
163
 
@@ -255,7 +334,7 @@ Paragraph with **bold**, *italic*, `code`, [links](https://example.com), and foo
255
334
  )
256
335
  ```
257
336
 
258
- Supported Markdown includes headings, paragraphs, bold, italic, inline code, strikethrough, links, images, linked images, image captions, code blocks, blockquotes, ordered lists, unordered lists, horizontal rules, and footnotes.
337
+ Supported Markdown includes headings, paragraphs, bold, italic, inline code, strikethrough, superscript, subscript, links, images, linked images, image captions, code blocks, blockquotes, ordered lists, unordered lists, horizontal rules, footnotes, LaTeX math, pull quotes, and callouts. See [docs/markdown.md](docs/markdown.md) for the full reference with examples.
259
338
 
260
339
  When an `Api` instance is passed to `from_markdown`, local image paths are uploaded before the draft is created:
261
340
 
@@ -336,9 +415,28 @@ pre-commit install
336
415
  pytest
337
416
  ```
338
417
 
339
- Live Substack tests are opt-in. Set `RUN_SUBSTACK_E2E=1` and configure credentials before running them.
418
+ Run the offline suite with:
419
+
420
+ ```bash
421
+ pytest -m "not live"
422
+ ```
423
+
424
+ Live Substack tests are not part of normal CI. They are opt-in and require
425
+ configured credentials:
426
+
427
+ ```bash
428
+ RUN_SUBSTACK_E2E=1 pytest -m live
429
+ ```
430
+
431
+ The CLI operations smoke tests are separately opt-in. They create, inspect, and
432
+ delete disposable drafts but never publish them:
433
+
434
+ ```bash
435
+ RUN_SUBSTACK_CLI_E2E=1 pytest -m live tests/substack/test_cli_end_to_end.py
436
+ ```
340
437
 
341
438
  Release changes are tracked in [CHANGELOG.md](CHANGELOG.md).
439
+ The maintainer release process is documented in [docs/releasing.md](docs/releasing.md).
342
440
 
343
441
  ## Disclaimer
344
442
 
@@ -1,7 +1,7 @@
1
1
  [tool.poetry]
2
2
  name = "python-substack"
3
- version = "0.1.25"
4
- description = "A Python wrapper around the Substack API."
3
+ version = "0.1.27"
4
+ description = "A Python SDK and CLI for managing Substack publications and drafts."
5
5
  authors = ["Paolo Mazza <mazzapaolo2019@gmail.com>"]
6
6
  license = "MIT"
7
7
  packages = [
@@ -14,7 +14,7 @@ readme = "README.md"
14
14
  repository = "https://github.com/ma2za/python-substack"
15
15
  homepage = "https://github.com/ma2za/python-substack"
16
16
 
17
- keywords = ["substack"]
17
+ keywords = ["substack", "substack-api", "cli", "newsletter", "publishing", "automation", "mcp"]
18
18
  classifiers = [
19
19
  "Development Status :: 3 - Alpha",
20
20
  "Intended Audience :: Developers",
@@ -39,15 +39,22 @@ requests = "^2.32.0"
39
39
  python-dotenv = "^1.2.1"
40
40
  PyYAML = "^6.0"
41
41
  markdown-it-py = "^3.0"
42
- mdit-py-plugins = "^0.4"
42
+ mdit-py-plugins = ">=0.5,<0.7"
43
43
  fastmcp = { version = "^3.1.1", optional = true }
44
44
 
45
45
  [tool.poetry.extras]
46
46
  mcp = ["fastmcp"]
47
47
 
48
48
  [tool.poetry.group.dev.dependencies]
49
+ pytest = "^9.1.1"
50
+
51
+ [tool.pytest.ini_options]
52
+ markers = [
53
+ "live: opt-in tests that call the live Substack service",
54
+ ]
49
55
 
50
56
  [tool.poetry.scripts]
57
+ substack = "substack.cli:main"
51
58
  substack-auth-check = "substack.cli:auth_check"
52
59
  substack-publish-markdown = "substack.cli:publish_markdown"
53
60
  substack-publish-yaml = "substack.cli:publish_yaml"
@@ -3,9 +3,9 @@
3
3
  __author__ = "Paolo Mazza"
4
4
  __email__ = "mazzapaolo2019@gmail.com"
5
5
  __license__ = "MIT License"
6
- __version__ = "0.1.25"
6
+ __version__ = "0.1.27"
7
7
  __url__ = "https://github.com/ma2za/python-substack"
8
8
  __download_url__ = "https://pypi.python.org/pypi/python-substack"
9
- __description__ = "A Python wrapper around the Substack API"
9
+ __description__ = "A Python SDK and CLI for managing Substack publications and drafts"
10
10
 
11
11
  from .api import Api
@@ -12,6 +12,7 @@ from datetime import datetime
12
12
  from urllib.parse import unquote, urljoin
13
13
 
14
14
  import requests
15
+ from requests.adapters import HTTPAdapter, Retry
15
16
 
16
17
  from substack.exceptions import SubstackAPIException, SubstackRequestException
17
18
 
@@ -65,6 +66,18 @@ class Api:
65
66
  logging.getLogger().setLevel(logging.DEBUG)
66
67
 
67
68
  self._session = requests.Session()
69
+ retry = Retry(
70
+ total=4,
71
+ status=4,
72
+ backoff_factor=1,
73
+ status_forcelist=(429,),
74
+ allowed_methods=frozenset({"GET", "DELETE"}),
75
+ respect_retry_after_header=True,
76
+ raise_on_status=False,
77
+ )
78
+ adapter = HTTPAdapter(max_retries=retry)
79
+ self._session.mount("http://", adapter)
80
+ self._session.mount("https://", adapter)
68
81
 
69
82
  # Load cookies from file if provided
70
83
  # Helps with Captcha errors by reusing cookies from "local" auth, then switching to running code in the cloud
@@ -346,7 +359,10 @@ class Api:
346
359
  f"{self.publication_url}/publication_launch_checklist"
347
360
  )
348
361
 
349
- return Api._handle_response(response=response)["subscriberCount"]
362
+ data = Api._handle_response(response=response)
363
+ if "subscriberCount" in data:
364
+ return data["subscriberCount"]
365
+ return len(data["subscribers"])
350
366
 
351
367
  def get_published_posts(
352
368
  self, offset=0, limit=25, order_by="post_date", order_direction="desc"
@@ -553,8 +569,8 @@ class Api:
553
569
 
554
570
  """
555
571
  response = self._session.post(
556
- f"{self.publication_url}/drafts/{draft}/schedule",
557
- json={"post_date": draft_datetime.isoformat()},
572
+ f"{self.publication_url}/drafts/{draft}/scheduled_release",
573
+ json={"trigger_at": draft_datetime.isoformat()},
558
574
  )
559
575
  return Api._handle_response(response=response)
560
576
 
@@ -567,8 +583,8 @@ class Api:
567
583
  Returns:
568
584
 
569
585
  """
570
- response = self._session.post(
571
- f"{self.publication_url}/drafts/{draft}/schedule", json={"post_date": None}
586
+ response = self._session.delete(
587
+ f"{self.publication_url}/drafts/{draft}/scheduled_release"
572
588
  )
573
589
  return Api._handle_response(response=response)
574
590