Skip to content

Commit 0639734

Browse files
committed
Merged PR 5852: SYNC: Github main to ADO main
Syncing Github main to ADO main Related work items: #38037
1 parent 899eb53 commit 0639734

File tree

115 files changed

+12165
-2976
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+12165
-2976
lines changed

.gitignore

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
# Ignore all files in the pybind/build directory
22
mssql_python/pybind/build/
33

4-
mssql_python/pybind/pymsbuild/build/
5-
6-
# Ignore pyd file
7-
mssql_python/ddbc_bindings.pyd
8-
94
# Ignore pycache files and folders
105
__pycache__/
116
**/__pycache__/
@@ -28,4 +23,27 @@ test-*.xml
2823

2924
# Ignore the build & mssql_python.egg-info directories
3025
build/
31-
mssql_python.egg-info/
26+
mssql_python.egg-info/
27+
28+
# Python bytecode
29+
__pycache__/
30+
*.py[cod]
31+
*$py.class
32+
33+
# Distribution / packaging
34+
dist/
35+
build/
36+
*.egg-info/
37+
38+
# C extensions
39+
*.so
40+
*.pyd
41+
*.pdb
42+
43+
# IDE files
44+
.vscode/
45+
.idea/
46+
*.swp
47+
48+
# .DS_Store files
49+
.DS_Store

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
9+
### Added
10+
- New feature: Support for macOS and Linux.
11+
- Documentation: Added API documentation in the Wiki.
12+
13+
### Changed
14+
- Improved error handling in the connection module.
15+
16+
### Fixed
17+
- Bug fix: Resolved issue with connection timeout.
18+
19+
## [1.0.0-alpha] - 2025-02-24
20+
21+
### Added
22+
- Initial release of the mssql-python driver for SQL Server.
23+
24+
### Changed
25+
- N/A
26+
27+
### Fixed
28+
- N/A

CODE_OF_CONDUCT.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Microsoft Open Source Code of Conduct
2+
3+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4+
5+
Resources:
6+
7+
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8+
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9+
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Contributing to mssql-python
2+
3+
This project welcomes contributions and suggestions. Most contributions require you to
4+
agree to a Contributor License Agreement (CLA) declaring that you have the right to,
5+
and actually do, grant us the rights to use your contribution. For details, visit
6+
https://cla.microsoft.com.
7+
8+
When you submit a pull request, a CLA-bot will automatically determine whether you need
9+
to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the
10+
instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
11+
12+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
13+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
14+
or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

LICENSE

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
MIT License
2+
All files licensed under the MIT license except the dynamic-link libraries (DLLs) in the mssql_python\libs\win folder,
3+
which are subject to different licensing terms. Please review the licensing details for each component below.
4+
5+
A. MIT License
6+
==================================================================
7+
Copyright (c) Microsoft Corporation.
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE
26+
27+
28+
B. MICROSOFT LICENSES
29+
==================================================================
30+
The following dynamic-link libraries (DLLs) in the mssql_python\libs\win folder fall under different Microsoft licenses.
31+
Below is a breakdown of these components by their respective licenses.
32+
33+
1. Microsoft ODBC Driver 18 End User License Agreement (EULA)
34+
These components are part of the Microsoft ODBC Driver 18 for SQL Server and are governed by the Microsoft ODBC Driver 18 EULA.
35+
36+
- msodbcsqlr18.rll: Resource library containing localized error messages for the ODBC driver.
37+
- msodbcdiag18.dll: Diagnostic library for handling error reporting and troubleshooting.
38+
- msodbcsql18.dll: Core ODBC driver enabling connectivity between SQL Server and applications.
39+
40+
For official licensing terms, refer to: mssql_python\libs\win\MICROSOFT_ODBC_DRIVER_FOR_SQL_SERVER_LICENSE.txt
41+
42+
2. Microsoft Visual C++ Redistributable EULA
43+
These components are part of the Microsoft Visual C++ Redistributable and are governed by the Microsoft Visual C++ Redistributable EULA.
44+
45+
- msvcp140.dll: Microsoft C++ Standard Library runtime, required for running C++ applications.
46+
47+
For redistribution and usage terms, refer to: mssql_python\libs\win\libs\win\MICROSOFT_VISUAL_STUDIO_LICENSE.txt

