Python
API reference
Complete client API, methods, and return types.
TeleGlanceClient
The main client class for all operations.
Python
client = TeleGlanceClient(
base_url="https://t.me", # Base URL for requests
rate_limit=1.0, # Seconds between requests
retries=3, # Retry attempts on failure
timeout=15.0, # Request timeout in seconds
proxy=None, # SOCKS5 proxy URL
headers=None, # Custom HTTP headers
registry=None, # Custom parser registry
selectors=None, # Custom CSS selectors
strict_parsing=False, # Raise on parse warnings
)get_channel
Fetch channel metadata including title, description, and subscriber count.
Python
channel = await client.get_channel("telegram")
print(channel.name) # Channel username
print(channel.title) # Display title
print(channel.description) # Channel description (if available)
print(channel.counts.subscribers) # Subscriber count
print(channel.photo_url) # Profile photo URL (if available)get_message
Fetch a single message by ID.
Python
message = await client.get_message("telegram", 12345)
print(message.id) # Message ID
print(message.text) # Text content
print(message.date) # Posted timestamp
print(message.views) # View count
print(message.media) # Media attachments (if any)get_messages
Fetch a page of messages. Returns newest-first by default.
Python
# Get latest messages
messages = await client.get_messages("telegram", limit=20)
# Paginate backwards
older = await client.get_messages("telegram", limit=20, before=messages[-1].id)
# Get newer messages (forward pagination)
newer = await client.get_messages("telegram", limit=20, after=oldest_id)iter_messages
Async iterator for history pagination. Automatically fetches pages.
Python
async for message in client.iter_messages("telegram", limit=100):
print(message.id, message.text)
# With before cursor
async for message in client.iter_messages("telegram", limit=50, before=message_id):
process(message)iter_new_messages
Iterate forward in time from a given message ID (oldest-first).
Python
# Get all messages after ID 12345
async for message in client.iter_new_messages("telegram", after=12345):
print(f"New: {message.id}")search
Search for messages matching a query string.
Python
# Simple search
results = await client.search("telegram", "python", limit=20)
# Async iteration
async for message in client.search("telegram", "release notes", limit=100):
print(message.url)watch
Poll for new messages in real-time. See Live watching page for details.
Python
async for message in client.watch("telegram", interval=30.0):
print(f"New post: {message.id}")Models
All models are Pydantic objects with type validation and serialization.
Python
from teleglance import Channel, Message, Media
# Serialize to dict
data = message.model_dump()
# Serialize to JSON
json_str = message.model_dump_json()
# Access nested fields
if message.media:
for item in message.media:
print(item.type, item.url)