Telegraph API Python Library
This Python library provides easy-to-use functions to interact with the Telegraph API, which allows you to create, edit, and manage Telegraph posts and accounts.
Features
- Create and manage Telegraph accounts.
- Create, edit, and retrieve pages.
- Fetch page view statistics.
- Revoke access tokens.
- Easily integrate with any Python project.
Installation
You can install the required dependencies using pip. Make sure you have Python installed.
pip install Telegraph-Uploader
Usage
Below is an example of how you can use the Telegraph API with this library.
from telegraph import TelegraphAPI
# Initialize API
telegraph_api = TelegraphAPI()
# Create a new account
account = telegraph_api.create_account(short_name="TestUser", author_name="Anonymous", author_url="https://example.com")
print(f"Account created: {account}")
# Access token for future requests
access_token = account['access_token']
# Initialize API with access token
telegraph_api = TelegraphAPI(access_token)
# Create a new page
content = [{"tag": "p", "children": ["This is a sample Telegraph page created via API."]}]
page = telegraph_api.create_page(title="Sample Page", content=content, author_name="Anonymous", return_content=True)
print(f"Page created: {page}")
# Fetch the page details
fetched_page = telegraph_api.get_page(page['path'], return_content=True)
print(f"Fetched page: {fetched_page}")
Methods
Account Management
create_account(short_name, author_name=None, author_url=None): Creates a new Telegraph account.edit_account_info(short_name=None, author_name=None, author_url=None): Updates account information.get_account_info(fields=None): Retrieves account information.revoke_access_token(): Revokes the current access token and generates a new one.
Page Management
create_page(title, content, author_name=None, author_url=None, return_content=False): Creates a new Telegraph page.edit_page(path, title, content, author_name=None, author_url=None, return_content=False): Edits an existing page.get_page(path, return_content=False): Fetches details of a specific page.get_page_list(offset=0, limit=50): Retrieves a list of pages belonging to the account.
Page Statistics
get_views(path, year=None, month=None, day=None, hour=None): Gets the number of views for a Telegraph page.
Error Handling
All errors returned by the Telegraph API are handled by raising TelegraphException. For example:
from telegraph.exceptions import TelegraphException
try:
account = telegraph_api.create_account(short_name="TestUser")
except TelegraphException as e:
print(f"An error occurred: {e}")
License
This project is licensed under the MIT License.
Metadata
Release files for telegraph-uploader 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| telegraph_uploader-1.0.tar.gz | 6.6 kB | Without provenance | Details for telegraph_uploader-1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| telegraph_uploader-1.0-py3-none-any.whl | Python 3 | none | any | Details for telegraph_uploader-1.0-py3-none-any.whl |
Total release size: 18.0 kB
Release files / telegraph_uploader-1.0.tar.gz
| Download URL | telegraph_uploader-1.0.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a27c316c204b300d1b07c32f39642a78f7a3c5b1c243f7796feeb25ec301b89
|
|
BLAKE2b-256 checksum How to use checksums |
d7620952492188472e2aa2f495f6eb2b608d552d47e2083f7d42808bb16dc7ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Release files / telegraph_uploader-1.0-py3-none-any.whl
| Download URL | telegraph_uploader-1.0-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
16c1248736a655bc4047f1fffe1f9fc0d6fbcbfce367182614945c3971f6a7ad
|
|
BLAKE2b-256 checksum How to use checksums |
0407bdb7caf45e1b49bdfdf469afd7eb1ffee325291839e919e361625f3997d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Security for telegraph-uploader 1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.