Skip to main content

Publish Markdown, images and zip archives to Telegraph

Project description

TelePress

中文文档

Publish Markdown, images and zip archives to Telegraph. Handles large files by auto-splitting into multiple linked pages.

Install

pip install telepress

# with REST API
pip install telepress[api]

# from source
git clone https://github.com/zoidberg-xgd/telepress
cd telepress && pip install -e .

Usage

from telepress import publish, publish_text

url = publish("article.md")
url = publish_text("# Hello\n\nWorld!", title="Test")

CLI:

telepress article.md --title "My Post"
telepress photos.zip --title "Album"

REST API:

telepress-server --port 8000

curl -X POST localhost:8000/publish/text \
  -H "Content-Type: application/json" \
  -d '{"content": "# Title\n\nBody", "title": "Test"}'

How it works

Text files are converted to Telegraph format (Markdown supported). Plain text files preserve line breaks as paragraphs. Large content is split at ~10KB boundaries into multiple pages with prev/next navigation.

Zip files are treated as image galleries. Images are sorted naturally (1, 2, 10 not 1, 10, 2) and paginated at 100 per page.

Token is auto-created on first run and saved to ~/.telegraph_token.

Features

  • Deduplication: Same content won't be uploaded twice (cache in ~/.telepress_cache.json)
  • Auto retry: Handles Telegraph rate limits automatically
  • Paragraph preservation: Plain text line breaks become paragraphs

Limits

  • 100MB max file size
  • 100 pages max (~1M chars text, or 5000 images)
  • 5MB per image (Telegraph limit)

Supported: .txt .md .markdown .rst .jpg .png .gif .webp .zip

Not supported: PDF, DOCX (convert first)

Project structure

telepress/
├── core.py       # TelegraphPublisher
├── auth.py       # token management
├── converter.py  # markdown to telegraph nodes
├── uploader.py   # image upload with retry
├── server.py     # FastAPI service
└── cli.py        # command line

Error handling

from telepress import publish, ValidationError, TelePressError

try:
    url = publish("file.md")
except ValidationError as e:
    # bad input: wrong format, too large, etc
    print(e)
except TelePressError as e:
    # other errors: upload failed, auth failed, etc
    print(e)

Integration

# Flask
@app.route('/publish', methods=['POST'])
def api_publish():
    url = publish_text(request.json['content'], title=request.json['title'])
    return {'url': url}

# async
async def async_publish(content, title):
    return await asyncio.to_thread(publish_text, content, title)

Dev

git clone https://github.com/zoidberg-xgd/telepress
cd telepress && pip install -e .[dev]
pytest tests/ -v

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telepress-0.1.1.tar.gz (29.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

telepress-0.1.1-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file telepress-0.1.1.tar.gz.

File metadata

  • Download URL: telepress-0.1.1.tar.gz
  • Upload date:
  • Size: 29.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.16

File hashes

Hashes for telepress-0.1.1.tar.gz
Algorithm Hash digest
SHA256 038545d162dcc22e5a7da74cdc540b44cc32a05415cfa89b27d7c531eec7271f
MD5 2d5f1cc78a32463144ad587397dee59c
BLAKE2b-256 39b21428fab7040999caa7bbe27516e5ae3a14454acc0c2c917753b4b838ddcd

See more details on using hashes here.

File details

Details for the file telepress-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: telepress-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.16

File hashes

Hashes for telepress-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7eda540f632ddbdcb1af34ffa679bb195f7a79795203a3eed4ee6817074635e7
MD5 09a4d3b1203044f12ccd390be2c555e7
BLAKE2b-256 a102bd71855e399493e92b4b7e9c73d79eb4df3dfdfc101a0e3ce5d06faf5780

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page