CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-telegraph

Python Telegraph API wrapper for creating and managing Telegraph pages and accounts

Overview
Eval results
Files

account-management.mddocs/

Account Management

Telegraph account operations for creating, managing, and configuring Telegraph accounts. All account methods are available in both synchronous and asynchronous versions.

Capabilities

Create Account

Create a new Telegraph account with custom configuration.

def create_account(short_name: str, author_name: str = None, author_url: str = None, replace_token: bool = True) -> dict:
    """
    Create a new Telegraph account.

    Parameters:
    - short_name (str): Account name displayed to user above Edit/Publish button
    - author_name (str, optional): Default author name for new articles
    - author_url (str, optional): Default profile link for author name
    - replace_token (bool): Whether to replace current token with new account token

    Returns:
    dict: Account information including access_token and auth_url
    """

Usage example:

from telegraph import Telegraph

telegraph = Telegraph()
response = telegraph.create_account(
    short_name='my-blog',
    author_name='Jane Doe',
    author_url='https://janedoe.com'
)
print(f"Access token: {response['access_token']}")
print(f"Auth URL: {response['auth_url']}")

Edit Account Information

Update existing account information. Only provide parameters you want to change.

def edit_account_info(short_name: str = None, author_name: str = None, author_url: str = None) -> dict:
    """
    Update Telegraph account information.

    Parameters:
    - short_name (str, optional): New account name
    - author_name (str, optional): New default author name
    - author_url (str, optional): New default profile link

    Returns:
    dict: Updated account information
    """

Usage example:

telegraph = Telegraph(access_token='your_token')
response = telegraph.edit_account_info(
    author_name='Jane Smith',
    author_url='https://janesmith.com'
)

Get Account Information

Retrieve current account information and statistics.

def get_account_info(fields: list = None) -> dict:
    """
    Get Telegraph account information.

    Parameters:
    - fields (list, optional): Specific fields to return. Available fields:
      'short_name', 'author_name', 'author_url', 'auth_url', 'page_count'
      Default: ['short_name', 'author_name', 'author_url']

    Returns:
    dict: Account information with requested fields
    """

Usage example:

telegraph = Telegraph(access_token='your_token')

# Get default fields
info = telegraph.get_account_info()

# Get all available fields
full_info = telegraph.get_account_info([
    'short_name', 'author_name', 'author_url', 'auth_url', 'page_count'
])
print(f"Total pages: {full_info['page_count']}")

Access Token Management

Manage account access tokens for authentication.

def get_access_token() -> str:
    """
    Get current access token.

    Returns:
    str: Current access token or None if not set
    """

def revoke_access_token() -> dict:
    """
    Revoke current access token and generate a new one.

    Returns:
    dict: New access_token and auth_url
    """

Usage example:

telegraph = Telegraph(access_token='old_token')

# Check current token
current_token = telegraph.get_access_token()

# Revoke and get new token
response = telegraph.revoke_access_token()
new_token = response['access_token']
print(f"New token: {new_token}")

Error Handling

Account operations may raise the following exceptions:

  • TelegraphException: General API errors (invalid parameters, API failures)
  • RetryAfterError: Rate limiting errors with retry_after seconds
from telegraph import Telegraph
from telegraph.exceptions import TelegraphException, RetryAfterError

telegraph = Telegraph()

try:
    response = telegraph.create_account(short_name='test')
except RetryAfterError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except TelegraphException as e:
    print(f"API error: {e}")

Install with Tessl CLI

npx tessl i tessl/pypi-telegraph

docs

account-management.md

async-api.md

file-upload.md

html-utilities.md

index.md

low-level-api.md

page-operations.md

tile.json