### Setup Snowflake Connector Performance Tests Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/test/stress/aio/README.md Clone the repository, install development requirements, and create a parameters file for credentials. ```bash git clone git@github.com:snowflakedb/snowflake-connector-python.git cd snowflake-connector-python/test/stress pip install -r dev_requirements.txt touch parameters.py # set your own connection parameters ``` -------------------------------- ### Simple Async Query Example Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/src/snowflake/connector/aio/README.md An example demonstrating how to execute a simple query asynchronously and iterate over the results. Ensure you have `aiohttp` installed. ```python import asyncio from snowflake.connector.aio import connect async def query_data(): async with connect(user='...', password='...', account='...') as conn: async with conn.cursor() as cur: await cur.execute("SELECT * FROM table WHERE id < %s", (100,)) async for row in cur: print(row) asyncio.run(query_data()) ``` -------------------------------- ### Install Dependencies from Requirements File Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/tested_requirements/README.md Use this command to install all dependencies listed in a requirements file. This is useful for setting up a consistent development or testing environment. ```shell python -m pip install -r requirements_37.reqs ``` -------------------------------- ### Install aiohttp Dependency Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/src/snowflake/connector/aio/README.md To use the asynchronous features, you need to install the `aiohttp` dependency. This import statement shows how to access the async components. ```python from snowflake.connector.aio import connect, SnowflakeConnection, DictCursor ``` -------------------------------- ### Define Connection Parameters in connections.toml Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/DESCRIPTION.md Example of how to define connection parameters in the connections.toml file. This allows for reusable connection configurations. ```toml [prod] account = "my_account" user = "my_user" password = "my_password" ``` -------------------------------- ### Build Snowflake Connector for Python Wheel Locally Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/README.md Build a wheel package for the Snowflake Connector for Python locally using PEP-517 build. Ensure you have a supported Python version installed. ```shell git clone git@github.com:snowflakedb/snowflake-connector-python.git cd snowflake-connector-python python -m pip install -U pip setuptools wheel build python -m build --wheel . ``` -------------------------------- ### Verify Package Signature with Cosign Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/README.md Verify the signature of a downloaded Snowflake Connector for Python package using the 'cosign verify-blob' command. Ensure you have cosign installed and the correct signature and key files. ```bash # replace the version number with the version you are verifying ./cosign verify-blob snowflake_connector_python-3.12.2.tar.gz \ --key snowflake-connector-python-v3.12.2.pub \ --signature resources.linux.snowflake_connector_python-3.12.2.tar.gz.sig ``` -------------------------------- ### Set Up Development Environment with Tox Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/CONTRIBUTING.md Use this command to create and activate a development environment with necessary dependencies. It's recommended to use the lowest supported Python version for development. ```shell tox --devenv venv310 -e py310 . venv310/bin/activate ``` -------------------------------- ### Configure Snowflake Connection Parameters Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/test/README.md Place this file in the `test` directory to define connection parameters for testing. Ensure all required fields are populated. ```python CONNECTION_PARAMETERS = { 'account': 'testaccount', 'user': 'user', 'password': 'testpasswd', 'schema': 'testschema', 'database': 'testdb', } ``` -------------------------------- ### Async Connection Patterns Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/src/snowflake/connector/aio/README.md Demonstrates recommended ways to establish and manage asynchronous connections to Snowflake. The context manager pattern is preferred for automatic resource management. ```python # Pattern 1: Async context manager (recommended) async with connect(user='...', password='...', account='...') as conn: # Use connection pass ``` ```python # Pattern 2: Direct await conn = await connect(user='...', password='...', account='...') await conn.close() ``` ```python # Pattern 3: Manual conn = SnowflakeConnection(user='...', password='...', account='...') await conn.connect() await conn.close() ``` -------------------------------- ### Run Full Test Suite with Tox Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/test/README.md Execute the most important tests using tox version 4. This command includes linting, Python 3.9 tests, and optional pandas/SSO integrations. ```shell tox -e "fix_lint,py39{,-pandas,-sso}" ``` -------------------------------- ### Print Snowflake CONNECTIONS_FILE Path Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/DESCRIPTION.md This command prints the path to the connections.toml file that the Python connector is currently using. This is useful for understanding configuration file locations. ```python from snowflake.connector.constants import CONNECTIONS_FILE print(str(CONNECTIONS_FILE)) ``` -------------------------------- ### Sample Row Data with All Data Types Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/test/stress/stress_test_data/README.md This sample row demonstrates a comprehensive set of data types, including integers, bytearrays, booleans, strings, dates, datetimes with and without timezones, decimals, and floats. It is used for testing the full spectrum of data handling capabilities. ```python (123456, bytearray(b'HELP'), True, 'a', 'b', datetime.date(2023, 7, 18), datetime.datetime(2023, 7, 18, 12, 51), Decimal('984.280'), Decimal('268.350'), 123.456, 738.132, 6789, 23456, 12583, 513.431, 10, 9, 'fjisfsj', 'wkdoajde131', datetime.time(12, 34, 56), datetime.datetime(2021, 1, 1, 0, 0), datetime.datetime(2021, 1, 1, 0, 0, tzinfo=), datetime.datetime(2020, 12, 31, 16, 0, tzinfo=), datetime.datetime(2021, 1, 1, 0, 0), 1, bytearray(b'HELP'), 'vxlmls!21321#@!#!' ) ``` -------------------------------- ### Sample Row Data with Multi-Column Decimals Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/test/stress/stress_test_data/README.md This sample row contains multiple decimal values and other data types, used for stress testing scenarios involving numerous decimal columns. It is part of a dataset with many batches and rows. ```python ( datetime.date(2021, 1, 3), 8371, 'segment_no_0', 1, 7, 2, Decimal('0.285714'), Decimal('1.000'), Decimal('7.000'), Decimal('2.000'), Decimal('0.285714000'), Decimal('1.000'), Decimal('7.000'), Decimal('2.000'), Decimal('0.285714000'), Decimal('1.000'), Decimal('7.000'), Decimal('2.000'), Decimal('0.285714000') ) ``` -------------------------------- ### Run End-to-End Performance Test Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/test/stress/aio/README.md Execute the end-to-end performance test script. Ensure data preparation is handled by updating the script as needed. ```python python e2e_iterator.py ``` -------------------------------- ### Run Unit Performance Test Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/test/stress/README.md Execute the unit performance test using the local iterator script. Ensure the 'stress_test_data' folder is populated. ```python python local_iterator.py ``` -------------------------------- ### Activate Tox Environment and Run Single Test Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/test/README.md Activate a specific tox environment (e.g., py39) and then run a single pytest test case. This is useful for debugging specific issues. ```shell . .tox/py39/bin/activate pytest -v test/integ/test_connection.py::test_basic ``` -------------------------------- ### Build Snowflake Connector for Python Wheel in Docker Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/README.md Use the provided Dockerized build script to compile wheel files for the Snowflake Connector for Python. You can specify Python versions to build for. ```shell # Build for all supported versions ci/build_docker.sh # Build for specific versions like 3.10 and 3.11 ci/build_docker.sh "3.10 3.11" ``` -------------------------------- ### Set SO_REUSEPORT Flag for External Browser Auth Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/DESCRIPTION.md Use the SNOWFLAKE_AUTH_SOCKET_REUSE_PORT flag to set the SO_REUSEPORT flag on the underlying socket. This is useful in containerized environments where the randomized port used in the localhost callback URL might be followed before the container engine completes port forwarding to the host. ```bash SNOWFLAKE_AUTH_SOCKET_REUSE_PORT=true ``` ```bash SF_AUTH_SOCKET_PORT=3037 SNOWFLAKE_AUTH_SOCKET_REUSE_PORT=true poetry run python somescript.py ``` -------------------------------- ### Disable Telemetry via Session Parameters Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/README.md Disable telemetry data collection by setting the CLIENT_TELEMETRY_ENABLED session parameter to False when connecting to Snowflake. ```python import snowflake.connector conn = snowflake.connector.connect( user='XXXX', password='XXXX', account='XXXX', session_parameters={ "CLIENT_TELEMETRY_ENABLED": False, } ) ``` -------------------------------- ### Disable Telemetry via Connection Object Source: https://github.com/snowflakedb/snowflake-connector-python/blob/main/README.md Disable telemetry data collection by setting the telemetry_enabled property to False on the SnowflakeConnection object after establishing the connection. ```python import snowflake.connector conn = snowflake.connector.connect( user='XXXX', password='XXXX', account='XXXX', ) conn.telemetry_enabled = False ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.