Skip to main content

A Telethon session storage implementation backed by SQLAlchemy.

Installation

telethon-session-sqlalchemy @ PyPI

pip install telethon-session-sqlalchemy

Usage

This session implementation can store multiple Sessions in the same database, but to do this, each session instance needs to have access to the same models and database session.

To get started, you need to create an AlchemySessionContainer which will contain that shared data. The simplest way to use AlchemySessionContainer is to simply pass it the database URL:

from alchemysession import AlchemySessionContainer
container = AlchemySessionContainer('postgres://user:pass@localhost/telethon')

If you already have SQLAlchemy set up for your own project, you can also pass the engine separately:

my_sqlalchemy_engine = sqlalchemy.create_engine('...')
container = AlchemySessionContainer(engine=my_sqlalchemy_engine)

By default, the session container will manage table creation/schema updates/etc automatically. If you want to manage everything yourself, you can pass your SQLAlchemy Session and declarative_base instances and set manage_tables to False:

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import orm
import sqlalchemy
...
session_factory = orm.sessionmaker(bind=my_sqlalchemy_engine)
session = session_factory()
my_base = declarative_base()
...
container = AlchemySessionContainer(
    session=session, table_base=my_base, manage_tables=False
)

You always need to provide either engine or session to the container. If you set manage_tables=False and provide a session, engine is not needed. In any other case, engine is always required.

After you have your AlchemySessionContainer instance created, you can create new sessions by calling new_session:

session = container.new_session('some session id')
client = TelegramClient(session)

where some session id is an unique identifier for the session.

Metadata

Release files for telethon-session-sqlalchemy 0.2.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for telethon-session-sqlalchemy 0.2.16
File Size Uploaded
telethon-session-sqlalchemy-0.2.16.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for telethon-session-sqlalchemy 0.2.16
File Interpreter ABI Platform
telethon_session_sqlalchemy-0.2.16-py3-none-any.whl Python 3 none any Details

Total release size: 20.4 kB

Release files / telethon-session-sqlalchemy-0.2.16.tar.gz

Download URL telethon-session-sqlalchemy-0.2.16.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f847c57302a102eb88e29ed95b8f4efa69582db2966fd806c21376b9a66ad4a8
BLAKE2b-256 checksum
How to use checksums
d1bb1522ed4df397e95c50b3e745512516450ef04ad5d168c724cb3e6254a663
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/49.6.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

Release files / telethon_session_sqlalchemy-0.2.16-py3-none-any.whl

Download URL telethon_session_sqlalchemy-0.2.16-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2703968f4457232790c6411256ab9652ba991fc8647cd470cd099c41783a2795
BLAKE2b-256 checksum
How to use checksums
15e95ba3be59ecabcc3a22a79b467317ac132b643cb824e6498afc72c32a0a5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/49.6.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.2.16 This release

2 release files

0.2.15

2 release files

0.2.14

2 release files

0.2.13

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page