You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PyMongoSQL is a Python [DB API 2.0 (PEP 249)](https://www.python.org/dev/peps/pep-0249/) client for [MongoDB](https://www.mongodb.com/). It provides a familiar SQL interface to MongoDB, allowing developers to use SQL queries to interact with MongoDB collections.
12
+
PyMongoSQL is a Python [DB API 2.0 (PEP 249)](https://www.python.org/dev/peps/pep-0249/) client for [MongoDB](https://www.mongodb.com/). It provides a familiar SQL interface to MongoDB, allowing developers to use SQL to interact with MongoDB collections.
13
13
14
14
## Objectives
15
15
16
16
PyMongoSQL implements the DB API 2.0 interfaces to provide SQL-like access to MongoDB. The project aims to:
17
17
18
-
- Bridge the gap between SQL and NoSQL by providing SQL query capabilities for MongoDB
18
+
- Bridge the gap between SQL and NoSQL by providing SQL capabilities for MongoDB
19
19
- Support standard SQL DQL (Data Query Language) operations including SELECT statements with WHERE, ORDER BY, and LIMIT clauses
20
20
- Provide seamless integration with existing Python applications that expect DB API 2.0 compliance
21
21
- Enable easy migration from traditional SQL databases to MongoDB
22
-
- Support field aliasing and projection mapping for flexible result set handling
23
-
- Maintain high performance through direct `db.command()` execution instead of high-level APIs
24
22
25
23
## Features
26
24
27
25
-**DB API 2.0 Compliant**: Full compatibility with Python Database API 2.0 specification
26
+
-**SQLAlchemy Integration**: Complete ORM and Core support with dedicated MongoDB dialect
28
27
-**SQL Query Support**: SELECT statements with WHERE conditions, field selection, and aliases
29
-
-**MongoDB Native Integration**: Direct `db.command()` execution for optimal performance
30
28
-**Connection String Support**: MongoDB URI format for easy configuration
31
-
-**Result Set Handling**: Support for `fetchone()`, `fetchmany()`, and `fetchall()` operations
32
-
-**Field Aliasing**: SQL-style field aliases with automatic projection mapping
33
-
-**Context Manager Support**: Automatic resource management with `with` statements
34
-
-**Transaction Ready**: Architecture designed for future DML operation support (INSERT, UPDATE, DELETE)
35
29
36
30
## Requirements
37
31
38
32
-**Python**: 3.9, 3.10, 3.11, 3.12, 3.13+
39
-
-**MongoDB**: 4.0+
33
+
-**MongoDB**: 7.0+
40
34
41
35
## Dependencies
42
36
@@ -46,6 +40,11 @@ PyMongoSQL implements the DB API 2.0 interfaces to provide SQL-like access to Mo
46
40
-**ANTLR4** (SQL Parser Runtime)
47
41
- antlr4-python3-runtime >= 4.13.0
48
42
43
+
### Optional Dependencies
44
+
45
+
-**SQLAlchemy** (for ORM/Core support)
46
+
- sqlalchemy >= 1.4.0 (SQLAlchemy 1.4+ and 2.0+ supported)
47
+
49
48
## Installation
50
49
51
50
```bash
@@ -70,7 +69,7 @@ from pymongosql import connect
70
69
# Connect to MongoDB
71
70
connection = connect(
72
71
host="mongodb://localhost:27017",
73
-
database="test_db"
72
+
database="database"
74
73
)
75
74
76
75
cursor = connection.cursor()
@@ -100,44 +99,19 @@ for row in cursor:
100
99
```python
101
100
from pymongosql import connect
102
101
103
-
with connect(host="mongodb://localhost:27017", database="mydb") as conn:
102
+
with connect(host="mongodb://localhost:27017/database") as conn:
104
103
with conn.cursor() as cursor:
105
104
cursor.execute('SELECT COUNT(*) as total FROM users')
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
0 commit comments