How thasneemshaik09/tross-linkedin-api works
Purpose and Entrypoints
A Python 3.11/3.12 FastAPI service exposing LinkedIn public-profile data as a stable JSON API. Primary runtime entrypoint is app/main.py; it serves GET/POST /api/profile, debug /api/profile/raw, and /health. Public response contracts live in app/models.py.
HTTP/API Boundary
app/main.py owns FastAPI routing, request validation, optional X-API-Key enforcement, and exception-to-HTTP response handling. It accepts a LinkedIn URL rather than a profile ID; URL normalization/extraction is isolated in app/linkedin/urls.py. Typed domain/upstream failures are defined in app/errors.py, allowing controlled 400/401/404/429/502/503 responses rather than leaked internal errors.
Profile Retrieval Orchestration
app/service.py is the application workflow boundary:
1. Parse URL to LinkedIn public ID.
2. Resolve identity and profile URN.
3. Fetch profile section resources concurrently.
4. Parse upstream entities into the public schema.
5. Return profile plus retrieval metadata.
It also provides an in-memory TTL cache, reducing repeat upstream calls and pressure on the shared LinkedIn account.
LinkedIn Voyager Integration
app/linkedin/client.py is the sole external-service adapter. Using async httpx, it calls authenticated LinkedIn private Voyager “dash” REST endpoints: identity first, then positions, education, skills, certifications, and languages keyed by the resolved profile URN. It constructs required cookies, CSRF/rest.li headers, finder query parameters, and optional proxy routing. This is a hard boundary: LinkedIn’s private payloads and auth behavior do not escape the adapter/parser layer.
Translation and Schema Stability
app/linkedin/parser.py translates Voyager normalized {data, included} payloads, discriminated by $type, into application-owned Pydantic models in app/models.py. Parsing is defensive against missing or renamed upstream fields; unavailable sections become null/empty schema values. This decouples consumers from LinkedIn’s volatile internal resource formats.
Configuration, Credentials, and Deployment
app/config.py loads environment-backed runtime settings, including LINKEDIN_LI_AT, LINKEDIN_JSESSIONID, optional API_KEY, cache settings, and PROXY_URL. LinkedIn requires an authenticated session and CSRF cookie/header pairing. Cloud deployments may require a residential/mobile egress proxy because datacenter IPs can trigger LinkedIn login/checkpoint flows. Container deployment is defined by Dockerfile; Render provisioning and health checks are defined in render.yaml.
Runtime Dependencies and Operational Constraints
The runtime is server-side only: FastAPI/Uvicorn provide HTTPS API hosting, httpx performs outbound Voyager calls, and Pydantic validates/contracts API data. There is no browser automation runtime. Upstream failure isolation is intentional: failure of an individual profile section degrades that section to empty, while identity/auth/rate-limit failures control the overall request outcome.
Main entry points: main.py FastAPI routes · service.py Profile workflow · client.py Voyager client · render.yaml Render deployment
Components 14
API service
- FastAPI routes · Serves profile, raw-debug, and health endpoints.
app/main.py - Public contracts · Stable JSON request and response schemas.
app/models.py - Typed failures · Maps domain and upstream failures to controlled HTTP responses.
app/errors.py
Application
- Profile workflow · Coordinates ID resolution, concurrent retrieval, parsing, metadata, and TTL caching.
app/service.py - LinkedIn URL parser · Extracts a public LinkedIn ID from the submitted URL.
app/linkedin/urls.py - TTL cache · Avoids repeat upstream retrieval for cached profiles.
app/service.py
LinkedIn integration
- Voyager client · Authenticated async adapter for private LinkedIn Voyager endpoints.
app/linkedin/client.py - Voyager parser · Defensively maps normalized Voyager payloads into public models.
app/linkedin/parser.py - LinkedIn Voyager · Private profile resources and authenticated session boundary.
Runtime & deployment
- Runtime settings · Loads session cookies, API key, cache, and proxy settings.
app/config.py - Optional egress proxy · Residential/mobile routing can avoid LinkedIn checkpoint flows.
- Container image
Dockerfile - Render deployment · Provisions the service and health checks.
render.yaml
Other components
- API consumer
Connections 16
- API consumer → FastAPI routes: GET/POST profile requests
- FastAPI routes → Public contracts: validates and serializes
- FastAPI routes → Profile workflow: invokes retrieval
- FastAPI routes → Typed failures: maps failures
- FastAPI routes → Runtime settings: reads API-key policy
- Profile workflow → LinkedIn URL parser: extracts public ID
- Profile workflow → TTL cache: reads and writes
- Profile workflow → Voyager client: resolves identity and fetches sections · Section requests run concurrently after URN resolution.
- Profile workflow → Voyager parser: translates resources
- Voyager parser → Public contracts: builds stable profile
- Voyager client → LinkedIn Voyager: authenticated async REST
- Voyager client → Runtime settings: uses cookies, CSRF, proxy
- Voyager client → Optional egress proxy: optional routing
- Container image → FastAPI routes: runs application
- Render deployment → Container image: deploys
- Render deployment → FastAPI routes: health checks