How diezo/ensta works
Project Type & Purpose
• Type: Open-source Python SDK / API wrapper
• Purpose: Expose Instagram Mobile (and deprecated Web) endpoints through a high-level Python interface (Mobile, Guest, Web classes).
• Key use cases: authentication, profile fetch, follow/unfollow, media upload, direct messaging.
File Structure
• Top-level package “ensta/” holds all modules.
• Core modules:
– Authentication.py, Credentials.py, PasswordEncryption.py → handle login and credential security
– SessionManager.py, WebSession.py → manage HTTP sessions, cookies, proxies
– Mobile.py, Guest.py, Web.py, Direct.py, MediaResolver.py, Utils.py → implement API endpoints
• Subfolders:
– containers/ → typed response wrappers (e.g., Profile, Post)
– parser/ → JSON→container parsers
– structures/ → domain models for individual data items
– lib/ → shared utilities (exceptions, searcher)
• Tests and CI config confirm usage of the Python “requests” library and proxy support.
README for Insights
• Confirms two main client classes: Mobile (full features) and Guest (limited). Web is deprecated.
• Highlights support for proxies, multi-stage operations (e.g., upload_id generation → media upload).
• No database or persistent storage—state is kept in in-memory SessionManager.
Main Components & Interactions
a. User Application
– Your code imports ensta.Mobile / Guest / Web.
b. Client Layer
– Mobile/Guest/Web classes expose methods (profile, follow, upload, direct, etc.).
c. Auth & Session
– Credentials + PasswordEncryption → Authentication → SessionManager initializes an HTTP session (requests.Session), applies proxies, headers, cookies.
d. Transport & Endpoint Resolution
– MediaResolver constructs URLs and payloads for each endpoint. Utils assists with parameter formatting.
e. HTTP Transport
– SessionManager uses requests library to send HTTP(S) calls to Instagram servers (Mobile API endpoints or Web endpoints).
f. Response Handling
– Raw JSON responses flow into parser/ modules (e.g., ProfileParser), which emit container classes.
– containers/ wrap related structures (from structures/) into high-level objects returned to the user.
g. Error Handling & Utilities
– ensta.lib.Exceptions catches HTTP or parsing errors. ensta.lib.Searcher helps locate items in nested data.
Architectural Patterns & Principles
• Layered architecture:
1) Client interface
2) Auth & Session management
3) Transport & resolver
4) Parsing & data modeling
• Separation of concerns: Each folder/module group has a single responsibility.
• Dependency injection: SessionManager, Credentials injected into client classes.
• Extensibility: New endpoints added via MediaResolver + matching parser + container + structure.