PyPI_Description.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# mssql-python
2+
3+
This is a new Python driver for Microsoft SQL Server currently in Alpha phase.
4+
5+
## Public Preview Release
6+
7+
We are making progress - The Public Preview of our driver is now available! This marks a significant milestone in our development journey. While we saw a few early adopters of our alpha release, we are introducing the following functionalities to support your applications in a more robust and reliable manner.
8+
9+
### What's Included:
10+
11+
- Everything from previous releases
12+
- **Azure Active Directory Authentication:** New authentication module supporting Azure AD login options (ActiveDirectoryInteractive, ActiveDirectoryDeviceCode, ActiveDirectoryDefault) for secure and flexible cloud integration.
13+
- **Batch Execution Performance:** Refactored `executemany` for efficient bulk operations and improved C++ bindings for performance.
14+
- **Robust Logging System:** Overhauled logging with a singleton manager, sensitive data sanitization, and better exception handling.
15+
- **Improved Row Representation:** Enhanced output and debugging via updated `Row` object string and representation methods.
16+
17+
For more information, please visit the project link on Github: https://github.com/microsoft/mssql-python
18+
19+
### What's Next:
20+
21+
As we continue to develop and refine the driver, you can expect regular updates that will introduce new features, optimizations, and bug fixes. We encourage you to contribute, provide feedback and report any issues you encounter, as this will help us improve the driver for the final release.
22+
23+
### Stay Tuned:
24+
25+
We appreciate your interest and support in this project. Stay tuned for more updates and enhancements as we work towards delivering a robust and fully-featured driver in coming months.
26+
Thank you for being a part of our journey!

README.md

