Convert Markdown to Medium's internal JSON delta protocol for programmatic publishing.
Project description
md-to-medium-deltas
Convert standard Markdown into Medium's undocumented, internal JSON "Deltas" protocol for programmatic publishing.
The Problem
Before 2025, developers could programmatically publish to Medium using their official REST API by sending standard Markdown or HTML.
Medium has since deprecated its public API and stopped issuing integration tokens. The only way to programmatically post rich content to Medium now is to reverse-engineer their internal, React-based web editor protocol, which uses a proprietary JSON "Delta" structure (POST /p/{id}/deltas).
Existing libraries only convert Medium articles to Markdown. This library does the opposite: it parses Markdown and generates exact Delta operations (with correct inline markup text offsets) to reconstruct your article in Medium's editor.
Features
- Accurate Text Offsets: Automatically calculates character-exact boundaries for inline markup (bold, italic, code).
- Rich Elements Supported:
- Headings (H1, H2, H3)
- Inline formatting (Bold, Italic, Strikethrough, Code)
- Auto-linked Hyperlinks and Markdown Links
- Blockquotes
- Code blocks
- Ordered and Unordered Lists
- Intelligent Pre-processing: Fixes edge cases with list elements and correctly drops Markdown dividers that Medium handles natively.
Installation
pip install md-to-medium-deltas
(Note: Requires Python 3.12+)
Usage
from md_to_medium_deltas import markdown_to_deltas
markdown_text = """
# My Awesome Post
This is a paragraph with **bold** and *italic* text, plus a [link](https://github.com).
- Bullet point one
- Bullet point two
```python
print("Hello World")
"""
The start_index indicates the starting delta sequence position.
Pass 1 if your request already created a title delta at index 0.
By default, strip_h1=True drops the leading # Title from the body
so it doesn't duplicate your separate Title field.
deltas = markdown_to_deltas(markdown_text, start_index=1, strip_h1=True)
import json print(json.dumps(deltas, indent=2))
This output can then be directly sent as the payload to Medium's `POST /p/{id}/deltas` internal endpoint.
## How it works
This package uses a robust two-step pipeline:
1. `python-markdown` parses the raw Markdown into compliant HTML.
2. `selectolax` traverses the HTML AST and translates DOM nodes into Medium's Delta paradigm, tracking text accumulation to emit exact inline-markup offsets.
## License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file md_to_medium_deltas-0.1.0.tar.gz.
File metadata
- Download URL: md_to_medium_deltas-0.1.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4841e334630e8496678eb68d3f73512ebde5e24c0b8bb8c229c1ab469fe7bc61
|
|
| MD5 |
6184d15953195ca08bf35d51840578c2
|
|
| BLAKE2b-256 |
ab150fd83f15c56a64a087adc541bc2041a4859a6d3a448de20a504c64750687
|
File details
Details for the file md_to_medium_deltas-0.1.0-py3-none-any.whl.
File metadata
- Download URL: md_to_medium_deltas-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f014d8c3c4c7e8fbb25eaf0359bd84ca8ce707cb3255bd04adfb2f37b6353209
|
|
| MD5 |
1d99aab7a6777696cf620aefac6e8eb3
|
|
| BLAKE2b-256 |
46a5480502961e332797c7ce1579d4f44b210bf6671cc55b228a9ee5e355d0d0
|