How yashdharme/linkedin-api works
Project Type and Purpose
• This is an open-source Python client library (“linkedin_api”) that provides a direct HTTP interface to LinkedIn’s internal “Voyager” endpoints.
• It is not a web application or microservice; it’s a reusable SDK that you install via pip or poetry.
Top-Level Components (from file structure and README)
a. linkedin_api package
• client.py – wraps HTTP logic, builds/sends requests
• linkedin.py – high-level Linkedin class exposing API methods
• cookie_repository.py – abstraction over cookie persistence (load/save auth cookies)
• settings.py – loads .env or configuration (credentials, endpoints)
• utils/helpers.py – low-level helpers (header builders, query decorators)
b. External Dependencies
• LinkedIn Voyager REST-li HTTP endpoints (external system)
• Python HTTP library (e.g., requests or httpx)
• .env file (credentials)
c. Development & CI
• tests/unit & tests/e2e – test suites invoking library, mocking or real LinkedIn requests
• GitHub Actions (ci.yml) – lint, build, test pipeline
• ReadTheDocs (docs) – documentation site, Sphinx config
Relationships and Data Flows
• A user application imports linkedin_api.Linkedin, instantiates it with credentials.
• The Linkedin class calls into cookie_repository to retrieve or refresh session cookies.
• client.py constructs REST-li requests (URL, headers, cookies) and sends them to LinkedIn’s Voyager endpoints.
• Responses (JSON) flow back into client.py, parsed by utils/helpers, and returned to user code.
• Unit tests mock HTTP calls; E2E tests perform real requests against LinkedIn.
• CI pipeline runs tests and, on merge, publishes docs to ReadTheDocs.
Architectural Patterns & Design Principles
• Separation of Concerns:
• settings.py isolates configuration
• cookie_repository.py isolates authentication/cookie logic
• client.py isolates HTTP transport
• linkedin.py exposes high-level domain methods
• Dependency Injection: Linkedin class can accept custom cookie repos or HTTP client for testing.
• Single Responsibility & Extensibility: helpers folder allows adding new utilities without cluttering core modules.
Elements
• Core Library (light blue): settings, cookie repository, client, high-level interface, utils.
• External System (green): LinkedIn Voyager API, HTTP transport layer.
• Dev Infrastructure (orange): tests, GitHub Actions, ReadTheDocs.
• App → Linkedin Interface → Cookie Repo → HTTP Client → LinkedIn Voyager
• HTTP Response → Client → Helpers → Linkedin Interface → App
• Tests → Core Library (unit tests mock HTTP; E2E tests → real HTTP)
• GitHub Actions → run tests & deploy docs
[Dev Infrastructure] — [Core Library] — [External System]
b. Inside Core Library zone, stack vertically:
• settings.py (.env loader)
• cookie_repository.py
• client.py
• linkedin.py (public interface)
• utils/helpers.py
c. Connect:
• settings → linkedin.py (provides credentials & endpoints)
• linkedin.py → cookie_repository (get/set cookies)
• linkedin.py → client (call HTTP methods)
• client ↔ Voyager API (HTTP)
• client → utils/helpers (parsing & header/URL assembly)
• tests → all Core components (unit vs E2E)
• GitHub Actions → run tests → publish docs → ReadTheDocs