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]

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). Large content is split at ~40KB 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.

Limits

  • 100MB max file size
  • 100 pages max (~4M 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.0.tar.gz (25.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.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: telepress-0.1.0.tar.gz
  • Upload date:
  • Size: 25.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.0.tar.gz
Algorithm Hash digest
SHA256 fa25edec4086dc36aa367d2050f9808ca07f113f6a9e484be3cd4e23a8a3fa7a
MD5 bdd13803f21b8fe25cb5004146b59cc2
BLAKE2b-256 e0eaaff977b68b318e2ce35885bf9444b5b923a72670cc0cba1423e9dc299362

See more details on using hashes here.

File details

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

File metadata

  • Download URL: telepress-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1a2b33a1eec83c20303dd6e09c8381d528f1a6fc1af5fac02e954f9d9b4b6fbf
MD5 a04334a3f65e5cf38ec5296aa2fb0f43
BLAKE2b-256 9c3cb18e7e4dd51ccd5c63919e0c1e994b5721224a6375aec285f015ca9edb83

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