Django backend for Snowflake
Maintained. Last release 3 months ago, commits in 4 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install django-snowflakeSnowflake backend for Django
Install and usage
Use the version of django-snowflake that corresponds to your version of Django. For example, to get the latest compatible release for Django 6.1.x:
pip install django-snowflake==6.1.*
The minor release number of Django doesn't correspond to the minor release number of django-snowflake. Use the latest minor release of each.
Configure the Django DATABASES setting similar to this:
DATABASES = {
'default': {
'ENGINE': 'django_snowflake',
'NAME': 'MY_DATABASE',
'SCHEMA': 'MY_SCHEMA',
'WAREHOUSE': 'MY_WAREHOUSE',
'USER': 'my_user',
'PASSWORD': 'my_password',
'ACCOUNT': 'my_account',
# Include 'OPTIONS' if you need to specify any other
# snowflake.connector.connect() parameters, documented at:
# https://docs.snowflake.com/en/user-guide/python-connector-api.html#connect
'OPTIONS': {
# Examples:
'role': 'MY_ROLE',
# To use native Okta authenticators:
# https://docs.snowflake.com/en/user-guide/admin-security-fed-auth-use#native-sso-okta-only
'authenticator': 'https://example.okta.com',
# To use private key authentication:
'private_key_file': '<path>/rsa_key.p8',
'private_key_file_pwd': 'my_passphrase',
},
},
}
Persistent connections
To use persisent connections, set Django's CONN_MAX_AGE
and Snowflake Python Connector's client_session_keep_alive:
DATABASES = {
'default': {
# ...
'CONN_MAX_AGE': None,
'OPTIONS': {
'client_session_keep_alive': True,
},
},
}
Snowpark Container Services (SPCS) connections
When your Django app runs inside a Snowpark Container
Services
(SPCS) service, Snowflake automatically provides an OAuth login token and a
host for connecting to Snowflake. django-snowflake detects this environment
using the SNOWFLAKE_SERVICE_NAME environment variable that Snowflake sets for
every service container. In that case, it:
- Falls back to the token at
/snowflake/session/tokenifOPTIONS['token']isn't set. This token is short-lived and is re-read for each new connection.