Skip to main content

qodev-linkedin-api

Async Python client for LinkedIn data export API.

Installation

From PyPI (recommended)

pip install qodev-linkedin-api
# or
uv add qodev-linkedin-api

From GitHub (alternative)

uv add qodev-linkedin-api --source git+ssh://git@github.com/qodevai/linkedin-api.git

For development

git clone git@github.com:qodevai/linkedin-api.git
cd linkedin-api
make install
make install-hooks  # Set up pre-commit hooks

Quick Start

make install        # Install dependencies
make install-hooks  # Set up pre-commit hooks (recommended)
make check          # Run all quality checks
make test           # Run tests with coverage

Usage

Basic Usage

import asyncio
from linkedin import LinkedInClient

async def main():
    async with LinkedInClient() as client:
        # Get all connections
        connections = await client.get_connections()
        for conn in connections:
            print(f"{conn.first_name} {conn.last_name} - {conn.company}")

        # Get invitations (both sent and received)
        invitations = await client.get_invitations()

        # Get only outgoing invitations
        sent = await client.get_outgoing_invitations()

        # Get inbox messages
        messages = await client.get_inbox()

        # Get changelog (API changes tracking)
        changelog = await client.get_changelog()

asyncio.run(main())

Configuration

from linkedin import LinkedInClient

# Auth token from environment variable (default)
# Set LINKEDIN_AUTH_TOKEN env var
client = LinkedInClient()

# Or pass token directly
client = LinkedInClient(auth_token="your-token-here")

# Custom API version and timeout
client = LinkedInClient(
    api_version="202312",  # LinkedIn API version
    timeout=60.0,          # Request timeout in seconds
)

Error Handling

from linkedin import (
    LinkedInClient,
    AuthenticationError,
    RateLimitError,
    APIError,
)

async def fetch_with_retry():
    try:
        async with LinkedInClient() as client:
            return await client.get_connections()
    except AuthenticationError:
        print("Invalid or expired token")
    except RateLimitError as e:
        print(f"Rate limited. Retry after: {e.retry_after} seconds")
    except APIError as e:
        print(f"API error {e.status_code}: {e}")

Models

All responses are typed Pydantic models:

from linkedin import Connection, Invitation, Message, ChangeLogEntry

# Connection fields
conn: Connection
conn.url           # LinkedIn profile URL
conn.first_name
conn.last_name
conn.email         # Optional
conn.company       # Optional
conn.position      # Optional
conn.connected_on  # Date string

# Invitation fields
inv: Invitation
inv.to
inv.invitee_profile_url
inv.message        # Optional
inv.direction      # "OUTGOING" or "INCOMING"
inv.sent_at        # Date string

# Message fields
msg: Message
msg.conversation_id
msg.from_member
msg.to_member      # Optional
msg.content
msg.date           # Date string
msg.subject        # Optional
msg.folder         # Optional

# ChangeLogEntry fields
entry: ChangeLogEntry
entry.id
entry.method
entry.resource_name
entry.captured_at          # Unix timestamp (ms)
entry.processed_at         # Unix timestamp (ms)
entry.captured_datetime    # Property: datetime object
entry.processed_datetime   # Property: datetime object

Development

Available Commands

make help           # Show all available commands
make install        # Install all dependencies
make install-hooks  # Install pre-commit hooks
make check          # Run all checks (lint, format, typecheck, typos)
make test           # Run tests with coverage
make test-fast      # Run tests without coverage
make lint           # Lint code with ruff
make lint-fix       # Auto-fix lint issues
make format         # Format code with ruff
make typecheck      # Run type checking with pyright
make typos          # Check for typos
make build          # Build package (sdist + wheel)
make clean          # Clean generated files

Pre-commit Hooks

Pre-commit hooks run automatically on every commit:

make install-hooks  # Install once

Hooks include:

  • YAML/TOML/JSON validation
  • Trailing whitespace removal
  • Ruff linting and formatting
  • Typos spell checking

Running Checks Manually

# Run all checks (recommended before committing)
make check

# Or run individual checks
make lint
make format-check
make typecheck
make typos

Environment Variables

Variable Description
LINKEDIN_AUTH_TOKEN LinkedIn API auth token (required if not passed to client)

Requirements

  • Python 3.11+
  • uv (for development)

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qodev_linkedin_api-0.3.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qodev_linkedin_api-0.3.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file qodev_linkedin_api-0.3.0.tar.gz.

File metadata

  • Download URL: qodev_linkedin_api-0.3.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for qodev_linkedin_api-0.3.0.tar.gz
Algorithm Hash digest
SHA256 37239b7deb3005b3a734c8f25040ec59213c59f9a56b30c88aa9fa41df703d28
MD5 ab447c613a22639bc83f1d92ccb12cc5
BLAKE2b-256 4f23ca80605f5f10c5914fb86e47348513a3666c615885c17a0cf88f783d9a37

See more details on using hashes here.

Provenance

The following attestation bundles were made for qodev_linkedin_api-0.3.0.tar.gz:

Publisher: publish.yml on qodevai/linkedin-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qodev_linkedin_api-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for qodev_linkedin_api-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 03852138dbc9110b7a60db95ea549fff29e858174de4f3c8b1658c5a80d48608
MD5 7b5b872eb037f3f5de718f1bd9a20ce9
BLAKE2b-256 4fc8bd62e16ac5017162217c7c3628fd8d7e0cbdee56bbd1352fe3670c0d0689

See more details on using hashes here.

Provenance

The following attestation bundles were made for qodev_linkedin_api-0.3.0-py3-none-any.whl:

Publisher: publish.yml on qodevai/linkedin-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page