Overview
MadelineProto provides theAPI class as the main entry point for interacting with Telegram’s MTProto protocol. The client handles session management, serialization, and IPC server initialization automatically.
Basic Initialization
The simplest way to create a client is by instantiating theAPI class with a session name:
session.madeline that stores authentication data and other state information.
Configuration with Settings
For production applications, you should configure the client with custom settings:You can obtain API credentials from my.telegram.org.
Session Management
MadelineProto automatically:- Serializes the session to disk after changes
- Locks the session file to prevent concurrent access
- Supports IPC for running multiple processes
Session Paths
The session parameter can be:- A simple filename:
'bot.madeline' - An absolute path:
'/var/lib/telegram/session.madeline' - A directory path (session will be created inside)
API Class Reference
Constants
Current version:
'8.6.4'Login state: Not logged in (value:
0)Login state: Waiting for login code (value:
1)Login state: Waiting for 2FA password (value:
2)Login state: Successfully logged in (value:
3)Login state: Logged out (value:
4)Peer Type Constants
Advanced Settings
Database Backend
Configure database storage for improved performance and reduced memory usage:Logger Configuration
Connection Settings
IPC Mode
MadelineProto can run in two modes:- IPC Client Mode: Connects to an existing MadelineProto instance
- Full Mode: Runs the complete MTProto implementation
Forcing Full Mode
Constructor Parameters
Session file path or name
Configuration settings for the client
Next Steps
Login Methods
Learn how to authenticate as a bot or user
Event Handlers
Set up event handlers to receive updates