SQL Server Python tutorials

This article provides a list of tutorials and samples that demonstrate the use of Python with SQL Server 2017. Through these samples and demos, you will learn:

  • How to run Python from T-SQL
  • What are remote and local compute contexts, and how you can execute Python code using the SQL Server computer
  • How to wrap Python code in a stored procedure
  • Optimizing Python code for a SQL production environment
  • Real-world scenarios for embedding machine learning in applications

For information about requirements and setup, see Prerequisites.

Python tutorials

Python samples

These samples and demos provided by the SQL Server development team highlight ways that you can use embedded analytics in real-world applications.

Prerequisites

To use these tutorials, you must have installed SQL Server 2017 Machine Learning Services (In-Database). SQL Server 2017 supports either R or Python. However, you must install the extensibility framework that supports machine learning, and select Python as the language to install. You can install both R and Python on the same computer.

Note

Support for Python is a new feature in SQL Server 2017, and requires CTP 2.0 or later. Although the feature is in pre-release and not supported for production environments, we invite you to try it out and send feedback.

SQL Server 2017

After running SQL Server setup, don't forget these important steps:

  • Enable the external script execution feature by running sp_configure 'external scripts enabled', 1.
  • Restart the server.
  • Ensure that the service that calls the external runtime has necessary permissions.
  • Ensure that your SQL login or Windows user account has necessary permissions to connect to the server, to read data, and to create any database objects required by the sample.

If you run into trouble, see this article for some common issues: Troubleshooting Machine Learning Services

See also

R tutorials for SQL Server