external-systems 0.2.0__py3-none-any.whl → 0.100.0__py3-none-any.whl
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.
Potentially problematic release.
This version of external-systems might be problematic. Click here for more details.
- external_systems/_version.py +1 -1
- external_systems/sources/_sockets.py +17 -9
- external_systems/sources/_sources.py +1 -1
- external_systems-0.100.0.dist-info/METADATA +148 -0
- {external_systems-0.2.0.dist-info → external_systems-0.100.0.dist-info}/RECORD +7 -7
- external_systems-0.2.0.dist-info/METADATA +0 -75
- {external_systems-0.2.0.dist-info → external_systems-0.100.0.dist-info}/LICENSE.txt +0 -0
- {external_systems-0.2.0.dist-info → external_systems-0.100.0.dist-info}/WHEEL +0 -0
external_systems/_version.py
CHANGED
|
@@ -19,6 +19,7 @@ import re
|
|
|
19
19
|
import socket
|
|
20
20
|
import ssl
|
|
21
21
|
import time
|
|
22
|
+
from typing import Optional
|
|
22
23
|
|
|
23
24
|
import urllib3
|
|
24
25
|
|
|
@@ -30,15 +31,20 @@ NUM_RETRIES = 10
|
|
|
30
31
|
RETRYABLE_RESPONSE_CODES = {503, 429}
|
|
31
32
|
|
|
32
33
|
|
|
33
|
-
def create_socket(
|
|
34
|
+
def create_socket(
|
|
35
|
+
https_proxy_uri: str, target_host: str, target_port: int, custom_ca_bundle_path: Optional[str] = None
|
|
36
|
+
) -> socket.socket:
|
|
34
37
|
"""
|
|
35
38
|
Establishes a socket connection through an HTTPS proxy to a target host and port.
|
|
36
|
-
|
|
39
|
+
|
|
40
|
+
Args:
|
|
37
41
|
https_proxy_uri (str): The URI of the HTTPS proxy, must include auth if required.
|
|
38
42
|
target_host (str): The hostname of the target server to connect to.
|
|
39
43
|
target_port (int): The port number of the target server to connect to.
|
|
44
|
+
|
|
40
45
|
Returns:
|
|
41
46
|
socket.socket: A connected SSL socket to the target host and port through the proxy.
|
|
47
|
+
|
|
42
48
|
Raises:
|
|
43
49
|
ValueError: If the proxy URI does not specify a hostname or port, or if the connection fails after retrying, with an invalid response code.
|
|
44
50
|
RuntimeError: If there is an exception during the socket creation process.
|
|
@@ -55,7 +61,7 @@ def create_socket(https_proxy_uri: str, target_host: str, target_port: int) -> s
|
|
|
55
61
|
last_response_code = -1
|
|
56
62
|
for _ in range(NUM_RETRIES):
|
|
57
63
|
try:
|
|
58
|
-
proxy_socket = _create_ssl_socket(parsed_proxy_uri.hostname, parsed_proxy_uri.port)
|
|
64
|
+
proxy_socket = _create_ssl_socket(parsed_proxy_uri.hostname, parsed_proxy_uri.port, custom_ca_bundle_path)
|
|
59
65
|
proxy_socket.sendall(f"CONNECT {target_host}:{target_port} HTTP/1.1\r\n".encode())
|
|
60
66
|
proxy_socket.sendall(f"Host: {target_host}:{target_port}\r\n".encode())
|
|
61
67
|
|
|
@@ -88,14 +94,16 @@ def create_socket(https_proxy_uri: str, target_host: str, target_port: int) -> s
|
|
|
88
94
|
raise ValueError(f"Failed to establish tunnel, invalid response code: {last_response_code}")
|
|
89
95
|
|
|
90
96
|
|
|
91
|
-
def _create_ssl_socket(proxy_host: str, proxy_port: int) -> socket.socket:
|
|
92
|
-
ca_bundle_path =
|
|
97
|
+
def _create_ssl_socket(proxy_host: str, proxy_port: int, custom_ca_bundle_path: Optional[str] = None) -> socket.socket:
|
|
98
|
+
ca_bundle_path = (
|
|
99
|
+
custom_ca_bundle_path if custom_ca_bundle_path is not None else os.environ.get("REQUESTS_CA_BUNDLE")
|
|
100
|
+
)
|
|
93
101
|
if not ca_bundle_path or not os.path.isfile(ca_bundle_path):
|
|
94
|
-
log.warning("The
|
|
95
|
-
raise ValueError("
|
|
102
|
+
log.warning("The CA_BUNDLE environment variable does not exist or is not a file.")
|
|
103
|
+
raise ValueError("CA_BUNDLE does not exist")
|
|
96
104
|
if not os.access(ca_bundle_path, os.R_OK):
|
|
97
|
-
log.warning("The
|
|
98
|
-
raise ValueError("
|
|
105
|
+
log.warning("The CA_BUNDLE file is not readable.")
|
|
106
|
+
raise ValueError("CA_BUNDLE is not readable")
|
|
99
107
|
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
100
108
|
context.load_verify_locations(ca_bundle_path)
|
|
101
109
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
@@ -241,4 +241,4 @@ class Source:
|
|
|
241
241
|
if not self._https_proxy_url:
|
|
242
242
|
raise ValueError("Only usable with Agent Proxy Sources")
|
|
243
243
|
|
|
244
|
-
return create_socket(self._https_proxy_url, target_host, target_port)
|
|
244
|
+
return create_socket(self._https_proxy_url, target_host, target_port, self._custom_ca_bundle_path)
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: external-systems
|
|
3
|
+
Version: 0.100.0
|
|
4
|
+
Summary: A Python library for interacting with Foundry Sources
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Keywords: Palantir,Foundry,Sources,Compute Modules,Python Functions,Transforms
|
|
7
|
+
Author: Palantir Technologies, Inc.
|
|
8
|
+
Requires-Python: >=3.9,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Dist: frozendict (>=2.4.6,<3.0.0)
|
|
17
|
+
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
18
|
+
Project-URL: Repository, https://github.com/palantir/external-systems
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# External Systems
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+
[](https://pypi.org/project/external-systems/)
|
|
25
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
26
|
+
<a href="https://autorelease.general.dmz.palantir.tech/palantir/external-systems"><img src="https://img.shields.io/badge/Perform%20an-Autorelease-success.svg" alt="Autorelease"></a>
|
|
27
|
+
|
|
28
|
+
> [!WARNING]
|
|
29
|
+
> This SDK is incubating and subject to change.
|
|
30
|
+
|
|
31
|
+
## About Foundry Sources
|
|
32
|
+
|
|
33
|
+
The External Systems library is Python SDK built as an interface to reference [Foundry Sources](https://www.palantir.com/docs/foundry/data-connection/set-up-source) from code.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
You can install the Python package using `pip`:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
pip install external-systems
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Basic Source Usage
|
|
44
|
+
|
|
45
|
+
### HTTP Client
|
|
46
|
+
|
|
47
|
+
For REST based sources, a preconfigured HTTP client is provided built on top of the Python requests library. For on-prem systems using [Agent Proxy](https://www.palantir.com/docs/foundry/data-connection/agent-proxy-runtime) the client will be pre-configured with the corresponding proxy
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from external_systems.sources import Source, HttpsConnection
|
|
51
|
+
from requests import Session
|
|
52
|
+
|
|
53
|
+
my_source: Source = ...
|
|
54
|
+
|
|
55
|
+
https_connection: HttpsConnection = my_source.get_https_connection()
|
|
56
|
+
|
|
57
|
+
source_url: str = https_connection.url
|
|
58
|
+
http_client: Session = https_connection.get_client()
|
|
59
|
+
|
|
60
|
+
response = http_client.get(source_url + "/api/v1/example/", timeout=10)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Secrets
|
|
64
|
+
|
|
65
|
+
Source secrets can be referenced using `get_secret("<secret_name>")` on the source.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from external_systems.sources import Source
|
|
69
|
+
|
|
70
|
+
my_source: Source = ...
|
|
71
|
+
|
|
72
|
+
some_secret: str = my_source.get_secret("SECRET_NAME")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
For sources using session credentials we support credentials generation and refresh management. Currently on an S3 source you can access session credentials using `get_aws_credentials()`. This method will throw if the source is not pre-configured with `AwsCredentials`
|
|
76
|
+
|
|
77
|
+
_Session credentials may not be available in all Foundry runtime environments_
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from external_systems.sources import Source, Refreshable, AwsCredentials
|
|
81
|
+
|
|
82
|
+
s3_source: Source = ...
|
|
83
|
+
|
|
84
|
+
refreshable_credentials: Refreshable[AwsCredentials] = s3_source.get_aws_credentials()
|
|
85
|
+
|
|
86
|
+
session_credentials: AwsCredentials = refreshable_credentials.get()
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## On-prem Connectivity with [Foundry Agent Proxy](https://www.palantir.com/docs/foundry/data-connection/agent-proxy-runtime)
|
|
90
|
+
|
|
91
|
+
### Socket
|
|
92
|
+
|
|
93
|
+
For non-HTTP connections to external systems that require connections through Foundry's agent proxy, a pre-configured socket is provided.
|
|
94
|
+
|
|
95
|
+
#### On-Prem SFTP Server Example
|
|
96
|
+
|
|
97
|
+
For this example we'll be using the [fabric](https://docs.fabfile.org/en/latest/) library
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
import fabric
|
|
101
|
+
|
|
102
|
+
from external_systems.sources import Source
|
|
103
|
+
from socket import socket
|
|
104
|
+
|
|
105
|
+
SFTP_HOST = <sftp_host>
|
|
106
|
+
SFTP_PORT = <sftp_port>
|
|
107
|
+
|
|
108
|
+
on_prem_proxied_source: Source = ...
|
|
109
|
+
|
|
110
|
+
username: str = on_prem_sftp_server.get_secret("username")
|
|
111
|
+
password: str = on_prem_sftp_server.get_secret("password")
|
|
112
|
+
|
|
113
|
+
proxy_socket: socket = source.create_socket(SFTP_HOST, SFTP_PORT)
|
|
114
|
+
|
|
115
|
+
with fabric.Connection(
|
|
116
|
+
SFTP_HOST,
|
|
117
|
+
user=username,
|
|
118
|
+
port=SFTP_PORT,
|
|
119
|
+
connect_kwargs={
|
|
120
|
+
"password": password,
|
|
121
|
+
"sock": proxy_socket,
|
|
122
|
+
},
|
|
123
|
+
) as conn:
|
|
124
|
+
sftp = conn.sftp()
|
|
125
|
+
file_list = sftp.listdir(".")
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Authenticated Proxy URI
|
|
129
|
+
|
|
130
|
+
For more granular use cases a pre-authenticated proxy URI is provided to allow connections to on-prem external systems.
|
|
131
|
+
|
|
132
|
+
#### Example
|
|
133
|
+
|
|
134
|
+
We'll be using the [httpx](https://www.python-httpx.org/) library.
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
import httpx
|
|
138
|
+
|
|
139
|
+
from external_systems.sources import Source
|
|
140
|
+
|
|
141
|
+
on_prem_system: Source = ...
|
|
142
|
+
|
|
143
|
+
authenticated_proxy_uri: str = on_prem_system.get_https_proxy_uri()
|
|
144
|
+
|
|
145
|
+
with httpx.Client(proxy=authenticated_proxy_uri) as client:
|
|
146
|
+
...
|
|
147
|
+
```
|
|
148
|
+
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
external_systems/__init__.py,sha256=xXDUDD6_qRO-nHuXZx-fXp0R0vc3N_OOsB1F5mF_kpU,651
|
|
2
|
-
external_systems/_version.py,sha256=
|
|
2
|
+
external_systems/_version.py,sha256=hjlDjGystUTnz8tbYT4EN9fUv5EDzQW6b4kjmTcz03s,749
|
|
3
3
|
external_systems/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
external_systems/sources/__init__.py,sha256=aqXbMIy_pnyIC1uPRzQfApLCbhYB4N8iRFnpOX4RdAk,1156
|
|
5
5
|
external_systems/sources/_api.py,sha256=NV7oNIgzSWz4ROFW8uPpUJjDN5vfFzdTs3yKC37S39k,3262
|
|
6
6
|
external_systems/sources/_connections.py,sha256=h82npEks29NALAAfMHrXcSnB7TY_OLeXgL3QN9Cssus,2509
|
|
7
7
|
external_systems/sources/_proxies.py,sha256=igWRL-kpQ_IlZyJwI_s66rDe0oQ68ltGeFNydgoiR4w,5071
|
|
8
8
|
external_systems/sources/_refreshable.py,sha256=0pa5XW0_2gTMW-ZymKhlhh3Kka_bWTWffThKvrTTifc,4421
|
|
9
|
-
external_systems/sources/_sockets.py,sha256=
|
|
10
|
-
external_systems/sources/_sources.py,sha256
|
|
9
|
+
external_systems/sources/_sockets.py,sha256=XH51adVnloqg8XYVHPxl6K8R_q2BCh6WZ77cq1L8nRg,4473
|
|
10
|
+
external_systems/sources/_sources.py,sha256=-DP1QzuCtXOnsijwTNxI9x2vyEmxgyRB47ZTVQshfXA,10829
|
|
11
11
|
external_systems/sources/_utils.py,sha256=EmUKKiKRDOZ2cZs7FZ4qCSan_lq1K_tquh3kxleB-jA,1004
|
|
12
|
-
external_systems-0.
|
|
13
|
-
external_systems-0.
|
|
14
|
-
external_systems-0.
|
|
15
|
-
external_systems-0.
|
|
12
|
+
external_systems-0.100.0.dist-info/LICENSE.txt,sha256=NAk6Uc9K_N_J5V75k9qECpzUnO-ujT-mKK_jk_mboUE,569
|
|
13
|
+
external_systems-0.100.0.dist-info/METADATA,sha256=3OYGduGNMYwz9ZI8KIlZRbBzFsNV9N1cJF3FKo6cxXI,4765
|
|
14
|
+
external_systems-0.100.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
15
|
+
external_systems-0.100.0.dist-info/RECORD,,
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: external-systems
|
|
3
|
-
Version: 0.2.0
|
|
4
|
-
Summary: A Python library for interacting with Foundry Sources
|
|
5
|
-
License: Apache-2.0
|
|
6
|
-
Keywords: Palantir,Foundry,Sources,Compute Modules,Python Functions,Transforms
|
|
7
|
-
Author: Palantir Technologies, Inc.
|
|
8
|
-
Requires-Python: >=3.9,<4.0
|
|
9
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
-
Requires-Dist: frozendict (>=2.4.6,<3.0.0)
|
|
17
|
-
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
18
|
-
Project-URL: Repository, https://github.com/palantir/external-systems
|
|
19
|
-
Description-Content-Type: text/markdown
|
|
20
|
-
|
|
21
|
-
# External Systems
|
|
22
|
-

|
|
23
|
-
[](https://pypi.org/project/external-systems/)
|
|
24
|
-
[](https://opensource.org/licenses/Apache-2.0)
|
|
25
|
-
<a href="https://autorelease.general.dmz.palantir.tech/palantir/external-systems"><img src="https://img.shields.io/badge/Perform%20an-Autorelease-success.svg" alt="Autorelease"></a>
|
|
26
|
-
|
|
27
|
-
> [!WARNING]
|
|
28
|
-
> This SDK is incubating and subject to change.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
## About Foundry Sources
|
|
32
|
-
|
|
33
|
-
The External Systems library is Python SDK built as an interface to reference [Foundry Sources](https://www.palantir.com/docs/foundry/data-connection/set-up-source) from code.
|
|
34
|
-
|
|
35
|
-
<a id="installation"></a>
|
|
36
|
-
## Installation
|
|
37
|
-
You can install the Python package using `pip`:
|
|
38
|
-
|
|
39
|
-
```sh
|
|
40
|
-
pip install external-systems
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
<a id="basic-usage"></a>
|
|
44
|
-
## Basic Source Usage
|
|
45
|
-
|
|
46
|
-
### Credentials
|
|
47
|
-
|
|
48
|
-
Long lived credentials can be referenced using `get_secret()` on the source.
|
|
49
|
-
|
|
50
|
-
```python
|
|
51
|
-
my_source: Source = ...
|
|
52
|
-
|
|
53
|
-
some_secret = my_source.get_secret("SECRET_NAME")
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
For sources using session credentials we support credentials generation and refresh management. Currently on an S3 source you can access session credentials using `get_aws_credentials()`.
|
|
57
|
-
|
|
58
|
-
```python
|
|
59
|
-
s3_source: Source = ...
|
|
60
|
-
|
|
61
|
-
refreshable_credentials: Refreshable[AwsCredentials] = s3_source.get_aws_credentials()
|
|
62
|
-
|
|
63
|
-
session_credentials: AwsCredentials = refreshable_credentials.get()
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### HTTP Client
|
|
67
|
-
For REST based sources, a preconfigured HTTP client is provided built on top of the Python requests library.
|
|
68
|
-
|
|
69
|
-
```python
|
|
70
|
-
source_url = my_source.get_https_connection().url
|
|
71
|
-
http_client = my_source.get_https_connection().get_client()
|
|
72
|
-
|
|
73
|
-
response = http_client.get(source_url + "/api/v1/example/", timeout=10)
|
|
74
|
-
```
|
|
75
|
-
|
|
File without changes
|
|
File without changes
|