Working with .session and .json
The .session file is the account's authorization for code: libraries such as Telethon connect with it without any login code. The .json next to it tells you which app and device the account was created with — use those values and the account will keep looking the same.
What the .json contains
The most important fields are app_id and app_hash (the API application the account belongs to), device, sdk and app_version (the device model, operating system and app version Telegram has seen so far), lang_pack and system_lang_pack (language settings) and twoFA — the same cloud password as in 2FA.txt. When you connect with different parameters, Telegram sees a new “device” on an existing authorization; that is exactly what you want to avoid.
Connecting with Telethon
The .session files we deliver are in Telethon's format (an SQLite file). A minimal example: read the .json, pass its values to the client, connect, check who you are and disconnect. If you work with Pyrogram or another library, convert the session with a tool you trust instead of logging in again.
import json
from telethon import TelegramClientcfg = json.load(open("+573001234567.json", encoding="utf-8-sig"))
client = TelegramClient(
"+573001234567", # имя .session без расширения / file name without .session
api_id=cfg["app_id"], api_hash=cfg["app_hash"],
device_model=cfg.get("device"), system_version=cfg.get("sdk"),
app_version=cfg.get("app_version"),
system_lang_code=cfg.get("system_lang_pack", "en-US"),
)
async def main():
await client.connect()
me = await client.get_me()
print(me.id, me.phone)
await client.disconnect() # disconnect — not log_out()
client.loop.run_until_complete(main())
Rules that keep the account alive
- Never call
log_out()or terminate other sessions from code: it destroys the authorization that the files contain. - Use the .session or the tdata, not both at the same time — they are one key.
- Keep one connection per account; do not run the same .session in two scripts.
- Disconnect cleanly when the job is done.
- Mass actions in the first day — joining dozens of groups, sending many messages, adding hundreds of contacts — are the fastest way to get a new account limited. Start slowly.
Proxies
Telethon accepts a proxy through the proxy argument. A stable address, ideally in the account's country, is a sensible choice; frequent changes of IP in the first hours are not. A proxy is not required for the account to work.