cdata-connect 0.0.1.dev1__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.
- cdata_connect-0.0.1.dev1/LICENSE +21 -0
- cdata_connect-0.0.1.dev1/MANIFEST.in +8 -0
- cdata_connect-0.0.1.dev1/PKG-INFO +290 -0
- cdata_connect-0.0.1.dev1/README.md +254 -0
- cdata_connect-0.0.1.dev1/cdata_connect/LICENSE +21 -0
- cdata_connect-0.0.1.dev1/cdata_connect/__init__.py +82 -0
- cdata_connect-0.0.1.dev1/cdata_connect/connection.py +118 -0
- cdata_connect-0.0.1.dev1/cdata_connect/cursor.py +366 -0
- cdata_connect-0.0.1.dev1/cdata_connect/exceptions.py +42 -0
- cdata_connect-0.0.1.dev1/cdata_connect/log.py +7 -0
- cdata_connect-0.0.1.dev1/cdata_connect/util/__init__.py +0 -0
- cdata_connect-0.0.1.dev1/cdata_connect/util/types.py +214 -0
- cdata_connect-0.0.1.dev1/cdata_connect/version.py +5 -0
- cdata_connect-0.0.1.dev1/cdata_connect.egg-info/PKG-INFO +290 -0
- cdata_connect-0.0.1.dev1/cdata_connect.egg-info/SOURCES.txt +19 -0
- cdata_connect-0.0.1.dev1/cdata_connect.egg-info/dependency_links.txt +1 -0
- cdata_connect-0.0.1.dev1/cdata_connect.egg-info/requires.txt +11 -0
- cdata_connect-0.0.1.dev1/cdata_connect.egg-info/top_level.txt +2 -0
- cdata_connect-0.0.1.dev1/pyproject.toml +79 -0
- cdata_connect-0.0.1.dev1/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 CData Software, Inc.
|
|
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,290 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cdata-connect
|
|
3
|
+
Version: 0.0.1.dev1
|
|
4
|
+
Summary: CData Connect Python DB-API 2.0 interface library
|
|
5
|
+
Author-email: "CData Software, Inc." <support@cdata.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://www.cdata.com/connect/
|
|
8
|
+
Project-URL: Repository, https://github.com/CDataSoftware/cloud-sdk-python
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/CDataSoftware/cloud-sdk-python/issues
|
|
10
|
+
Keywords: cdata,dbapi,database,connector
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Natural Language :: English
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
21
|
+
Classifier: Topic :: Database :: Front-Ends
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: requests>=2.28.0
|
|
27
|
+
Requires-Dist: ijson>=3.1.0
|
|
28
|
+
Requires-Dist: pyhocon>=0.3.60
|
|
29
|
+
Provides-Extra: full
|
|
30
|
+
Requires-Dist: pandas>=1.3.0; extra == "full"
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-mock>=3.10; extra == "dev"
|
|
34
|
+
Requires-Dist: requests; extra == "dev"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# ConnectAI Python Connector
|
|
38
|
+
|
|
39
|
+
A Python [DB-API 2.0 (PEP 249)](https://peps.python.org/pep-0249/) compliant connector for [CData Connect AI](https://www.cdata.com/connect/). Query any data source connected through Connect AI using the standard Python database interface.
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install cdata-connect
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
For pandas integration:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install "cdata-connect[full]"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Quick Start
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import cdata_connect
|
|
57
|
+
|
|
58
|
+
conn = cdata_connect.connect(
|
|
59
|
+
base_url="https://cloud.cdata.com/api/",
|
|
60
|
+
username="you@example.com",
|
|
61
|
+
password="<your_personal_access_token>",
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
cursor = conn.cursor()
|
|
65
|
+
cursor.execute("SELECT * FROM [Salesforce1].[Salesforce].[Account]")
|
|
66
|
+
rows = cursor.fetchall()
|
|
67
|
+
for row in rows:
|
|
68
|
+
print(row)
|
|
69
|
+
|
|
70
|
+
conn.close()
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Configuration File
|
|
74
|
+
|
|
75
|
+
Use a [PyHOCON](https://github.com/chimpler/pyhocon) config file to keep credentials out of code:
|
|
76
|
+
|
|
77
|
+
```hocon
|
|
78
|
+
# config.conf
|
|
79
|
+
cdata_api_db {
|
|
80
|
+
base_url = "https://cloud.cdata.com/api/"
|
|
81
|
+
username = "you@example.com"
|
|
82
|
+
password = "<your_personal_access_token>"
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
conn = cdata_connect.connect(config_path="config.conf")
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Parameterized Queries
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
cursor.execute(
|
|
94
|
+
"SELECT * FROM [DB].[public].[users] WHERE city = %(city)s LIMIT %(limit)s",
|
|
95
|
+
{"city": "New York", "limit": 10},
|
|
96
|
+
)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Batch Operations
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
cursor.executemany(
|
|
103
|
+
"INSERT INTO [DB].[public].[cities] (city, id) VALUES (@city, @id)",
|
|
104
|
+
[
|
|
105
|
+
{"@city": {"dataType": 5, "value": "New York"}, "@id": {"dataType": 8, "value": 1}},
|
|
106
|
+
{"@city": {"dataType": 5, "value": "London"}, "@id": {"dataType": 8, "value": 2}},
|
|
107
|
+
],
|
|
108
|
+
)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Stored Procedures
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
cursor.callproc("[DB].[public].[my_procedure]", ("arg1", "arg2"))
|
|
115
|
+
rows = cursor.fetchall()
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Connection Options
|
|
119
|
+
|
|
120
|
+
| Parameter | Description | Default |
|
|
121
|
+
|-----------|-------------|---------|
|
|
122
|
+
| `base_url` | Connect AI API base URL | — |
|
|
123
|
+
| `username` | Authentication username | — |
|
|
124
|
+
| `password` | Personal access token | — |
|
|
125
|
+
| `config_path` | Path to PyHOCON config file | — |
|
|
126
|
+
| `workspace` | Connect AI workspace name | — |
|
|
127
|
+
| `timeout` | HTTP request timeout (seconds) | `30` |
|
|
128
|
+
| `max_retries` | Retries on transient 5xx errors | `3` |
|
|
129
|
+
| `retry_delay` | Base delay between retries (seconds) | `1.0` |
|
|
130
|
+
|
|
131
|
+
## DB-API 2.0 Compliance
|
|
132
|
+
|
|
133
|
+
| Attribute | Value |
|
|
134
|
+
|-----------|-------|
|
|
135
|
+
| `apilevel` | `"2.0"` |
|
|
136
|
+
| `threadsafety` | `3` |
|
|
137
|
+
| `paramstyle` | `"pyformat"` |
|
|
138
|
+
|
|
139
|
+
**Supported methods:** `connect()`, `cursor()`, `execute()`, `executemany()`, `callproc()`, `fetchone()`, `fetchmany()`, `fetchall()`, `close()`, `commit()`, `rollback()`
|
|
140
|
+
|
|
141
|
+
## Exception Hierarchy
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
cdata_connect.Error
|
|
145
|
+
├── InterfaceError
|
|
146
|
+
└── DatabaseError
|
|
147
|
+
├── DataError
|
|
148
|
+
├── OperationalError
|
|
149
|
+
├── IntegrityError
|
|
150
|
+
├── InternalError
|
|
151
|
+
├── ProgrammingError
|
|
152
|
+
└── NotSupportedError
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Requirements
|
|
156
|
+
|
|
157
|
+
- Python >= 3.10
|
|
158
|
+
- `requests >= 2.28.0`
|
|
159
|
+
- `ijson >= 3.1.0`
|
|
160
|
+
- `pyhocon >= 0.3.60`
|
|
161
|
+
|
|
162
|
+
## Running Tests
|
|
163
|
+
|
|
164
|
+
Tests are split into **unit** (no server) and **integration** (mock server auto-starts).
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
pip install -e ".[dev]"
|
|
168
|
+
|
|
169
|
+
# Unit tests only — fast, no server needed
|
|
170
|
+
pytest tests/unit/ -v
|
|
171
|
+
|
|
172
|
+
# Integration tests — mock server auto-starts on localhost
|
|
173
|
+
pytest tests/integration/ -v
|
|
174
|
+
|
|
175
|
+
# All tests
|
|
176
|
+
pytest tests/ -v
|
|
177
|
+
|
|
178
|
+
# Run against a live Connect AI endpoint
|
|
179
|
+
CDATA_BASE_URL=https://cloud.cdata.com/api \
|
|
180
|
+
CDATA_USERNAME=you@example.com \
|
|
181
|
+
CDATA_PASSWORD=<pat> \
|
|
182
|
+
SKIP_LIVE_TESTS=0 \
|
|
183
|
+
pytest tests/integration/ -v
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
See [`tests/README.md`](tests/README.md) for test organization details.
|
|
187
|
+
|
|
188
|
+
### Test Environment Variables
|
|
189
|
+
|
|
190
|
+
| Variable | Description | Default |
|
|
191
|
+
|----------|-------------|---------|
|
|
192
|
+
| `CDATA_BASE_URL` | API endpoint | `http://localhost:8080/api` |
|
|
193
|
+
| `CDATA_USERNAME` | Auth username | `test@example.com` |
|
|
194
|
+
| `CDATA_PASSWORD` | Auth password / PAT | `any_token` |
|
|
195
|
+
| `MOCK_PORT` | Mock server port | `8080` |
|
|
196
|
+
| `MOCK_SERVER_DIR` | Path to mock server | `../connect-ai-mock` |
|
|
197
|
+
| `SKIP_LIVE_TESTS` | Skip live API tests | `1` |
|
|
198
|
+
|
|
199
|
+
## Building from Source
|
|
200
|
+
|
|
201
|
+
Install the build tool:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
pip install build
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Build both the wheel and source distribution from the `connector/` directory:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
cd connector
|
|
211
|
+
python -m build
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Artifacts are written to `connector/dist/`:
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
dist/
|
|
218
|
+
├── cdata_connect-1.0.0-py3-none-any.whl # Wheel (preferred for install)
|
|
219
|
+
└── cdata_connect-1.0.0.tar.gz # Source distribution
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Install the locally built wheel:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
pip install dist/cdata_connect-1.0.0-py3-none-any.whl
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Publishing to PyPI
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
pip install twine
|
|
232
|
+
|
|
233
|
+
# Verify the package metadata before uploading
|
|
234
|
+
twine check dist/*
|
|
235
|
+
|
|
236
|
+
# Upload to TestPyPI first (recommended for a dry run)
|
|
237
|
+
twine upload --repository testpypi dist/*
|
|
238
|
+
|
|
239
|
+
# Upload to PyPI
|
|
240
|
+
twine upload dist/*
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Store your PyPI credentials in `~/.pypirc` or pass them as environment variables:
|
|
244
|
+
|
|
245
|
+
```ini
|
|
246
|
+
# ~/.pypirc
|
|
247
|
+
[pypi]
|
|
248
|
+
username = __token__
|
|
249
|
+
password = pypi-<your-api-token>
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Demo Client
|
|
253
|
+
|
|
254
|
+
A demo script at the repo root (`client_demo.py`) exercises the connector end-to-end against the mock server. It covers:
|
|
255
|
+
|
|
256
|
+
- `SELECT` with `fetchall`, `fetchone`, and `fetchmany`
|
|
257
|
+
- `cursor.description` (column metadata)
|
|
258
|
+
- Parameterized queries (`pyformat`)
|
|
259
|
+
- Batch `INSERT` via `executemany` and `SELECT` to verify
|
|
260
|
+
- `DELETE` and confirm empty result
|
|
261
|
+
- Stored procedure via `callproc`
|
|
262
|
+
- Error handling (`OperationalError` on bad host)
|
|
263
|
+
|
|
264
|
+
**Step 1 — Start the mock server** (in one terminal):
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
cd connect-ai-mock
|
|
268
|
+
pip install -r requirements.txt
|
|
269
|
+
python run.py
|
|
270
|
+
# Server ready at http://localhost:8080
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Step 2 — Install the connector and run the demo** (in another terminal):
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
# Install from PyPI
|
|
277
|
+
pip install cdata-connect
|
|
278
|
+
|
|
279
|
+
# OR install the locally built wheel
|
|
280
|
+
pip install connector/dist/cdata_connect-1.0.0-py3-none-any.whl
|
|
281
|
+
|
|
282
|
+
# Run
|
|
283
|
+
python client_demo.py
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Expected output covers all 9 demo sections and ends with `All done.`
|
|
287
|
+
|
|
288
|
+
## License
|
|
289
|
+
|
|
290
|
+
MIT — see [LICENSE](LICENSE)
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# ConnectAI Python Connector
|
|
2
|
+
|
|
3
|
+
A Python [DB-API 2.0 (PEP 249)](https://peps.python.org/pep-0249/) compliant connector for [CData Connect AI](https://www.cdata.com/connect/). Query any data source connected through Connect AI using the standard Python database interface.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install cdata-connect
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For pandas integration:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install "cdata-connect[full]"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import cdata_connect
|
|
21
|
+
|
|
22
|
+
conn = cdata_connect.connect(
|
|
23
|
+
base_url="https://cloud.cdata.com/api/",
|
|
24
|
+
username="you@example.com",
|
|
25
|
+
password="<your_personal_access_token>",
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
cursor = conn.cursor()
|
|
29
|
+
cursor.execute("SELECT * FROM [Salesforce1].[Salesforce].[Account]")
|
|
30
|
+
rows = cursor.fetchall()
|
|
31
|
+
for row in rows:
|
|
32
|
+
print(row)
|
|
33
|
+
|
|
34
|
+
conn.close()
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Configuration File
|
|
38
|
+
|
|
39
|
+
Use a [PyHOCON](https://github.com/chimpler/pyhocon) config file to keep credentials out of code:
|
|
40
|
+
|
|
41
|
+
```hocon
|
|
42
|
+
# config.conf
|
|
43
|
+
cdata_api_db {
|
|
44
|
+
base_url = "https://cloud.cdata.com/api/"
|
|
45
|
+
username = "you@example.com"
|
|
46
|
+
password = "<your_personal_access_token>"
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
conn = cdata_connect.connect(config_path="config.conf")
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Parameterized Queries
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
cursor.execute(
|
|
58
|
+
"SELECT * FROM [DB].[public].[users] WHERE city = %(city)s LIMIT %(limit)s",
|
|
59
|
+
{"city": "New York", "limit": 10},
|
|
60
|
+
)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Batch Operations
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
cursor.executemany(
|
|
67
|
+
"INSERT INTO [DB].[public].[cities] (city, id) VALUES (@city, @id)",
|
|
68
|
+
[
|
|
69
|
+
{"@city": {"dataType": 5, "value": "New York"}, "@id": {"dataType": 8, "value": 1}},
|
|
70
|
+
{"@city": {"dataType": 5, "value": "London"}, "@id": {"dataType": 8, "value": 2}},
|
|
71
|
+
],
|
|
72
|
+
)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Stored Procedures
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
cursor.callproc("[DB].[public].[my_procedure]", ("arg1", "arg2"))
|
|
79
|
+
rows = cursor.fetchall()
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Connection Options
|
|
83
|
+
|
|
84
|
+
| Parameter | Description | Default |
|
|
85
|
+
|-----------|-------------|---------|
|
|
86
|
+
| `base_url` | Connect AI API base URL | — |
|
|
87
|
+
| `username` | Authentication username | — |
|
|
88
|
+
| `password` | Personal access token | — |
|
|
89
|
+
| `config_path` | Path to PyHOCON config file | — |
|
|
90
|
+
| `workspace` | Connect AI workspace name | — |
|
|
91
|
+
| `timeout` | HTTP request timeout (seconds) | `30` |
|
|
92
|
+
| `max_retries` | Retries on transient 5xx errors | `3` |
|
|
93
|
+
| `retry_delay` | Base delay between retries (seconds) | `1.0` |
|
|
94
|
+
|
|
95
|
+
## DB-API 2.0 Compliance
|
|
96
|
+
|
|
97
|
+
| Attribute | Value |
|
|
98
|
+
|-----------|-------|
|
|
99
|
+
| `apilevel` | `"2.0"` |
|
|
100
|
+
| `threadsafety` | `3` |
|
|
101
|
+
| `paramstyle` | `"pyformat"` |
|
|
102
|
+
|
|
103
|
+
**Supported methods:** `connect()`, `cursor()`, `execute()`, `executemany()`, `callproc()`, `fetchone()`, `fetchmany()`, `fetchall()`, `close()`, `commit()`, `rollback()`
|
|
104
|
+
|
|
105
|
+
## Exception Hierarchy
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
cdata_connect.Error
|
|
109
|
+
├── InterfaceError
|
|
110
|
+
└── DatabaseError
|
|
111
|
+
├── DataError
|
|
112
|
+
├── OperationalError
|
|
113
|
+
├── IntegrityError
|
|
114
|
+
├── InternalError
|
|
115
|
+
├── ProgrammingError
|
|
116
|
+
└── NotSupportedError
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Requirements
|
|
120
|
+
|
|
121
|
+
- Python >= 3.10
|
|
122
|
+
- `requests >= 2.28.0`
|
|
123
|
+
- `ijson >= 3.1.0`
|
|
124
|
+
- `pyhocon >= 0.3.60`
|
|
125
|
+
|
|
126
|
+
## Running Tests
|
|
127
|
+
|
|
128
|
+
Tests are split into **unit** (no server) and **integration** (mock server auto-starts).
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
pip install -e ".[dev]"
|
|
132
|
+
|
|
133
|
+
# Unit tests only — fast, no server needed
|
|
134
|
+
pytest tests/unit/ -v
|
|
135
|
+
|
|
136
|
+
# Integration tests — mock server auto-starts on localhost
|
|
137
|
+
pytest tests/integration/ -v
|
|
138
|
+
|
|
139
|
+
# All tests
|
|
140
|
+
pytest tests/ -v
|
|
141
|
+
|
|
142
|
+
# Run against a live Connect AI endpoint
|
|
143
|
+
CDATA_BASE_URL=https://cloud.cdata.com/api \
|
|
144
|
+
CDATA_USERNAME=you@example.com \
|
|
145
|
+
CDATA_PASSWORD=<pat> \
|
|
146
|
+
SKIP_LIVE_TESTS=0 \
|
|
147
|
+
pytest tests/integration/ -v
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
See [`tests/README.md`](tests/README.md) for test organization details.
|
|
151
|
+
|
|
152
|
+
### Test Environment Variables
|
|
153
|
+
|
|
154
|
+
| Variable | Description | Default |
|
|
155
|
+
|----------|-------------|---------|
|
|
156
|
+
| `CDATA_BASE_URL` | API endpoint | `http://localhost:8080/api` |
|
|
157
|
+
| `CDATA_USERNAME` | Auth username | `test@example.com` |
|
|
158
|
+
| `CDATA_PASSWORD` | Auth password / PAT | `any_token` |
|
|
159
|
+
| `MOCK_PORT` | Mock server port | `8080` |
|
|
160
|
+
| `MOCK_SERVER_DIR` | Path to mock server | `../connect-ai-mock` |
|
|
161
|
+
| `SKIP_LIVE_TESTS` | Skip live API tests | `1` |
|
|
162
|
+
|
|
163
|
+
## Building from Source
|
|
164
|
+
|
|
165
|
+
Install the build tool:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
pip install build
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Build both the wheel and source distribution from the `connector/` directory:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
cd connector
|
|
175
|
+
python -m build
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Artifacts are written to `connector/dist/`:
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
dist/
|
|
182
|
+
├── cdata_connect-1.0.0-py3-none-any.whl # Wheel (preferred for install)
|
|
183
|
+
└── cdata_connect-1.0.0.tar.gz # Source distribution
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Install the locally built wheel:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
pip install dist/cdata_connect-1.0.0-py3-none-any.whl
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Publishing to PyPI
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
pip install twine
|
|
196
|
+
|
|
197
|
+
# Verify the package metadata before uploading
|
|
198
|
+
twine check dist/*
|
|
199
|
+
|
|
200
|
+
# Upload to TestPyPI first (recommended for a dry run)
|
|
201
|
+
twine upload --repository testpypi dist/*
|
|
202
|
+
|
|
203
|
+
# Upload to PyPI
|
|
204
|
+
twine upload dist/*
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Store your PyPI credentials in `~/.pypirc` or pass them as environment variables:
|
|
208
|
+
|
|
209
|
+
```ini
|
|
210
|
+
# ~/.pypirc
|
|
211
|
+
[pypi]
|
|
212
|
+
username = __token__
|
|
213
|
+
password = pypi-<your-api-token>
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Demo Client
|
|
217
|
+
|
|
218
|
+
A demo script at the repo root (`client_demo.py`) exercises the connector end-to-end against the mock server. It covers:
|
|
219
|
+
|
|
220
|
+
- `SELECT` with `fetchall`, `fetchone`, and `fetchmany`
|
|
221
|
+
- `cursor.description` (column metadata)
|
|
222
|
+
- Parameterized queries (`pyformat`)
|
|
223
|
+
- Batch `INSERT` via `executemany` and `SELECT` to verify
|
|
224
|
+
- `DELETE` and confirm empty result
|
|
225
|
+
- Stored procedure via `callproc`
|
|
226
|
+
- Error handling (`OperationalError` on bad host)
|
|
227
|
+
|
|
228
|
+
**Step 1 — Start the mock server** (in one terminal):
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
cd connect-ai-mock
|
|
232
|
+
pip install -r requirements.txt
|
|
233
|
+
python run.py
|
|
234
|
+
# Server ready at http://localhost:8080
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**Step 2 — Install the connector and run the demo** (in another terminal):
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
# Install from PyPI
|
|
241
|
+
pip install cdata-connect
|
|
242
|
+
|
|
243
|
+
# OR install the locally built wheel
|
|
244
|
+
pip install connector/dist/cdata_connect-1.0.0-py3-none-any.whl
|
|
245
|
+
|
|
246
|
+
# Run
|
|
247
|
+
python client_demo.py
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Expected output covers all 9 demo sections and ends with `All done.`
|
|
251
|
+
|
|
252
|
+
## License
|
|
253
|
+
|
|
254
|
+
MIT — see [LICENSE](LICENSE)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 CData Software, Inc.
|
|
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,82 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from .connection import Connection
|
|
4
|
+
from .exceptions import (
|
|
5
|
+
ConfigurationError,
|
|
6
|
+
DatabaseError,
|
|
7
|
+
DataError,
|
|
8
|
+
Error,
|
|
9
|
+
IntegrityError,
|
|
10
|
+
InterfaceError,
|
|
11
|
+
InternalError,
|
|
12
|
+
NotSupportedError,
|
|
13
|
+
OperationalError,
|
|
14
|
+
ProgrammingError,
|
|
15
|
+
Warning,
|
|
16
|
+
)
|
|
17
|
+
from .util.types import (
|
|
18
|
+
DBAPI_TYPE_STRING,
|
|
19
|
+
DBAPI_TYPE_BINARY,
|
|
20
|
+
DBAPI_TYPE_NUMBER,
|
|
21
|
+
DBAPI_TYPE_TIMESTAMP,
|
|
22
|
+
Date,
|
|
23
|
+
Time,
|
|
24
|
+
Timestamp,
|
|
25
|
+
Binary,
|
|
26
|
+
DateFromTicks,
|
|
27
|
+
TimeFromTicks,
|
|
28
|
+
TimestampFromTicks,
|
|
29
|
+
)
|
|
30
|
+
from .version import __version__
|
|
31
|
+
|
|
32
|
+
# PEP 249 mandatory module-level type objects
|
|
33
|
+
STRING = DBAPI_TYPE_STRING # 0
|
|
34
|
+
BINARY = DBAPI_TYPE_BINARY # 1
|
|
35
|
+
NUMBER = DBAPI_TYPE_NUMBER # 2
|
|
36
|
+
DATETIME = DBAPI_TYPE_TIMESTAMP # 3
|
|
37
|
+
ROWID = DBAPI_TYPE_STRING # No dedicated ROWID type; STRING is the standard fallback
|
|
38
|
+
|
|
39
|
+
# DB API 2.0 module attributes
|
|
40
|
+
apilevel = "2.0"
|
|
41
|
+
threadsafety = 1
|
|
42
|
+
paramstyle = "pyformat"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def connect(
|
|
46
|
+
config_path: Optional[str] = None,
|
|
47
|
+
base_url: Optional[str] = None,
|
|
48
|
+
username: Optional[str] = None,
|
|
49
|
+
password: Optional[str] = None,
|
|
50
|
+
workspace: Optional[str] = None,
|
|
51
|
+
timeout: int = 30,
|
|
52
|
+
max_retries: int = 3,
|
|
53
|
+
retry_delay: float = 1.0,
|
|
54
|
+
) -> Connection:
|
|
55
|
+
"""
|
|
56
|
+
Create a connection to the CData Connect API.
|
|
57
|
+
|
|
58
|
+
:param base_url: The base URL of the CData Connect API.
|
|
59
|
+
:param username: The username for authentication.
|
|
60
|
+
:param password: The password for authentication.
|
|
61
|
+
:param config_path: Optional path to a pyhocon config file.
|
|
62
|
+
:param workspace: Optional workspace name to append as a query parameter.
|
|
63
|
+
:param timeout: HTTP request timeout in seconds. Default 30.
|
|
64
|
+
:param max_retries: Retry count for transient 5xx errors. Default 3.
|
|
65
|
+
:param retry_delay: Base seconds between retries (exponential backoff). Default 1.0.
|
|
66
|
+
:return: A Connection object.
|
|
67
|
+
"""
|
|
68
|
+
if not config_path and not (base_url and username and password):
|
|
69
|
+
raise InterfaceError(
|
|
70
|
+
"Either config_path or base_url, username, and password must be provided."
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
return Connection(
|
|
74
|
+
config_path=config_path,
|
|
75
|
+
base_url=base_url,
|
|
76
|
+
username=username,
|
|
77
|
+
password=password,
|
|
78
|
+
workspace=workspace,
|
|
79
|
+
timeout=timeout,
|
|
80
|
+
max_retries=max_retries,
|
|
81
|
+
retry_delay=retry_delay,
|
|
82
|
+
)
|