fastmssql 0.4.2__cp310-cp310-manylinux_2_28_x86_64.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.
|
Binary file
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastmssql
|
|
3
|
+
Version: 0.4.2
|
|
4
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
5
|
+
Classifier: Intended Audience :: Developers
|
|
6
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
7
|
+
Classifier: Operating System :: OS Independent
|
|
8
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
9
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
10
|
+
Classifier: Operating System :: MacOS
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Programming Language :: Rust
|
|
19
|
+
Classifier: Topic :: Database
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Dist: pytest>=8.4.2 ; extra == 'dev'
|
|
22
|
+
Requires-Dist: pytest-asyncio>=1.2.0 ; extra == 'dev'
|
|
23
|
+
Requires-Dist: psutil>=7.1.1 ; extra == 'dev'
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Summary: A high-performance async Python library for Microsoft SQL Server built on Rust for heavy workloads and low latency.
|
|
27
|
+
Author-email: Riveranda <riverb514@gmail.com>
|
|
28
|
+
License: GPL-3.0-or-later OR Commercial
|
|
29
|
+
Requires-Python: >=3.9
|
|
30
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
31
|
+
Project-URL: Homepage, https://github.com/Rivendael/FastMssql
|
|
32
|
+
Project-URL: Repository, https://github.com/Rivendael/FastMssql
|
|
33
|
+
Project-URL: Bug Tracker, https://github.com/Rivendael/FastMssql/issues
|
|
34
|
+
Project-URL: Documentation, https://github.com/Rivendael/FastMssql#readme
|
|
35
|
+
|
|
36
|
+
# FastMSSQL ⚡
|
|
37
|
+
|
|
38
|
+
FastMSSQL is an async Python library for Microsoft SQL Server (MSSQL), built in Rust.
|
|
39
|
+
Unlike pyodbc or pymssql, it uses a native SQL Server client—no ODBC required—simplifying installation on Windows, macOS, and Linux.
|
|
40
|
+
Great for data ingestion, bulk inserts, and large-scale query workloads.
|
|
41
|
+
|
|
42
|
+
[](https://pypi.org/project/fastmssql/)
|
|
43
|
+
[](https://github.com/Rivendael/fastmssql)
|
|
44
|
+
|
|
45
|
+
[](LICENSE)
|
|
46
|
+
|
|
47
|
+
[](https://github.com/Rivendael/fastmssql/actions/workflows/build.yml)
|
|
48
|
+
|
|
49
|
+
[](https://github.com/Rivendael/fastmssql/releases)
|
|
50
|
+
|
|
51
|
+
[](https://github.com/Rivendael/fastmssql)
|
|
52
|
+
|
|
53
|
+
[](https://github.com/Rivendael/pymssql-rs)
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
- High performance: optimized for very high RPS and low overhead
|
|
58
|
+
- Rust core: memory‑safe and reliable, tuned Tokio runtime
|
|
59
|
+
- No ODBC: native SQL Server client, no external drivers needed
|
|
60
|
+
- Connection pooling: bb8‑based, smart defaults (default max_size=10, min_idle=2)
|
|
61
|
+
- Async first: clean async/await API with `async with` context managers
|
|
62
|
+
- Strong typing: fast conversions for common SQL Server types
|
|
63
|
+
- Thread‑safe: safe to use in concurrent apps
|
|
64
|
+
- Cross‑platform: Windows, macOS, Linux
|
|
65
|
+
- Batch operations: high-performance bulk inserts and batch query execution
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## Key API methods
|
|
69
|
+
|
|
70
|
+
Core methods for individual operations:
|
|
71
|
+
|
|
72
|
+
- `query()` — SELECT statements that return rows
|
|
73
|
+
- `execute()` — INSERT/UPDATE/DELETE/DDL that return affected row count
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
# Use query() for SELECT statements
|
|
77
|
+
result = await conn.query("SELECT * FROM users WHERE age > @P1", [25])
|
|
78
|
+
rows = result.rows()
|
|
79
|
+
|
|
80
|
+
# Use execute() for data modification
|
|
81
|
+
affected = await conn.execute("INSERT INTO users (name) VALUES (@P1)", ["John"])
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
|
|
87
|
+
### From PyPI (recommended)
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pip install fastmssql
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Prerequisites
|
|
94
|
+
|
|
95
|
+
- Python 3.9 to 3.14
|
|
96
|
+
- Microsoft SQL Server (any recent version)
|
|
97
|
+
|
|
98
|
+
## Quick start
|
|
99
|
+
|
|
100
|
+
### Basic async usage
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
import asyncio
|
|
104
|
+
from fastmssql import Connection
|
|
105
|
+
|
|
106
|
+
async def main():
|
|
107
|
+
conn_str = "Server=localhost;Database=master;User Id=myuser;Password=mypass"
|
|
108
|
+
async with Connection(conn_str) as conn:
|
|
109
|
+
# SELECT: use query() -> rows()
|
|
110
|
+
result = await conn.query("SELECT @@VERSION as version")
|
|
111
|
+
for row in result.rows():
|
|
112
|
+
print(row['version'])
|
|
113
|
+
|
|
114
|
+
# Pool statistics (tuple: connected, connections, idle, max_size, min_idle)
|
|
115
|
+
connected, connections, idle, max_size, min_idle = await conn.pool_stats()
|
|
116
|
+
print(f"Pool: connected={connected}, size={connections}/{max_size}, idle={idle}, min_idle={min_idle}")
|
|
117
|
+
|
|
118
|
+
asyncio.run(main())
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Explicit Connection Management
|
|
122
|
+
|
|
123
|
+
When not utilizing Python's context manager (async with), **FastMssql** uses *lazy connection initialization*:
|
|
124
|
+
if you call `query()` or `execute()` on a new `Connection`, the underlying pool is created if not already present.
|
|
125
|
+
|
|
126
|
+
For more control, you can explicitly connect and disconnect:
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
import asyncio
|
|
130
|
+
from fastmssql import Connection
|
|
131
|
+
|
|
132
|
+
async def main():
|
|
133
|
+
conn_str = "Server=localhost;Database=master;User Id=myuser;Password=mypass"
|
|
134
|
+
conn = Connection(conn_str)
|
|
135
|
+
|
|
136
|
+
# Explicitly connect
|
|
137
|
+
await conn.connect()
|
|
138
|
+
assert await conn.is_connected()
|
|
139
|
+
|
|
140
|
+
# Run queries
|
|
141
|
+
result = await conn.query("SELECT 42 as answer")
|
|
142
|
+
print(result.rows()[0]["answer"]) # -> 42
|
|
143
|
+
|
|
144
|
+
# Explicitly disconnect
|
|
145
|
+
await conn.disconnect()
|
|
146
|
+
assert not await conn.is_connected()
|
|
147
|
+
|
|
148
|
+
asyncio.run(main())
|
|
149
|
+
```
|
|
150
|
+
## Usage
|
|
151
|
+
|
|
152
|
+
### Connection options
|
|
153
|
+
|
|
154
|
+
You can connect either with a connection string or individual parameters.
|
|
155
|
+
|
|
156
|
+
1) Connection string
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
import asyncio
|
|
160
|
+
from fastmssql import Connection
|
|
161
|
+
|
|
162
|
+
async def main():
|
|
163
|
+
conn_str = "Server=localhost;Database=master;User Id=myuser;Password=mypass"
|
|
164
|
+
async with Connection(connection_string=conn_str) as conn:
|
|
165
|
+
rows = (await conn.query("SELECT DB_NAME() as db")).rows()
|
|
166
|
+
print(rows[0]['db'])
|
|
167
|
+
|
|
168
|
+
asyncio.run(main())
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
2) Individual parameters
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
import asyncio
|
|
175
|
+
from fastmssql import Connection
|
|
176
|
+
|
|
177
|
+
async def main():
|
|
178
|
+
async with Connection(
|
|
179
|
+
server="localhost",
|
|
180
|
+
database="master",
|
|
181
|
+
username="myuser",
|
|
182
|
+
password="mypassword"
|
|
183
|
+
) as conn:
|
|
184
|
+
rows = (await conn.query("SELECT SUSER_SID() as sid")).rows()
|
|
185
|
+
print(rows[0]['sid'])
|
|
186
|
+
|
|
187
|
+
asyncio.run(main())
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Note: Windows authentication (Trusted Connection) is currently not supported. Use SQL authentication (username/password).
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
### Working with data
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
import asyncio
|
|
197
|
+
from fastmssql import Connection
|
|
198
|
+
|
|
199
|
+
async def main():
|
|
200
|
+
async with Connection("Server=.;Database=MyDB;User Id=sa;Password=StrongPwd;") as conn:
|
|
201
|
+
# SELECT (returns rows)
|
|
202
|
+
users = (await conn.query(
|
|
203
|
+
"SELECT id, name, email FROM users WHERE active = 1"
|
|
204
|
+
)).rows()
|
|
205
|
+
for u in users:
|
|
206
|
+
print(f"User {u['id']}: {u['name']} ({u['email']})")
|
|
207
|
+
|
|
208
|
+
# INSERT / UPDATE / DELETE (returns affected row count)
|
|
209
|
+
inserted = await conn.execute(
|
|
210
|
+
"INSERT INTO users (name, email) VALUES (@P1, @P2)",
|
|
211
|
+
["Jane", "jane@example.com"],
|
|
212
|
+
)
|
|
213
|
+
print(f"Inserted {inserted} row(s)")
|
|
214
|
+
|
|
215
|
+
updated = await conn.execute(
|
|
216
|
+
"UPDATE users SET last_login = GETDATE() WHERE id = @P1",
|
|
217
|
+
[123],
|
|
218
|
+
)
|
|
219
|
+
print(f"Updated {updated} row(s)")
|
|
220
|
+
|
|
221
|
+
asyncio.run(main())
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Parameters use positional placeholders: `@P1`, `@P2`, ... Provide values as a list in the same order.
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
### Batch operations
|
|
228
|
+
|
|
229
|
+
For high-throughput scenarios, use batch methods to reduce network round-trips:
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
import asyncio
|
|
233
|
+
from fastmssql import Connection
|
|
234
|
+
|
|
235
|
+
async def main_fetching():
|
|
236
|
+
# Replace with your actual connection string
|
|
237
|
+
async with Connection("Server=.;Database=MyDB;User Id=sa;Password=StrongPwd;") as conn:
|
|
238
|
+
|
|
239
|
+
# --- 1. Prepare Data for Demonstration ---
|
|
240
|
+
columns = ["name", "email", "age"]
|
|
241
|
+
data_rows = [
|
|
242
|
+
["Alice Johnson", "alice@example.com", 28],
|
|
243
|
+
["Bob Smith", "bob@example.com", 32],
|
|
244
|
+
["Carol Davis", "carol@example.com", 25],
|
|
245
|
+
["David Lee", "david@example.com", 35],
|
|
246
|
+
["Eva Green", "eva@example.com", 29]
|
|
247
|
+
]
|
|
248
|
+
await conn.bulk_insert("users", columns, data_rows)
|
|
249
|
+
|
|
250
|
+
# --- 2. Execute Query and Retrieve the Result Object ---
|
|
251
|
+
print("\n--- Result Object Fetching (fetchone, fetchmany, fetchall) ---")
|
|
252
|
+
|
|
253
|
+
# The Result object is returned after the awaitable query executes.
|
|
254
|
+
result = await conn.query("SELECT name, age FROM users ORDER BY age DESC")
|
|
255
|
+
|
|
256
|
+
# fetchone(): Retrieves the next single row synchronously.
|
|
257
|
+
oldest_user = result.fetchone()
|
|
258
|
+
if oldest_user:
|
|
259
|
+
print(f"1. fetchone: Oldest user is {oldest_user['name']} (Age: {oldest_user['age']})")
|
|
260
|
+
|
|
261
|
+
# fetchmany(2): Retrieves the next set of rows synchronously.
|
|
262
|
+
next_two_users = result.fetchmany(2)
|
|
263
|
+
print(f"2. fetchmany: Retrieved {len(next_two_users)} users: {[r['name'] for r in next_two_users]}.")
|
|
264
|
+
|
|
265
|
+
# fetchall(): Retrieves all remaining rows synchronously.
|
|
266
|
+
remaining_users = result.fetchall()
|
|
267
|
+
print(f"3. fetchall: Retrieved all {len(remaining_users)} remaining users: {[r['name'] for r in remaining_users]}.")
|
|
268
|
+
|
|
269
|
+
# Exhaustion Check: Subsequent calls return None/[]
|
|
270
|
+
print(f"4. Exhaustion Check (fetchone): {result.fetchone()}")
|
|
271
|
+
print(f"5. Exhaustion Check (fetchmany): {result.fetchmany(1)}")
|
|
272
|
+
|
|
273
|
+
# --- 3. Batch Commands for multiple operations ---
|
|
274
|
+
print("\n--- Batch Commands (execute_batch) ---")
|
|
275
|
+
commands = [
|
|
276
|
+
("UPDATE users SET last_login = GETDATE() WHERE name = @P1", ["Alice Johnson"]),
|
|
277
|
+
("INSERT INTO user_logs (action, user_name) VALUES (@P1, @P2)", ["login", "Alice Johnson"])
|
|
278
|
+
]
|
|
279
|
+
|
|
280
|
+
affected_counts = await conn.execute_batch(commands)
|
|
281
|
+
print(f"Updated {affected_counts[0]} users, inserted {affected_counts[1]} logs")
|
|
282
|
+
|
|
283
|
+
asyncio.run(main_fetching())
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Connection pooling
|
|
287
|
+
|
|
288
|
+
Tune the pool to fit your workload. Constructor signature:
|
|
289
|
+
|
|
290
|
+
```python
|
|
291
|
+
from fastmssql import PoolConfig
|
|
292
|
+
|
|
293
|
+
# PoolConfig(max_size=10, min_idle=2, max_lifetime_secs=None, idle_timeout_secs=None, connection_timeout_secs=30)
|
|
294
|
+
config = PoolConfig(
|
|
295
|
+
max_size=20, # max connections in pool
|
|
296
|
+
min_idle=5, # keep at least this many idle
|
|
297
|
+
max_lifetime_secs=3600, # recycle connections after 1h
|
|
298
|
+
idle_timeout_secs=600, # close idle connections after 10m
|
|
299
|
+
connection_timeout_secs=30
|
|
300
|
+
)
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
Presets:
|
|
304
|
+
|
|
305
|
+
```python
|
|
306
|
+
high = PoolConfig.high_throughput() # ~ max_size=50, min_idle=15
|
|
307
|
+
low = PoolConfig.low_resource() # ~ max_size=3, min_idle=1
|
|
308
|
+
dev = PoolConfig.development() # ~ max_size=5, min_idle=1
|
|
309
|
+
maxp = PoolConfig.maximum_performance() # ~ max_size=100, min_idle=30
|
|
310
|
+
ultra = PoolConfig.ultra_high_concurrency() # ~ max_size=200, min_idle=50
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Apply to a connection:
|
|
314
|
+
|
|
315
|
+
```python
|
|
316
|
+
async with Connection(conn_str, pool_config=high) as conn:
|
|
317
|
+
rows = (await conn.query("SELECT 1 AS ok")).rows()
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Default pool (if omitted): `max_size=10`, `min_idle=2`.
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
### SSL/TLS
|
|
324
|
+
|
|
325
|
+
```python
|
|
326
|
+
from fastmssql import SslConfig, EncryptionLevel, Connection
|
|
327
|
+
|
|
328
|
+
ssl = SslConfig(
|
|
329
|
+
encryption_level=EncryptionLevel.REQUIRED, # or "Required"
|
|
330
|
+
trust_server_certificate=False,
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
async with Connection(conn_str, ssl_config=ssl) as conn:
|
|
334
|
+
...
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Helpers:
|
|
338
|
+
|
|
339
|
+
- `SslConfig.development()` – encrypt, trust all (dev only)
|
|
340
|
+
- `SslConfig.with_ca_certificate(path)` – use custom CA
|
|
341
|
+
- `SslConfig.login_only()` / `SslConfig.disabled()` – legacy modes
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
## Performance tips
|
|
345
|
+
|
|
346
|
+
For maximum throughput in highly concurrent scenarios, use multiple `Connection` instances (each with its own pool) and batch your work:
|
|
347
|
+
|
|
348
|
+
```python
|
|
349
|
+
import asyncio
|
|
350
|
+
from fastmssql import Connection, PoolConfig
|
|
351
|
+
|
|
352
|
+
async def worker(conn_str, cfg):
|
|
353
|
+
async with Connection(conn_str, pool_config=cfg) as conn:
|
|
354
|
+
for _ in range(1000):
|
|
355
|
+
_ = (await conn.query("SELECT 1 as v")).rows()
|
|
356
|
+
|
|
357
|
+
async def main():
|
|
358
|
+
conn_str = "Server=.;Database=master;User Id=sa;Password=StrongPwd;"
|
|
359
|
+
cfg = PoolConfig.high_throughput()
|
|
360
|
+
await asyncio.gather(*[asyncio.create_task(worker(conn_str, cfg)) for _ in range(32)])
|
|
361
|
+
|
|
362
|
+
asyncio.run(main())
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
## Examples & benchmarks
|
|
367
|
+
|
|
368
|
+
- Examples: `examples/comprehensive_example.py`
|
|
369
|
+
- Benchmarks: `benchmarks/` (MIT licensed)
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
## Troubleshooting
|
|
373
|
+
|
|
374
|
+
- Import/build: ensure Rust toolchain and `maturin` are installed if building from source
|
|
375
|
+
- Connection: verify connection string; Windows auth not supported
|
|
376
|
+
- Timeouts: increase pool size or tune `connection_timeout_secs`
|
|
377
|
+
- Parameters: use `@P1, @P2, ...` and pass a list of values
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
## Contributing
|
|
381
|
+
|
|
382
|
+
Contributions are welcome. Please open an issue or PR.
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
## License
|
|
386
|
+
|
|
387
|
+
FastMSSQL is dual‑licensed:
|
|
388
|
+
|
|
389
|
+
- GPL‑3.0 (for open source projects)
|
|
390
|
+
- Commercial (for proprietary use). Contact: riverb514@gmail.com
|
|
391
|
+
|
|
392
|
+
See the [LICENSE](LICENSE) file for details.
|
|
393
|
+
|
|
394
|
+
### Examples and Benchmarks
|
|
395
|
+
|
|
396
|
+
- `examples/` and `benchmarks/` are under the MIT License. See files in `licenses/`.
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
## Third‑party attributions
|
|
400
|
+
|
|
401
|
+
Built on excellent open source projects: Tiberius, PyO3, pyo3‑asyncio, bb8, tokio, serde, pytest, maturin, and more. See `licenses/NOTICE.txt` for the full list. The full texts of Apache‑2.0 and MIT are in `licenses/`.
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
## Acknowledgments
|
|
405
|
+
|
|
406
|
+
Thanks to the maintainers of Tiberius, PyO3, pyo3‑asyncio, Tokio, pytest, maturin, and the broader open source community.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
fastmssql/__init__.py,sha256=H2sCgkVlgRo3oIbejLqnHUIsFCqcbJIc20TJ4CCPkQo,43543
|
|
2
|
+
fastmssql/fastmssql.cpython-310-x86_64-linux-gnu.so,sha256=-6egnqPDapqQDpifljxbgp2q1VvHH-5QT5sj8Bz9Yvc,2651616
|
|
3
|
+
fastmssql-0.4.2.dist-info/METADATA,sha256=TC5Fo8TolV0uQ8UQu0VJo-vbWy5wsYfuji4rNAQhlRE,13729
|
|
4
|
+
fastmssql-0.4.2.dist-info/WHEEL,sha256=QOwyhFjeU03iwd0TNwaY85yHYVtSAI5FB0ZbI6zffpo,110
|
|
5
|
+
fastmssql-0.4.2.dist-info/RECORD,,
|
|
6
|
+
fastmssql-0.4.2.dist-info/licenses/LICENSE,sha256=OHj2nKice3tSk2Us200EWXDpwDKtAzeOu4NF4rwg5gk,33858
|