Skip to main content

Telethon SQLAlchemy session

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 sqlalchemy-telethon-session 0.0.1

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

Source distribution (sdist)

Source distribution for sqlalchemy-telethon-session 0.0.1
File Size Uploaded Provenance
sqlalchemy_telethon_session-0.0.1.tar.gz 8.4 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 18.2 kB

Release files / sqlalchemy_telethon_session-0.0.1.tar.gz

Download URL sqlalchemy_telethon_session-0.0.1.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
77bd603cd00dcb0c887eeffe41f89268446f04052bc58ec639d353bad4d97545
BLAKE2b-256 checksum
How to use checksums
97424e2be050b5210abc11d6fbe96a2717c8198979694d300ef2e2b8bb1f9051
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.10.0

Release files / sqlalchemy_telethon_session-0.0.1-py3-none-any.whl

Download URL sqlalchemy_telethon_session-0.0.1-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90bbae4336e53c20a69e112bf160f56dcfadb02061d473dc53164a6be3239701
BLAKE2b-256 checksum
How to use checksums
3b676c26133eafbb99d1371988e4c4732d18856ce4c210740d316a2f239d1a75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.10.0

Security for sqlalchemy-telethon-session 0.0.1

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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

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