Install the Snowflake Python APIs library¶
You can install the Snowflake Python APIs library for use with conda or a virtual environment. Before you start, be sure to review the supported Python versions.
To set up the Snowflake Python APIs library, complete the following steps:
Activate a Python environment.
Optional: To use the library in government regions, build the Python cryptography library in the environment.
Note
The Snowflake Python APIs library relies on the Python cryptography library for authentication. If you’re using a FIPS-compliant Python environment, you must compile the cryptography library against the system’s FIPS-compliant OpenSSL.
Install the library.
Set options for the Python API client.
Activate a Python environment¶
To set up an environment in which to run Python code, you need to activate a Python environment. For example, you can use conda or a virtual environment (venv).
Note
These steps are only shown as an example, and following along with the example might require additional rights to third-party data, products, or services that are not owned or provided by Snowflake. Ensure that you have the appropriate rights to third-party data, products, or services before continuing.
You can use conda
to create an environment for running Python code. If you don’t have conda, you can install it from the conda website.
For information about conda, see Conda Documentation. To download and install conda, see Installing conda.
Create a conda environment:
conda create -n <env_name> python==3.10
Activate the environment:
conda activate <env_name>
You can use venv
to create a virtual environment for running Python code. If you don’t have Python yet, you can download and install Python,
and then create a virtual environment.
For information about venv, see venv — Creation of virtual environments. To download Python, see Python Downloads.
Use
venv
to create a virtual environment:cd <your Python project root folder> python3 -m venv '.venv'
Activate the environment:
source '.venv/bin/activate'
Build the Python cryptography library for government regions¶
For authentication, the Snowflake Python APIs use the Snowflake Connector for Python, which relies on the Python cryptography library. The cryptography library depends on the OpenSSL C library for all cryptographic operations and ships wheel packages with a statically linked OpenSSL dependency included.
As such, when you install cryptography
by using the default command pip install cryptography
, the library uses its own version
of OpenSSL rather than the system’s version. For more information, see Use of OpenSSL.
If you’re using the Python API to connect to Snowflake accounts in government regions, you need to ensure that you use a FIPS-compliant Python environment. To ensure FIPS compliance, instead of installing the cryptography library from a PyPI wheel, you must compile it yourself against your system’s FIPS-compliant OpenSSL.
For instructions on building the cryptography library on your specific operating system, see Installation in the
cryptography
documentation.
Important
You must build the cryptography library in this manner before you run pip install snowflake -U
. This build sets the cryptography
dependency and ensures that the cryptography
package is not pulled from PyPI.
The cryptography library must be compiled using a version that meets the dependency requirements defined in the Snowflake Connector for Python library.
Install the Snowflake Python APIs library¶
You can install the Snowflake Python APIs library from the Python Package Index (PyPI).
In the conda or virtual environment that you created, run the following
pip
command to install the library:pip install snowflake -U
The snowflake package is the PEP 420 namespace parent package for the Snowflake Python APIs. It includes
snowflake.core
, which is the subpackage that provides Python APIs for managing Snowflake resource objects.Installing the
snowflake
package automatically installssnowflake.core
along with its required dependencies, includingsnowflake-connector-python
.To also install the Snowpark ML library as an extra package dependency, you can run the following
pip
command:pip install "snowflake[ml]" -U
After you install the library, you must create a connection to Snowflake before you can use the API. For more information about connecting, see Connect to Snowflake with the Snowflake Python APIs.
Set Python API client options¶
You can set the following environment variables to control client options for the Snowflake Python APIs:
_SNOWFLAKE_PRINT_VERBOSE_STACK_TRACE
Specifies whether full stack tracing is enabled in printed error messages.
Possible values:
Enabled:
true
,t
,yes
,y
,on
, or undefinedDisabled: Any other value
Default: Enabled
When this option is disabled, the API client sets
sys.tracebacklimit
to0
when processing requests. This setting causes the client to suppress traceback information for all types of exceptions (not only the ones related to the API client) and to print only the error messages.To disable this option for Python notebook environments, run the following line in your notebook:
%env _SNOWFLAKE_PRINT_VERBOSE_STACK_TRACE=false
_SNOWFLAKE_ENABLE_RETRY_REQUEST_QUERY
Specifies whether automatic retries are enabled on query requests with specific status codes.
Possible values:
Enabled:
true
,t
,yes
,y
,on
Disabled: Any other value or undefined
Default: Enabled
When this option is enabled, the API client automatically retries query requests when they have the following status codes:
202
429
503
504