linkedapi 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. linkedapi-1.0.0/.github/workflows/publish.yaml +70 -0
  2. linkedapi-1.0.0/.gitignore +9 -0
  3. linkedapi-1.0.0/LICENSE +21 -0
  4. linkedapi-1.0.0/PKG-INFO +125 -0
  5. linkedapi-1.0.0/README.md +93 -0
  6. linkedapi-1.0.0/linkedapi/__init__.py +127 -0
  7. linkedapi-1.0.0/linkedapi/admin/__init__.py +13 -0
  8. linkedapi-1.0.0/linkedapi/admin/accounts.py +91 -0
  9. linkedapi-1.0.0/linkedapi/admin/admin.py +22 -0
  10. linkedapi-1.0.0/linkedapi/admin/http_client.py +73 -0
  11. linkedapi-1.0.0/linkedapi/admin/limits.py +70 -0
  12. linkedapi-1.0.0/linkedapi/admin/subscription.py +69 -0
  13. linkedapi-1.0.0/linkedapi/client.py +160 -0
  14. linkedapi-1.0.0/linkedapi/config.py +10 -0
  15. linkedapi-1.0.0/linkedapi/core/__init__.py +4 -0
  16. linkedapi-1.0.0/linkedapi/core/operation.py +89 -0
  17. linkedapi-1.0.0/linkedapi/core/polling.py +48 -0
  18. linkedapi-1.0.0/linkedapi/errors.py +119 -0
  19. linkedapi-1.0.0/linkedapi/http/__init__.py +4 -0
  20. linkedapi-1.0.0/linkedapi/http/base.py +22 -0
  21. linkedapi-1.0.0/linkedapi/http/linked_api_http_client.py +74 -0
  22. linkedapi-1.0.0/linkedapi/mappers/__init__.py +16 -0
  23. linkedapi-1.0.0/linkedapi/mappers/array.py +49 -0
  24. linkedapi-1.0.0/linkedapi/mappers/base.py +70 -0
  25. linkedapi-1.0.0/linkedapi/mappers/simple.py +56 -0
  26. linkedapi-1.0.0/linkedapi/mappers/then.py +175 -0
  27. linkedapi-1.0.0/linkedapi/mappers/void.py +33 -0
  28. linkedapi-1.0.0/linkedapi/operations/__init__.py +58 -0
  29. linkedapi-1.0.0/linkedapi/operations/check_connection_status.py +15 -0
  30. linkedapi-1.0.0/linkedapi/operations/comment_on_post.py +12 -0
  31. linkedapi-1.0.0/linkedapi/operations/create_post.py +15 -0
  32. linkedapi-1.0.0/linkedapi/operations/custom_workflow.py +22 -0
  33. linkedapi-1.0.0/linkedapi/operations/fetch_company.py +35 -0
  34. linkedapi-1.0.0/linkedapi/operations/fetch_person.py +43 -0
  35. linkedapi-1.0.0/linkedapi/operations/fetch_post.py +33 -0
  36. linkedapi-1.0.0/linkedapi/operations/nv_fetch_company.py +33 -0
  37. linkedapi-1.0.0/linkedapi/operations/nv_fetch_person.py +23 -0
  38. linkedapi-1.0.0/linkedapi/operations/nv_search_companies.py +15 -0
  39. linkedapi-1.0.0/linkedapi/operations/nv_search_people.py +15 -0
  40. linkedapi-1.0.0/linkedapi/operations/nv_send_message.py +12 -0
  41. linkedapi-1.0.0/linkedapi/operations/nv_sync_conversation.py +12 -0
  42. linkedapi-1.0.0/linkedapi/operations/react_to_post.py +12 -0
  43. linkedapi-1.0.0/linkedapi/operations/remove_connection.py +12 -0
  44. linkedapi-1.0.0/linkedapi/operations/retrieve_connections.py +15 -0
  45. linkedapi-1.0.0/linkedapi/operations/retrieve_pending_requests.py +15 -0
  46. linkedapi-1.0.0/linkedapi/operations/retrieve_performance.py +15 -0
  47. linkedapi-1.0.0/linkedapi/operations/retrieve_ssi.py +15 -0
  48. linkedapi-1.0.0/linkedapi/operations/search_companies.py +15 -0
  49. linkedapi-1.0.0/linkedapi/operations/search_people.py +15 -0
  50. linkedapi-1.0.0/linkedapi/operations/send_connection_request.py +12 -0
  51. linkedapi-1.0.0/linkedapi/operations/send_message.py +12 -0
  52. linkedapi-1.0.0/linkedapi/operations/sync_conversation.py +12 -0
  53. linkedapi-1.0.0/linkedapi/operations/withdraw_connection_request.py +12 -0
  54. linkedapi-1.0.0/linkedapi/py.typed +1 -0
  55. linkedapi-1.0.0/linkedapi/types/__init__.py +336 -0
  56. linkedapi-1.0.0/linkedapi/types/account.py +8 -0
  57. linkedapi-1.0.0/linkedapi/types/admin/__init__.py +91 -0
  58. linkedapi-1.0.0/linkedapi/types/admin/accounts.py +71 -0
  59. linkedapi-1.0.0/linkedapi/types/admin/config.py +8 -0
  60. linkedapi-1.0.0/linkedapi/types/admin/limits.py +77 -0
  61. linkedapi-1.0.0/linkedapi/types/admin/subscription.py +58 -0
  62. linkedapi-1.0.0/linkedapi/types/base.py +47 -0
  63. linkedapi-1.0.0/linkedapi/types/company.py +140 -0
  64. linkedapi-1.0.0/linkedapi/types/connection.py +86 -0
  65. linkedapi-1.0.0/linkedapi/types/message.py +48 -0
  66. linkedapi-1.0.0/linkedapi/types/params.py +15 -0
  67. linkedapi-1.0.0/linkedapi/types/person.py +105 -0
  68. linkedapi-1.0.0/linkedapi/types/post.py +119 -0
  69. linkedapi-1.0.0/linkedapi/types/responses.py +18 -0
  70. linkedapi-1.0.0/linkedapi/types/search_companies.py +72 -0
  71. linkedapi-1.0.0/linkedapi/types/search_people.py +46 -0
  72. linkedapi-1.0.0/linkedapi/types/statistics.py +27 -0
  73. linkedapi-1.0.0/linkedapi/types/workflow.py +55 -0
  74. linkedapi-1.0.0/pyproject.toml +65 -0
  75. linkedapi-1.0.0/tests/conftest.py +67 -0
  76. linkedapi-1.0.0/tests/test_admin.py +127 -0
  77. linkedapi-1.0.0/tests/test_direct_methods.py +96 -0
  78. linkedapi-1.0.0/tests/test_errors.py +58 -0
  79. linkedapi-1.0.0/tests/test_http_client.py +79 -0
  80. linkedapi-1.0.0/tests/test_mappers.py +151 -0
  81. linkedapi-1.0.0/tests/test_models.py +62 -0
  82. linkedapi-1.0.0/tests/test_operations.py +95 -0
  83. linkedapi-1.0.0/tests/test_polling.py +118 -0
