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 AsyncPararamio
from pararamio_aio import AsyncFileCookieManager
async def main():
# Initialize cookie manager for persistent authentication
cookie_manager = AsyncFileCookieManager("session.cookie")
# Initialize client
async with AsyncPararamio(
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())
Manual Session Management
If you prefer not to use context managers, you can use connect() and close() methods for manual session management:
import asyncio
from pararamio_aio import AsyncPararamio
async def main():
client = AsyncPararamio(
login="your_login",
password="your_password",
key="your_2fa_key"
)
# Connect and initialize session
await client.connect()
try:
# Work with API
profile = await client.get_profile()
print(profile)
users = await client.search_users("friend")
for user in users:
print(user.name)
finally:
# Always close to save cookies and release resources
await client.close()
# Session can be reconnected after close
await client.connect()
profile = await client.get_profile()
await client.close()
asyncio.run(main())
Note: The
connect()method initializes the session, loads cookies, and checks authentication. Theclose()method saves cookies and closes the HTTP session.
Explicit Loading
Unlike the sync version, pararamio-aio uses explicit loading for predictable async behavior:
from pararamio_aio import AsyncPararamio
async def main():
# Get user object
client = AsyncPararamio(
login="user",
password="pass",
key="key",
)
await client.authenticate()
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
# Run the async function
import asyncio
asyncio.run(main())
Cookie Management
The async client supports multiple cookie storage options:
Default (In-Memory)
from pararamio_aio import AsyncPararamio
async def main():
# By default, uses AsyncInMemoryCookieManager (no persistence)
async with AsyncPararamio(
login="user",
password="pass",
key="key"
) as client:
await client.authenticate()
# Cookies are stored in memory only during the session
# Run the async function
import asyncio
asyncio.run(main())
File-based Persistence
from pararamio_aio import AsyncFileCookieManager, AsyncPararamio
async def main():
# Create a cookie manager for persistent storage
cookie_manager = AsyncFileCookieManager("session.cookie")
# First run - authenticates with credentials
async with AsyncPararamio(
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 AsyncPararamio(cookie_manager=cookie_manager2) as client:
# Already authenticated!
profile = await client.get_profile()
# Run the async function
import asyncio
asyncio.run(main())
Concurrent Operations
Take advantage of async for concurrent operations:
import asyncio
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 a 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 a message
-
Post- Message/postload()- Load post contentdelete()- Delete post
-
Group- Community groupload()- Load group detailsmembers- Get member list (property)
Error Handling
from pararamio_aio import AsyncPararamio
from pararamio_aio.exceptions import PararamioAuthenticationError, PararamioHTTPRequestError
async def main():
async with AsyncPararamio(login="user", password="pass", key="key") as client:
try:
await client.authenticate()
except PararamioAuthenticationError as e:
print(f"Authentication failed: {e}")
except PararamioHTTPRequestError as e:
print(f"HTTP error {e.code}: {e.message}")
# Run the async function
import asyncio
asyncio.run(main())
Advanced Usage
Custom Session
import httpx
from pararamio_aio import AsyncPararamio
async def main():
# Create custom httpx client with specific timeout and limits
timeout = httpx.Timeout(timeout=60.0, connect=10.0)
limits = httpx.Limits(max_keepalive_connections=5, max_connections=100)
async with httpx.AsyncClient(timeout=timeout, limits=limits) as session:
async with AsyncPararamio(session=session, login="user", password="pass", key="key") as client:
# Client will use your custom session
await client.authenticate()
# Perform operations
user = await client.get_user_by_id(123)
await user.load()
# Run the async function
import asyncio
asyncio.run(main())
Rate Limiting
The client automatically handles rate limiting:
from pararamio_aio import AsyncPararamio
client = AsyncPararamio(
login="user",
password="pass",
key="key",
wait_auth_limit=True, # Wait instead of failing on rate limit
)
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:
from pararamio import Pararamio
from pararamio_aio import AsyncPararamio
async def main():
# Sync version
client = Pararamio()
user = client.get_user_by_id(123)
print(user.bio) # Lazy loaded
# Async version
async with AsyncPararamio(login="user", password="pass", key="key") as client:
user = await client.get_user_by_id(123)
await user.load() # Explicit load
print(user.bio)
# Run the async function
import asyncio
asyncio.run(main())
License
MIT License—see LICENSE file for details.
Metadata
Release files for pararamio-aio 3.0.37
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 |
|---|---|---|---|---|
| pararamio_aio-3.0.37.tar.gz | 122.1 kB | Without provenance | Details for pararamio_aio-3.0.37.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pararamio_aio-3.0.37-py3-none-any.whl | Python 3 | none | any | Details for pararamio_aio-3.0.37-py3-none-any.whl |
Total release size: 295.9 kB
Release files / pararamio_aio-3.0.37.tar.gz
| Download URL | pararamio_aio-3.0.37.tar.gz |
|---|---|
| Size | 122.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
57bfc8288ae002f2e9a30066448c1eaa0a070f87a0f2db036dc326d5f80a2f8c
|
|
BLAKE2b-256 checksum How to use checksums |
8736af8eafa1a38f8283cfc19ab417b53469fd8fbbc380e54cade737db2b6cfd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.14
|
Release files / pararamio_aio-3.0.37-py3-none-any.whl
| Download URL | pararamio_aio-3.0.37-py3-none-any.whl |
|---|---|
| Size | 173.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
69a0621d6ef07516e2939f9b10d8382ec6d8b94d08dfbcf2434e548304a74275
|
|
BLAKE2b-256 checksum How to use checksums |
52d179514aab721cac30d9a1f09f96a5f0eb7a2ad3c09dad0dc451c5b7e65495
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.14
|
Security for pararamio-aio 3.0.37
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.