|
| 1 | +This official Python SDK is the synchronous way to integrate with Linked API. It provides pre-defined workflow operations, direct account/statistics methods, admin APIs, authentication headers, polling, and structured error responses. |
| 2 | + |
| 3 | +## Get started |
| 4 | + |
| 5 | +To get started with Linked API Python SDK, read these essential guides first: |
| 6 | + |
| 7 | +1. [Core concepts](https://linkedapi.io/sdks/core-concepts-0/) - understand how Linked API works. |
| 8 | +2. [Installation & authorization](https://linkedapi.io/sdks/installation-authorization/) - install the SDK and authorize it. |
| 9 | +3. [Predefined vs. custom workflows](https://linkedapi.io/sdks/predefined-vs-custom-workflows/) - choose ready-made operations or custom workflow definitions. |
| 10 | +4. [Handling results and errors](https://linkedapi.io/sdks/handling-results-and-errors/) - process successful data and action errors. |
| 11 | +5. [Persisting and cancelling workflows](https://linkedapi.io/sdks/persisting-and-cancelling-workflows/) - save, resume, and cancel workflows. |
| 12 | + |
| 13 | +Install the package: |
| 14 | + |
| 15 | +```bash |
| 16 | +pip install linkedapi |
| 17 | +``` |
| 18 | + |
| 19 | +Initialize the client: |
| 20 | + |
| 21 | +```python |
| 22 | +from linkedapi import LinkedApi, LinkedApiConfig |
| 23 | + |
| 24 | +linkedapi = LinkedApi( |
| 25 | + LinkedApiConfig( |
| 26 | + linked_api_token="your-linked-api-token", |
| 27 | + identification_token="your-identification-token", |
| 28 | + ) |
| 29 | +) |
| 30 | +``` |
| 31 | + |
| 32 | +Run a predefined workflow and poll the result: |
| 33 | + |
| 34 | +```python |
| 35 | +from linkedapi import FetchPersonParams |
| 36 | + |
| 37 | +workflow = linkedapi.fetch_person.execute( |
| 38 | + FetchPersonParams( |
| 39 | + person_url="https://www.linkedin.com/in/john-doe", |
| 40 | + retrieve_experience=True, |
| 41 | + retrieve_posts=True, |
| 42 | + posts_retrieval_config={"limit": 10}, |
| 43 | + ) |
| 44 | +) |
| 45 | + |
| 46 | +result = linkedapi.fetch_person.result(workflow.workflow_id) |
| 47 | +if result.data: |
| 48 | + print(result.data.name) |
| 49 | +for error in result.errors: |
| 50 | + print(error.type, error.message) |
| 51 | +``` |
| 52 | + |
| 53 | +Execute a custom workflow: |
| 54 | + |
| 55 | +```python |
| 56 | +workflow = linkedapi.custom_workflow.execute( |
| 57 | + { |
| 58 | + "actionType": "st.searchCompanies", |
| 59 | + "term": "Tech Inc", |
| 60 | + "filter": { |
| 61 | + "sizes": ["51-200", "2001-5000"], |
| 62 | + "locations": ["San Francisco", "New York"], |
| 63 | + "industries": ["Software Development"], |
| 64 | + }, |
| 65 | + "then": {"actionType": "st.openCompanyPage", "basicInfo": True}, |
| 66 | + } |
| 67 | +) |
| 68 | + |
| 69 | +result = linkedapi.custom_workflow.result(workflow.workflow_id) |
| 70 | +print(result.data) |
| 71 | +``` |
| 72 | + |
| 73 | +Continue polling after a workflow timeout: |
| 74 | + |
| 75 | +```python |
| 76 | +from linkedapi import LinkedApiWorkflowTimeoutError |
| 77 | + |
| 78 | +try: |
| 79 | + result = linkedapi.fetch_person.result(workflow.workflow_id, timeout=30.0) |
| 80 | +except LinkedApiWorkflowTimeoutError as error: |
| 81 | + result = linkedapi.fetch_person.result(error.workflow_id) |
| 82 | +``` |
| 83 | + |
| 84 | +Cancel a workflow: |
| 85 | + |
| 86 | +```python |
| 87 | +cancelled = linkedapi.fetch_person.cancel(workflow.workflow_id) |
| 88 | +print(cancelled) |
| 89 | +``` |
| 90 | + |
| 91 | +## License |
| 92 | + |
| 93 | +This project is licensed under the MIT License. See [LICENSE](LICENSE) for details. |
0 commit comments