@@ -0,0 +1,70 @@
1
+ name: PR Merged -> main
2
+
3
+ on:
4
+ push:
5
+ branches: ['main']
6
+
7
+ jobs:
8
+ quality:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - name: Checkout code
13
+ uses: actions/checkout@v4
14
+
15
+ - name: Set up Python
16
+ uses: actions/setup-python@v5
17
+ with:
18
+ python-version: '3.12'
19
+
20
+ - name: Install dependencies
21
+ run: pip install -e '.[dev]'
22
+
23
+ - name: Lint
24
+ run: ruff check .
25
+
26
+ - name: Type check
27
+ run: mypy linkedapi
28
+
29
+ - name: Test
30
+ run: pytest -q
31
+
32
+ publish:
33
+ needs: [quality]
34
+ runs-on: ubuntu-latest
35
+ environment: pypi
36
+ permissions:
37
+ id-token: write
38
+
39
+ steps:
40
+ - name: Checkout code
41
+ uses: actions/checkout@v4
42
+
43
+ - name: Set up Python
44
+ uses: actions/setup-python@v5
45
+ with:
46
+ python-version: '3.12'
47
+
48
+ - name: Check if version changed
49
+ id: version-check
50
+ run: |
51
+ PACKAGE_NAME=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['name'])")
52
+ PACKAGE_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
53
+ PYPI_VERSION=$(curl -fsSL "https://pypi.org/pypi/${PACKAGE_NAME}/json" | python -c "import json,sys; print(json.load(sys.stdin)['info']['version'])" 2>/dev/null || echo "none")
54
+ if [ "$PACKAGE_VERSION" != "$PYPI_VERSION" ]; then
55
+ echo "should_publish=true" >> "$GITHUB_OUTPUT"
56
+ echo "Version changed: $PYPI_VERSION -> $PACKAGE_VERSION"
57
+ else
58
+ echo "should_publish=false" >> "$GITHUB_OUTPUT"
59
+ echo "Version unchanged: $PACKAGE_VERSION"
60
+ fi
61
+
62
+ - name: Build distributions
63
+ if: steps.version-check.outputs.should_publish == 'true'
64
+ run: |
65
+ pip install build
66
+ python -m build
67
+
68
+ - name: Publish to PyPI
69
+ if: steps.version-check.outputs.should_publish == 'true'
70
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ dist/
4
+ *.egg-info/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ .pytest_cache/
8
+ .venv/
9
+ build/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Linked API <https://linkedapi.io>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,125 @@
1
+ Metadata-Version: 2.4
2
+ Name: linkedapi
3
+ Version: 1.0.0
4
+ Summary: Official synchronous Python SDK for Linked API.
5
+ Project-URL: Homepage, https://linkedapi.io
6
+ Project-URL: Repository, https://github.com/Linked-API/linkedapi-python
7
+ Project-URL: Documentation, https://linkedapi.io/docs/
8
+ Author: Linked API
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: api,automation,data,linkedapi,linkedin,sdk
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: pydantic<3,>=2
23
+ Requires-Dist: requests<3,>=2
24
+ Provides-Extra: dev
25
+ Requires-Dist: build; extra == 'dev'
26
+ Requires-Dist: mypy; extra == 'dev'
27
+ Requires-Dist: pytest>=8; extra == 'dev'
28
+ Requires-Dist: requests-mock>=1.12; extra == 'dev'
29
+ Requires-Dist: ruff; extra == 'dev'
30
+ Requires-Dist: types-requests; extra == 'dev'
31
+ Description-Content-Type: text/markdown
32
+
33
+ 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.
34
+
35
+ ## Get started
36
+
37
+ To get started with Linked API Python SDK, read these essential guides first:
38
+
39
+ 1. [Core concepts](https://linkedapi.io/sdks/core-concepts-0/) - understand how Linked API works.
40
+ 2. [Installation & authorization](https://linkedapi.io/sdks/installation-authorization/) - install the SDK and authorize it.
41
+ 3. [Predefined vs. custom workflows](https://linkedapi.io/sdks/predefined-vs-custom-workflows/) - choose ready-made operations or custom workflow definitions.
42
+ 4. [Handling results and errors](https://linkedapi.io/sdks/handling-results-and-errors/) - process successful data and action errors.
43
+ 5. [Persisting and cancelling workflows](https://linkedapi.io/sdks/persisting-and-cancelling-workflows/) - save, resume, and cancel workflows.
44
+
45
+ Install the package:
46
+
47
+ ```bash
48
+ pip install linkedapi
49
+ ```
50
+
51
+ Initialize the client:
52
+
53
+ ```python
54
+ from linkedapi import LinkedApi, LinkedApiConfig
55
+
56
+ linkedapi = LinkedApi(
57
+ LinkedApiConfig(
58
+ linked_api_token="your-linked-api-token",
59
+ identification_token="your-identification-token",
60
+ )
61
+ )
62
+ ```
63
+
64
+ Run a predefined workflow and poll the result:
65
+
66
+ ```python
67
+ from linkedapi import FetchPersonParams
68
+
69
+ workflow = linkedapi.fetch_person.execute(
70
+ FetchPersonParams(
71
+ person_url="https://www.linkedin.com/in/john-doe",
72
+ retrieve_experience=True,
73
+ retrieve_posts=True,
74
+ posts_retrieval_config={"limit": 10},
75
+ )
76
+ )
77
+
78
+ result = linkedapi.fetch_person.result(workflow.workflow_id)
79
+ if result.data:
80
+ print(result.data.name)
81
+ for error in result.errors:
82
+ print(error.type, error.message)
83
+ ```
84
+
85
+ Execute a custom workflow:
86
+
87
+ ```python
88
+ workflow = linkedapi.custom_workflow.execute(
89
+ {
90
+ "actionType": "st.searchCompanies",
91
+ "term": "Tech Inc",
92
+ "filter": {
93
+ "sizes": ["51-200", "2001-5000"],
94
+ "locations": ["San Francisco", "New York"],
95
+ "industries": ["Software Development"],
96
+ },
97
+ "then": {"actionType": "st.openCompanyPage", "basicInfo": True},
98
+ }
99
+ )
100
+
101
+ result = linkedapi.custom_workflow.result(workflow.workflow_id)
102
+ print(result.data)
103
+ ```
104
+
105
+ Continue polling after a workflow timeout:
106
+
107
+ ```python
108
+ from linkedapi import LinkedApiWorkflowTimeoutError
109
+
110
+ try:
111
+ result = linkedapi.fetch_person.result(workflow.workflow_id, timeout=30.0)
112
+ except LinkedApiWorkflowTimeoutError as error:
113
+ result = linkedapi.fetch_person.result(error.workflow_id)
114
+ ```
115
+
116
+ Cancel a workflow:
117
+
118
+ ```python
119
+ cancelled = linkedapi.fetch_person.cancel(workflow.workflow_id)
120
+ print(cancelled)
121
+ ```
122
+
123
+ ## License
124
+
125
+ This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,93 @@
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,0 +1,127 @@
1
+ from linkedapi.admin import (
2
+ AdminAccounts,
3
+ AdminHttpClient,
4
+ AdminLimits,
5
+ AdminSubscription,
6
+ LinkedApiAdmin,
7
+ )
8
+ from linkedapi.client import LinkedApi
9
+ from linkedapi.config import LinkedApiConfig
10
+ from linkedapi.core import Operation, poll_workflow_result
11
+ from linkedapi.errors import (
12
+ LINKED_API_ACTION_ERROR_TYPES,
13
+ LINKED_API_ERROR_TYPES,
14
+ LinkedApiActionErrorType,
15
+ LinkedApiError,
16
+ LinkedApiErrorType,
17
+ LinkedApiWorkflowTimeoutError,
18
+ )
19
+ from linkedapi.http import HttpClient, LinkedApiHttpClient
20
+ from linkedapi.mappers import (
21
+ ActionConfig,
22
+ ArrayWorkflowMapper,
23
+ BaseMapper,
24
+ MappedResponse,
25
+ ResponseMapping,
26
+ SimpleWorkflowMapper,
27
+ ThenWorkflowMapper,
28
+ VoidWorkflowMapper,
29
+ )
30
+ from linkedapi.operations import (
31
+ CheckConnectionStatus,
32
+ CommentOnPost,
33
+ CreatePost,
34
+ CustomWorkflow,
35
+ FetchCompany,
36
+ FetchCompanyMapper,
37
+ FetchPerson,
38
+ FetchPersonMapper,
39
+ FetchPost,
40
+ FetchPostMapper,
41
+ NvFetchCompany,
42
+ NvFetchCompanyMapper,
43
+ NvFetchPerson,
44
+ NvFetchPersonMapper,
45
+ NvSearchCompanies,
46
+ NvSearchPeople,
47
+ NvSendMessage,
48
+ NvSyncConversation,
49
+ ReactToPost,
50
+ RemoveConnection,
51
+ RetrieveConnections,
52
+ RetrievePendingRequests,
53
+ RetrievePerformance,
54
+ RetrieveSSI,
55
+ SearchCompanies,
56
+ SearchPeople,
57
+ SendConnectionRequest,
58
+ SendMessage,
59
+ SyncConversation,
60
+ WithdrawConnectionRequest,
61
+ )
62
+ from linkedapi.types import * # noqa: F403
63
+ from linkedapi.types import __all__ as _types_all
64
+
65
+ __version__ = "1.0.0"
66
+ PredefinedOperation = Operation
67
+
68
+ __all__ = [
69
+ *_types_all,
70
+ "AdminAccounts",
71
+ "AdminHttpClient",
72
+ "AdminLimits",
73
+ "AdminSubscription",
74
+ "ActionConfig",
75
+ "ArrayWorkflowMapper",
76
+ "BaseMapper",
77
+ "CheckConnectionStatus",
78
+ "CommentOnPost",
79
+ "CreatePost",
80
+ "CustomWorkflow",
81
+ "FetchCompany",
82
+ "FetchCompanyMapper",
83
+ "FetchPerson",
84
+ "FetchPersonMapper",
85
+ "FetchPost",
86
+ "FetchPostMapper",
87
+ "HttpClient",
88
+ "LINKED_API_ACTION_ERROR_TYPES",
89
+ "LINKED_API_ERROR_TYPES",
90
+ "LinkedApi",
91
+ "LinkedApiActionErrorType",
92
+ "LinkedApiAdmin",
93
+ "LinkedApiConfig",
94
+ "LinkedApiError",
95
+ "LinkedApiErrorType",
96
+ "LinkedApiHttpClient",
97
+ "LinkedApiWorkflowTimeoutError",
98
+ "MappedResponse",
99
+ "NvFetchCompany",
100
+ "NvFetchCompanyMapper",
101
+ "NvFetchPerson",
102
+ "NvFetchPersonMapper",
103
+ "NvSearchCompanies",
104
+ "NvSearchPeople",
105
+ "NvSendMessage",
106
+ "NvSyncConversation",
107
+ "Operation",
108
+ "PredefinedOperation",
109
+ "ReactToPost",
110
+ "RemoveConnection",
111
+ "ResponseMapping",
112
+ "RetrieveConnections",
113
+ "RetrievePendingRequests",
114
+ "RetrievePerformance",
115
+ "RetrieveSSI",
116
+ "SearchCompanies",
117
+ "SearchPeople",
118
+ "SendConnectionRequest",
119
+ "SendMessage",
120
+ "SimpleWorkflowMapper",
121
+ "SyncConversation",
122
+ "ThenWorkflowMapper",
123
+ "VoidWorkflowMapper",
124
+ "WithdrawConnectionRequest",
125
+ "__version__",
126
+ "poll_workflow_result",
127
+ ]
@@ -0,0 +1,13 @@
1
+ from linkedapi.admin.accounts import AdminAccounts
2
+ from linkedapi.admin.admin import LinkedApiAdmin
3
+ from linkedapi.admin.http_client import AdminHttpClient
4
+ from linkedapi.admin.limits import AdminLimits
5
+ from linkedapi.admin.subscription import AdminSubscription
6
+
7
+ __all__ = [
8
+ "AdminAccounts",
9
+ "AdminHttpClient",
10
+ "AdminLimits",
11
+ "AdminSubscription",
12
+ "LinkedApiAdmin",
13
+ ]
@@ -0,0 +1,91 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, TypeVar
4
+
5
+ from pydantic import BaseModel
6
+
7
+ from linkedapi.errors import LinkedApiError
8
+ from linkedapi.http import HttpClient
9
+ from linkedapi.types.admin import (
10
+ AccountsResult,
11
+ CancelConnectionSessionParams,
12
+ ConnectionSessionResult,
13
+ CreateConnectionSessionResult,
14
+ DisconnectParams,
15
+ GetConnectionSessionParams,
16
+ RegenerateTokenParams,
17
+ RegenerateTokenResult,
18
+ )
19
+
20
+ TModel = TypeVar("TModel", bound=BaseModel)
21
+
22
+
23
+ class AdminAccounts:
24
+ def __init__(self, http_client: HttpClient[Any]) -> None:
25
+ self.http_client = http_client
26
+
27
+ def get_all(self) -> AccountsResult:
28
+ return self._post_result("/admin/accounts.getAll", AccountsResult, "Failed to get accounts")
29
+
30
+ def disconnect(self, params: DisconnectParams) -> None:
31
+ self._post_void("/admin/accounts.disconnect", "Failed to disconnect account", params)
32
+
33
+ def regenerate_identification_token(
34
+ self,
35
+ params: RegenerateTokenParams,
36
+ ) -> RegenerateTokenResult:
37
+ return self._post_result(
38
+ "/admin/accounts.regenerateIdentificationToken",
39
+ RegenerateTokenResult,
40
+ "Failed to regenerate token",
41
+ params,
42
+ )
43
+
44
+ def create_connection_session(self) -> CreateConnectionSessionResult:
45
+ return self._post_result(
46
+ "/admin/accounts.createConnectionSession",
47
+ CreateConnectionSessionResult,
48
+ "Failed to create connection session",
49
+ )
50
+
51
+ def get_connection_session(
52
+ self,
53
+ params: GetConnectionSessionParams,
54
+ ) -> ConnectionSessionResult:
55
+ return self._post_result(
56
+ "/admin/accounts.getConnectionSession",
57
+ ConnectionSessionResult,
58
+ "Failed to get connection session",
59
+ params,
60
+ )
61
+
62
+ def cancel_connection_session(self, params: CancelConnectionSessionParams) -> None:
63
+ self._post_void(
64
+ "/admin/accounts.cancelConnectionSession",
65
+ "Failed to cancel connection session",
66
+ params,
67
+ )
68
+
69
+ def _post_result(
70
+ self,
71
+ path: str,
72
+ model: type[TModel],
73
+ default_message: str,
74
+ params: Any | None = None,
75
+ ) -> TModel:
76
+ response = self.http_client.post(path, params)
77
+ if response.success and response.result is not None:
78
+ return model.model_validate(response.result)
79
+ raise LinkedApiError(
80
+ response.error.type if response.error else "httpError",
81
+ response.error.message if response.error else default_message,
82
+ )
83
+
84
+ def _post_void(self, path: str, default_message: str, params: Any | None = None) -> None:
85
+ response = self.http_client.post(path, params)
86
+ if response.success:
87
+ return
88
+ raise LinkedApiError(
89
+ response.error.type if response.error else "httpError",
90
+ response.error.message if response.error else default_message,
91
+ )
@@ -0,0 +1,22 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from linkedapi.admin.accounts import AdminAccounts
6
+ from linkedapi.admin.http_client import AdminHttpClient
7
+ from linkedapi.admin.limits import AdminLimits
8
+ from linkedapi.admin.subscription import AdminSubscription
9
+ from linkedapi.http import HttpClient
10
+ from linkedapi.types.admin import AdminConfig
11
+
12
+
13
+ class LinkedApiAdmin:
14
+ """Admin SDK for Linked API subscription, account, and limit management."""
15
+
16
+ def __init__(self, config: AdminConfig | HttpClient[Any]) -> None:
17
+ http_client = (
18
+ config if isinstance(config, HttpClient) else AdminHttpClient(config, config.client)
19
+ )
20
+ self.subscription = AdminSubscription(http_client)
21
+ self.accounts = AdminAccounts(http_client)
22
+ self.limits = AdminLimits(http_client)
@@ -0,0 +1,73 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ import requests
6
+
7
+ from linkedapi.errors import LinkedApiError
8
+ from linkedapi.http import HttpClient
9
+ from linkedapi.types import LinkedApiResponse, serialize_value
10
+ from linkedapi.types.admin import AdminConfig
11
+
12
+
13
+ class AdminHttpClient(HttpClient[Any]):
14
+ def __init__(
15
+ self,
16
+ config: AdminConfig,
17
+ client: str | None = None,
18
+ base_url: str = "https://api.linkedapi.io",
19
+ session: requests.Session | None = None,
20
+ ) -> None:
21
+ self.base_url = base_url.rstrip("/")
22
+ self.session = session or requests.Session()
23
+ self.headers = {
24
+ "Content-Type": "application/json",
25
+ "linked-api-token": config.linked_api_token,
26
+ "client": client or config.client,
27
+ }
28
+
29
+ def get(self, path: str) -> LinkedApiResponse[Any]:
30
+ return self._request("GET", path)
31
+
32
+ def post(self, path: str, data: Any | None = None) -> LinkedApiResponse[Any]:
33
+ return self._request("POST", path, data)
34
+
35
+ def delete(self, path: str) -> LinkedApiResponse[Any]:
36
+ return self._request("DELETE", path)
37
+
38
+ def _request(self, method: str, path: str, data: Any | None = None) -> LinkedApiResponse[Any]:
39
+ try:
40
+ response = self.session.request(
41
+ method,
42
+ f"{self.base_url}{path}",
43
+ headers=self.headers,
44
+ json=serialize_value(data) if data is not None else None,
45
+ )
46
+ return self._handle_response(response)
47
+ except LinkedApiError:
48
+ raise
49
+ except requests.RequestException as error:
50
+ raise LinkedApiError(
51
+ "httpError", f"Request error: {error}", {"error": error}
52
+ ) from error
53
+
54
+ def _handle_response(self, response: requests.Response) -> LinkedApiResponse[Any]:
55
+ if response.ok:
56
+ return LinkedApiResponse[Any].model_validate(response.json())
57
+
58
+ try:
59
+ error_data = response.json()
60
+ error = error_data["error"]
61
+ raise LinkedApiError(error["type"], error["message"], error_data)
62
+ except LinkedApiError:
63
+ raise
64
+ except (KeyError, TypeError, ValueError) as error:
65
+ raise LinkedApiError(
66
+ "httpError",
67
+ f"HTTP {response.status_code}: {response.reason}",
68
+ {
69
+ "status": response.status_code,
70
+ "statusText": response.reason,
71
+ "url": response.url,
72
+ },
73
+ ) from error