Lines changed: 126 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,132 @@
1-
# mssql-python
1+
# Microsoft Python Driver for SQL Server
2+
3+
**mssql-python** is a Python driver for Microsoft SQL Server and the Azure SQL family of databases. It leverages Direct Database Connectivity (DDBC) that enables direct connections to SQL Server without requiring an external driver manager. Designed to comply with the [DB API 2.0](https://peps.python.org/pep-0249/) specification, this driver also introduces Pythonic enhancements for improved usability and functionality. It supports a full range of database operations, including connection management, query execution, and transaction handling.
4+
5+
The driver is compatible with all the Python versions >= 3.10
6+
7+
[Documentation](https://github.com/microsoft/mssql-python/wiki) | [Release Notes](https://github.com/microsoft/mssql-python/releases) | [Roadmap](https://github.com/microsoft/mssql-python/blob/main/ROADMAP.md)
8+
9+
> **Note:**
10+
> This project is currently in Public Preview, meaning it is still under active development. We are working on core functionalities and gathering more feedback before GA. Please use with caution and avoid production environments.
11+
>
12+
## Installation
13+
14+
**Windows:** mssql-python can be installed with [pip](http://pypi.python.org/pypi/pip)
15+
```bash
16+
pip install mssql-python
17+
```
18+
**MacOS:** mssql-python can be installed with [pip](http://pypi.python.org/pypi/pip)
19+
```bash
20+
brew install openssl
21+
pip install mssql-python
22+
```
23+
**Linux:** mssql-python can be installed with [pip](http://pypi.python.org/pypi/pip)
24+
```bash
25+
pip install mssql-python
26+
```
227

3-
This is a new Python driver for Microsoft SQL Server currently in Alpha phase.
28+
## Key Features
29+
### Supported Platforms
30+
31+
Windows, MacOS and Linux (manylinux2014 - Debian, Ubuntu & RHEL)
432

5-
## Alpha Version Release
33+
> **Note:**
34+
> Support for additional Linux OSs (Alpine, SUSE Linux) will come soon
35+
>
36+
37+
### DBAPI v2.0 Compliance
38+
39+
The Microsoft **mssql-python** module is designed to be fully compliant with the DB API 2.0 specification. This ensures that the driver adheres to a standardized interface for database access in Python, providing consistency and reliability across different database systems. Key aspects of DBAPI v2.0 compliance include:
40+
41+
- **Connection Objects**: Establishing and managing connections to the database.
42+
- **Cursor Objects**: Executing SQL commands and retrieving results.
43+
- **Transaction Management**: Supporting commit and rollback operations to ensure data integrity.
44+
- **Error Handling**: Providing a consistent set of exceptions for handling database errors.
45+
- **Parameter Substitution**: Allowing the use of placeholders in SQL queries to prevent SQL injection attacks.
46+
47+
By adhering to the DB API 2.0 specification, the mssql-python module ensures compatibility with a wide range of Python applications and frameworks, making it a versatile choice for developers working with Microsoft SQL Server, Azure SQL Database, and Azure SQL Managed Instance.
48+
49+
### Support for Microsoft Entra ID Authentication
50+
51+
The Microsoft mssql-python driver enables Python applications to connect to Microsoft SQL Server, Azure SQL Database, or Azure SQL Managed Instance using Microsoft Entra ID identities. It supports a variety of authentication methods, including username and password, Microsoft Entra managed identity (system-assigned and user-assigned), Integrated Windows Authentication in a federated, domain-joined environment, interactive authentication via browser, device code flow for environments without browser access, and the default authentication method based on environment and configuration. This flexibility allows developers to choose the most suitable authentication approach for their deployment scenario.
652

7-
We are excited to announce the release of the alpha version of our driver. This marks a significant milestone in our development journey. While this version is still in the early stages, it includes the foundational code and initial logic that will drive future enhancements.
53+
EntraID authentication is now fully supported on MacOS and Linux but with certain limitations as mentioned in the table:
854

9-
### What's Included:
55+
| Authentication Method | Windows Support | macOS/Linux Support | Notes |
56+
|----------------------|----------------|---------------------|-------|
57+
| ActiveDirectoryPassword | ✅ Yes | ✅ Yes | Username/password-based authentication |
58+
| ActiveDirectoryInteractive | ✅ Yes | ✅ Yes | Interactive login via browser; requires user interaction |
59+
| ActiveDirectoryMSI (Managed Identity) | ✅ Yes | ✅ Yes | For Azure VMs/containers with managed identity |
60+
| ActiveDirectoryServicePrincipal | ✅ Yes | ✅ Yes | Use client ID and secret or certificate |
61+
| ActiveDirectoryIntegrated | ✅ Yes | ❌ No | Only works on Windows (requires Kerberos/SSPI) |
62+
| ActiveDirectoryDeviceCode | ✅ Yes | ✅ Yes | Device code flow for authentication; suitable for environments without browser access |
63+
| ActiveDirectoryDefault | ✅ Yes | ✅ Yes | Uses default authentication method based on environment and configuration |
1064

11-
Basic functionality to get you started
12-
Initial implementation of core features
13-
Placeholder for future improvements and updates
65+
**NOTE**:
66+
- **Access Token**: the connection string **must not** contain `UID`, `PWD`, `Authentication`, or `Trusted_Connection` keywords.
67+
- **Device Code**: make sure to specify a `Connect Timeout` that provides enough time to go through the device code flow authentication process.
68+
- **Default**: Ensure you're authenticated via az login, or running within a managed identity-enabled environment.
1469

15-
### What's Next:
16-
17-
As we continue to develop and refine the driver, you can expect regular updates that will introduce new features, optimizations, and bug fixes. We encourage you to provide feedback and report any issues you encounter, as this will help us improve the driver for the final release.
18-
19-
### Stay Tuned:
20-
21-
We appreciate your interest and support in this project. Stay tuned for more updates and enhancements as we work towards delivering a robust and fully-featured driver in coming months.
22-
Thank you for being a part of our journey!
70+
### Enhanced Pythonic Features
71+
72+
The driver offers a suite of Pythonic enhancements that streamline database interactions, making it easier for developers to execute queries, manage connections, and handle data more efficiently.
73+
74+
### Connection Pooling
75+
76+
The Microsoft mssql_python driver provides built-in support for connection pooling, which helps improve performance and scalability by reusing active database connections instead of creating a new connection for every request. This feature is enabled by default. For more information, refer [Connection Pooling Wiki](https://github.com/microsoft/mssql-python/wiki/Connection#connection-pooling).
77+
78+
## Getting Started Examples
79+
Connect to SQL Server and execute a simple query:
80+
81+
```python
82+
import mssql_python
83+
84+
# Establish a connection
85+
# Specify connection string
86+
connection_string = "SERVER=<your_server_name>;DATABASE=<your_database_name>;UID=<your_user_name>;PWD=<your_password>;Encrypt=yes;"
87+
connection = mssql_python.connect(connection_string)
88+
89+
# Execute a query
90+
cursor = connection.cursor()
91+
cursor.execute("SELECT * from customer")
92+
rows = cursor.fetchall()
93+
94+
for row in rows:
95+
print(row)
96+
97+
# Close the connection
98+
connection.close()
99+
100+
```
101+
102+
## Still have questions?
103+
104+
Check out our [FAQ](https://github.com/microsoft/mssql-python/wiki/Frequently-Asked-Questions). Still not answered? Create an [issue](https://github.com/microsoft/mssql-python/issues/new/choose) to ask a question.
105+
106+
## Contributing
107+
108+
This project welcomes contributions and suggestions. Most contributions require you to agree to a
109+
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
110+
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
111+
112+
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
113+
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
114+
provided by the bot. You will only need to do this once across all repos using our CLA.
115+
116+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
117+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
118+
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
119+
120+
## License
121+
The mssql-python driver for SQL Server is licensed under the MIT license, except the dynamic-link libraries (DLLs) in the [libs](https://github.com/microsoft/mssql-python/tree/alphaChanges/mssql_python/libs) folder
122+
that are licensed under MICROSOFT SOFTWARE LICENSE TERMS.
123+
124+
Please review the [LICENSE](LICENSE) file for more details.
125+
126+
## Trademarks
127+
128+
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
129+
trademarks or logos is subject to and must follow
130+
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
131+
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
132+
Any use of third-party trademarks or logos are subject to those third-party's policies.

0 commit comments

Comments
 (0)