Registry / http-networking / linkedin-api

linkedin-api

JSON →
library2.3.1pypypi✓ verified 85d ago

linkedin-api is an unofficial Python client for interacting with LinkedIn's internal APIs. It allows developers to programmatically access various LinkedIn features, such as profiles, connections, and company data, by simulating browser behavior. As it uses unofficial APIs, it is prone to breaking changes and requires careful usage to avoid account issues. The current version is 2.3.1, with releases occurring as needed to address LinkedIn's frequent changes.

pip install linkedin-api
INSTALL
IMPORT
SIG · LINKEDIN-API
L
linkedin-api
http-networkingpythonv2.3.1
Install
3.0s avg
Import
993ms
Disk
32MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 1.031s · 34.5MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.0s · import 0.956s · 35MB
32MB installed
● package 32MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Linkedin
from linkedin_api import Linkedin

Initialize the Linkedin API client with your username and password, then make a simple call to retrieve a user profile. It's crucial to handle credentials securely, preferably via environment variables. This library uses unofficial APIs, so methods and responses might change without notice.

import os from linkedin_api import Linkedin # It's highly recommended to use environment variables for credentials USERNAME = os.environ.get('LINKEDIN_USERNAME', 'your_email@example.com') PASSWORD = os.environ.get('LINKEDIN_PASSWORD', 'your_strong_password') if not USERNAME or not PASSWORD: print("Please set LINKEDIN_USERNAME and LINKEDIN_PASSWORD environment variables.") else: try: api = Linkedin(USERNAME, PASSWORD) # Example: Get a public profile by its LinkedIn URL or ID # Replace 'ACoAAADm-wABuE77A8WbNlQoV-xT8D12345' with an actual profile ID profile = api.get_profile('ACoAAADm-wABuE77A8WbNlQoV-xT8D12345') print(f"Successfully fetched profile for {profile.get('firstName')} {profile.get('lastName')}") # Example: Get posts from a specific person # posts = api.get_profile_posts('ACoAAADm-wABuE77A8WbNlQoV-xT8D12345') # print(f"Fetched {len(posts)} posts.") except Exception as e: print(f"An error occurred: {e}")
Debug
Known issues
breakingAs an unofficial client, 'linkedin-api' is highly susceptible to breaking changes. LinkedIn frequently updates its internal APIs, which can cause methods to fail or return unexpected data. The library maintainers strive to keep it updated, but delays are possible.
fix
Regularly update the library (`pip install --upgrade linkedin-api`) and test your code. Monitor the GitHub repository for recent commits or issue reports regarding functionality breakage.
affects: All versions
gotchaFrequent or aggressive use of the API can lead to your LinkedIn account being rate-limited, temporarily blocked, or even permanently restricted by LinkedIn's bot detection mechanisms. This includes rapid successive requests or scraping large amounts of data.
fix
Implement rate limiting and exponential backoff in your code. Use reasonable delays between requests. Consider using a session cookie for authentication if you have an active browser session, which might be less prone to detection than direct username/password login.
affects: All versions
gotchaAuthentication with username/password can be unreliable, especially if your LinkedIn account has Two-Factor Authentication (2FA) enabled or if LinkedIn suspects bot activity, leading to CAPTCHA challenges or login failures.
fix
Try disabling 2FA temporarily for programmatic access if possible, or use the `linkedin_api.Linkedin(..., cookies=...)` option to provide a session cookie from a browser. If login fails, check your LinkedIn account manually for any security challenges.
affects: All versions
Errors
Common errors & fixes
Could not login: Check your email and password.
Incorrect username or password, or LinkedIn detected suspicious activity requiring manual intervention (e.g., CAPTCHA, 2FA challenge, or account lock).
fix
Double-check your credentials. Try logging into LinkedIn manually in a browser to see if there's a security challenge. If 2FA is enabled, you might need to provide a session cookie instead of direct username/password.
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The API endpoint did not return valid JSON. This often happens if LinkedIn redirected the request to a CAPTCHA page, a 'something went wrong' page, or a block page instead of the expected data.
fix
This usually indicates your account or IP is being challenged or temporarily blocked. Wait some time, reduce request frequency, or try with a different IP/account. Check the raw response content to understand what LinkedIn actually returned.
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: ...
You have exceeded LinkedIn's rate limits, or your IP address has been temporarily throttled or blocked due to aggressive scraping behavior.
fix
Implement robust rate limiting and exponential backoff in your code. Introduce delays between API calls (e.g., `time.sleep()`). Consider distributing requests across multiple IP addresses or using a different API client if the issue persists.
Login failed, please try again later.
LinkedIn's login flow or security measures have changed (e.g., CAPTCHA, 2FA, or HTML structure), preventing the unofficial API from successfully authenticating, or your credentials are incorrect.
fix
Ensure your credentials are correct, try updating the `linkedin-api` library to the latest version (`pip install --upgrade linkedin-api`), and try manually logging into LinkedIn in a browser to check for any interactive challenges.
ModuleNotFoundError: No module named 'linkedin_api'
The `linkedin-api` Python package has not been installed in your current Python environment.
fix
Install the library using pip: `pip install linkedin-api`.
Upgrade
Version history
2.3.1latest on PyPI · released Nov 7, 2024
Audit
Dependencies
requestsrequiredUsed for making HTTP requests to LinkedIn's endpoints.
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
linkedin-api — pip install linkedin-api · libregistry