Registry / http-networking / telegraph

telegraph

JSON →
library2.2.0pypypi✓ verified 85d ago

The `telegraph` library is a Python wrapper for the Telegraph publishing platform API, allowing programmatic creation and management of Telegraph pages and accounts. It supports both synchronous and asynchronous operations. The current version is 2.2.0, with releases occurring every few months for new features and bug fixes.

pip install telegraph
INSTALL
IMPORT
SIG · TELEGRAPH
T
telegraph
http-networkingpythonv2.2.0
Install
2.0s avg
Import
617ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.649s · 21.3MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.0s · import 0.584s · 22MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Telegraph (sync client)
from telegraph import Telegraph
Telegraph (async client)
from telegraph.aio import Telegraph
from telegraph import Telegraph as AsyncTelegraph
Async client moved to `telegraph.aio` module for clarity and to avoid name clashes.
exceptions
from telegraph.exceptions import RetryAfterError

Initializes the Telegraph client, creates a new account if no access token is provided (or uses an existing one), and then publishes a simple page. Ensure `TELEGRAPH_ACCESS_TOKEN` is set as an environment variable to reuse an existing token.

import os from telegraph import Telegraph # Create a Telegraph instance (can reuse existing access_token if available) # For a fresh start, omit access_token to create a new one. access_token = os.environ.get('TELEGRAPH_ACCESS_TOKEN', None) telegraph = Telegraph(access_token=access_token) if not telegraph.get_access_token(): # If no access token is set, create a new account account_info = telegraph.create_account( short_name='MyTestAccount', author_name='Test User', author_url='https://example.com' ) telegraph.access_token = account_info['access_token'] print(f"New Telegraph account created. Access Token: {telegraph.access_token}") else: print(f"Using existing Telegraph account with Access Token: {telegraph.access_token}") # Create a new Telegraph page response = telegraph.create_page( title='My First Telegraph Page', author_name='Test User', content='<p>Hello from <b>Python</b>!</p><p>This is a test page created programmatically.</p>', return_content=True ) print(f"Page created: {response['url']}") print(f"Page views: {response['views']}")
Debug
Known issues
breakingPython 2.x is no longer supported. Version 2.0.0 and above require Python 3.
fix
Upgrade your Python environment to Python 3.6+ to use `telegraph` versions 2.0.0 or later.
affects: >=2.0.0
deprecatedThe standalone `telegraph.upload_file` function is deprecated.
fix
Use the `Telegraph.upload_file` *method* instead, accessible via an instantiated `Telegraph` object (e.g., `telegraph_instance.upload_file(...)`).
affects: >=2.1.0
gotchaWhen providing HTML content to `create_page`, ensure it is valid Telegraph-compatible HTML. Invalid or unsupported tags/attributes will raise `telegraph.exceptions.NotAllowedTag`.
fix
Refer to the Telegraph API documentation for a list of supported HTML tags and attributes. Use simple `p`, `h3`, `a`, `b`, `i`, `strong`, `em`, `ul`, `ol`, `li`, `br`, `img`, `iframe` for best compatibility.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'telegraph.aio'
Attempting to import the asynchronous client incorrectly or using an outdated import path.
fix
Ensure you are using `from telegraph.aio import Telegraph` for the async client. If you see this with the correct import, verify your `telegraph` library version is 2.1.0 or newer.
AttributeError: module 'telegraph' has no attribute 'upload_file'
Trying to use the old top-level `upload_file` function after version 2.1.0, where it was deprecated and moved.
fix
Instantiate a `Telegraph` object and call the `upload_file` method on it: `telegraph_instance = Telegraph(); telegraph_instance.upload_file(...)`.
telegraph.exceptions.RetryAfterError: Flood control exceeded. Retry in X seconds.
The Telegraph API rate limits requests. You've sent too many requests in a short period.
fix
Implement a retry mechanism with backoff, respecting the `retry_after` seconds provided in the exception. For example, use `asyncio.sleep` or `time.sleep`.
Upgrade
Version history
2.2.0latest on PyPI · released Oct 26, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
telegraph — pip install telegraph · libregistry