Async Python client library for pararam.io platform
Project description
Pararamio AIO
Async Python API client for pararam.io platform.
Features
- ⚡ Async/Await: Modern asynchronous interface with aiohttp
- 🚀 Explicit Loading: Predictable API calls with explicit
load()methods - 🍪 Cookie Persistence: Automatic session management
- 🔐 Two-Factor Authentication: Built-in 2FA support
- 🐍 Type Hints: Full typing support for better IDE experience
Installation
pip install pararamio-aio
Quick Start
import asyncio
from pararamio_aio import PararamioAIO, User, Chat, Post
from pararamio_core import AsyncFileCookieManager
async def main():
# Initialize cookie manager for persistent authentication
cookie_manager = AsyncFileCookieManager("session.cookie")
# Initialize client
async with PararamioAIO(
login="your_login",
password="your_password",
key="your_2fa_key",
cookie_manager=cookie_manager
) as client:
# Authenticate
await client.authenticate()
# Search for users - returns User objects (clean names!)
users = await client.search_users("John")
for user in users:
print(f"{user.name}")
# Get chat messages - returns Chat and Post objects
chat = await client.get_chat_by_id(12345)
posts = await chat.get_posts(limit=10)
for post in posts:
await post.load() # Explicit loading
print(f"{post.author.name}: {post.text}")
asyncio.run(main())
Explicit Loading
Unlike the sync version, pararamio-aio uses explicit loading for predictable async behavior:
# Get user object
user = await client.get_user_by_id(123)
print(user.name) # Basic data is already loaded
# Load full profile data explicitly
await user.load()
print(user.bio) # Now additional data is available
# Load specific relations
posts = await user.get_posts()
for post in posts:
await post.load() # Load each post's content
Cookie Management
The async client supports multiple cookie storage options:
Default (In-Memory)
# By default, uses AsyncInMemoryCookieManager (no persistence)
async with PararamioAIO(
login="user",
password="pass",
key="key"
) as client:
await client.authenticate()
# Cookies are stored in memory only during the session
File-based Persistence
from pararamio_core import AsyncFileCookieManager
# Create a cookie manager for persistent storage
cookie_manager = AsyncFileCookieManager("session.cookie")
# First run - authenticates with credentials
async with PararamioAIO(
login="user",
password="pass",
key="key",
cookie_manager=cookie_manager
) as client:
await client.authenticate()
# Later runs - uses saved cookie
cookie_manager2 = AsyncFileCookieManager("session.cookie")
async with PararamioAIO(cookie_manager=cookie_manager2) as client:
# Already authenticated!
profile = await client.get_profile()
Concurrent Operations
Take advantage of async for concurrent operations:
async def get_multiple_users(client, user_ids):
# Fetch all users concurrently
tasks = [client.get_user_by_id(uid) for uid in user_ids]
users = await asyncio.gather(*tasks)
# Load all profiles concurrently
await asyncio.gather(*[user.load() for user in users])
return users
API Reference
Client Methods
All methods are async and must be awaited:
authenticate()- Authenticate with the APIsearch_users(query)- Search for usersget_user_by_id(user_id)- Get user by IDget_users_by_ids(ids)- Get multiple usersget_chat_by_id(chat_id)- Get chat by IDsearch_groups(query)- Search for groupscreate_chat(title, description)- Create new chat
Model Objects
All models have async methods:
-
User- User profileload()- Load full profileget_posts()- Get user's postsget_groups()- Get user's groups
-
Chat- Chat/conversationload()- Load chat detailsget_posts(limit, offset)- Get messagessend_message(text)- Send message
-
Post- Message/postload()- Load post contentdelete()- Delete post
-
Group- Community groupload()- Load group detailsget_members()- Get member list
Error Handling
from pararamio_aio import (
PararamioAuthenticationException,
PararamioHTTPRequestException
)
async with PararamioAIO(**credentials) as client:
try:
await client.authenticate()
except PararamioAuthenticationException as e:
print(f"Authentication failed: {e}")
except PararamioHTTPRequestException as e:
print(f"HTTP error {e.code}: {e.message}")
Advanced Usage
Custom Session
import aiohttp
# Create custom session with specific timeout
timeout = aiohttp.ClientTimeout(total=60)
connector = aiohttp.TCPConnector(limit=100)
session = aiohttp.ClientSession(timeout=timeout, connector=connector)
async with PararamioAIO(session=session, **credentials) as client:
# Client will use your custom session
await client.authenticate()
Rate Limiting
The client automatically handles rate limiting:
client = PararamioAIO(
wait_auth_limit=True, # Wait instead of failing on rate limit
**credentials
)
Migration from Sync Version
If you're migrating from the synchronous pararamio package:
- Add
async/awaitkeywords - Use async context manager (
async with) - Call
load()explicitly when needed - Use
asyncio.gather()for concurrent operations
Example migration:
# Sync version
client = Pararamio(**creds)
user = client.get_user_by_id(123)
print(user.bio) # Lazy loaded
# Async version
async with PararamioAIO(**creds) as client:
user = await client.get_user_by_id(123)
await user.load() # Explicit load
print(user.bio)
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pararamio_aio-2.1.1.tar.gz.
File metadata
- Download URL: pararamio_aio-2.1.1.tar.gz
- Upload date:
- Size: 68.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c12d7ef0862c95d7e6a57f57a00e441e46764cc48df2b179f89eaaf0ca80c6c
|
|
| MD5 |
d4e5cceb3ca2aa9c2bc976d793df775d
|
|
| BLAKE2b-256 |
c3d0f2e0c47bc9ae0560b0a827f1093b6f4796595bde3251e497aa8d692cff3e
|
File details
Details for the file pararamio_aio-2.1.1-py3-none-any.whl.
File metadata
- Download URL: pararamio_aio-2.1.1-py3-none-any.whl
- Upload date:
- Size: 87.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32fd6d2b93bb72c978646eb319ae51d1206a4c58305e77079277f3f2f4883ecd
|
|
| MD5 |
e5a9ce1c95c91e3996b71724a42bc8e2
|
|
| BLAKE2b-256 |
2f4e52b78df4cae6d39cdc50cdc932d14dc161eae67bc8c3914a4306316c6079
|