### Install SingleStore Package Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Installs the SingleStore Python package using pip. Optionally includes dataframe support. ```bash pip install singlestoredb ``` ```bash pip install singlestoredb[dataframe] ``` -------------------------------- ### Project Setup and Testing Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/singlestoredb/docstring/README.md Guides on setting up the docstring_parser project for development, including cloning the repository, creating a virtual environment, installing dependencies, setting up pre-commit hooks, and running tests. ```shell git clone https://github.com/rr-/docstring_parser.git cd docstring_parser python -m venv venv # create environment source venv/bin/activate # activate environment pip install -e ".[dev]" # install as editable pre-commit install # make sure pre-commit is setup source venv/bin/activate pytest ``` -------------------------------- ### Execute a Query Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/src/getting-started.rst Executes a SQL query using a cursor and fetches all results. This example shows how to display variable information. ```python with conn.cursor() as cur: cur.execute('show variables like "auto%"') for row in cur.fetchall(): print(row) ``` -------------------------------- ### Install and Run Pre-commit Hooks Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/CONTRIBUTING.md Installs the pre-commit tool and its hooks to ensure code quality and formatting before committing. It also shows how to run these checks manually on all files. ```bash pip install pre-commit==3.7.1 pre-commit install ``` ```bash pre-commit run --all-files ``` -------------------------------- ### Executing Queries and Fetching Results Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/getting-started.html Shows how to execute SQL queries using a cursor and fetch the results. It includes an example of fetching all rows from a query that shows variables like 'auto%'. ```python with conn.cursor() as cur: cur.execute('show variables like "auto%"') for row in cur.fetchall(): print(row) ``` -------------------------------- ### Display Workspace Information Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Prints the details of the newly created workspace. This is useful for verifying the workspace's properties. ```python ws ``` -------------------------------- ### Getting Started - Executing Queries Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/index.html Demonstrates the basic process of executing SQL queries against a SingleStoreDB database using the connector. ```python import singlestoredb as s2 conn = s2.connect(host='127.0.0.1', user='root', password='your_password') cursor = conn.cursor() cursor.execute("CREATE DATABASE IF NOT EXISTS test_db") cursor.execute("USE test_db") cursor.execute("CREATE TABLE IF NOT EXISTS users (id INT, name VARCHAR(50))") cursor.execute("INSERT INTO users (id, name) VALUES (1, 'Alice')") ``` -------------------------------- ### List Files in Stage Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Lists all files currently present in the stage. This is useful for verifying uploads or checking the contents of the stage. ```python wg.stages.listdir() ``` -------------------------------- ### List Files in Stage Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Lists the files currently present in a workspace group's stage. Initially, the stage is empty. ```python wg.stages.listdir() ``` -------------------------------- ### Install Test Dependencies Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/CONTRIBUTING.md Installs the required Python packages for running tests, including the main SDK requirements and specific test requirements. ```bash pip install -r requirements.txt pip install -r test-requirements.txt ``` -------------------------------- ### Access File Information Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Retrieves and prints information about a file in the stage, such as its name, creation timestamp, writability, and whether it is a directory. ```python print('name', f.name) print('created at', f.created_at) print('is writable?', f.writable) print('is dir?', f.is_dir()) ``` -------------------------------- ### Getting Started - Connecting using a URL Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/index.html Illustrates how to connect to SingleStoreDB by providing a connection URL, which encapsulates all necessary connection details. ```python import singlestoredb as s2 conn = s2.connect( 'mysql://root:your_password@127.0.0.1:3306/test_db' ) ``` -------------------------------- ### Import SingleStore Package Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Imports the SingleStore Python package with a common alias. ```python import singlestoredb as s2 ``` -------------------------------- ### Download Stage File Content by Name Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Downloads the content of a stage file specified by its name, with optional encoding for string output. ```python print(wg.stages.download('stage_open_test.csv', encoding='utf-8')) ``` -------------------------------- ### Get Available Regions Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Retrieves a list of available regions where SingleStoreDB workspaces can be deployed. This is essential for provisioning new resources. ```python wm.regions ``` -------------------------------- ### Create Database Connection Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Establishes a connection to SingleStoreDB using a connection URL. Supports DB-API 2.0 and environment variables. ```python conn_url = 'root:@127.0.0.1:9306/x_db' conn = s2.connect(conn_url) ``` ```python import os os.environ['SINGLESTOREDB_URL'] = conn_url ``` -------------------------------- ### Getting Started - Connecting with DB-API Parameters Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/index.html Demonstrates how to establish a connection to SingleStoreDB using standard DB-API parameters such as host, port, user, and password. ```python import singlestoredb as s2 conn = s2.connect( host='127.0.0.1', port=3306, user='root', password='your_password', database='test_db' ) ``` -------------------------------- ### Reset and Create Tables Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Drops existing tables if they exist and then creates 'departments', 'employees', and 'salaries' tables with specified schemas. ```sql cur.execute(r'drop table if exists departments') cur.execute(r'drop table if exists employees') cur.execute(r'drop table if exists salaries') cur.execute(r''' create table if not exists departments ( id int, name varchar(255), primary key (id) ); ''') cur.execute(r''' create table if not exists employees ( id int, deptId int, managerId int, name varchar(255), hireDate date, state char(2), primary key (id) ); ''') cur.execute(r''' create table if not exists salaries ( employeeId int, salary int, primary key (employeeId) ); ''') ``` -------------------------------- ### Connect to SingleStoreDB using DB-API Parameters Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/src/getting-started.rst Establishes a connection to SingleStoreDB using standard DB-API parameters such as host, port, user, password, and database. ```python import singlestoredb as s2 conn = s2.connect(host='...', port='...', user='...', password='...', database='...') ``` -------------------------------- ### Manage Workspaces Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Initializes the WorkspaceManager to manage SingleStoreDB workspaces. Requires a cluster management API token or environment variable. ```python wm = s2.manage_workspaces() ``` -------------------------------- ### Terminate Connection Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Terminates the connection to the SingleStoreDB instance. ```python wg.terminate() ``` -------------------------------- ### Create HTTP Connection Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Establishes a connection to SingleStoreDB using the HTTP API. Requires the connection URL including credentials and port. ```python http_conn = s2.connect('http://root:@localhost:8100/x_db') ``` -------------------------------- ### Getting Started - Specifying Additional Connection Parameters Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/index.html Shows how to include extra connection parameters beyond the basic ones when establishing a connection to SingleStoreDB. ```python import singlestoredb as s2 conn = s2.connect( host='127.0.0.1', port=3306, user='root', password='your_password', autocommit=True, # Example of an additional parameter ssl_verify_cert=False ) ``` -------------------------------- ### Download File Content Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Downloads the content of a file from the stage. The content is returned as bytes by default, but can be decoded to a string using the 'encoding' parameter. ```python print(f.download(encoding='utf-8')) ``` -------------------------------- ### Getting Started - Fetching Results Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/index.html Shows how to retrieve data from executed SQL queries using different fetching methods provided by the cursor object. ```python import singlestoredb as s2 conn = s2.connect(host='127.0.0.1', user='root', password='your_password', database='test_db') cursor = conn.cursor() cursor.execute("SELECT id, name FROM users") # Fetch one row first_row = cursor.fetchone() print(f"First row: {first_row}") # Fetch all remaining rows all_rows = cursor.fetchall() print(f"All rows: {all_rows}") ``` -------------------------------- ### Access HTTP Cursor Description (Second Instance) Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Retrieves the description of the query results from the HTTP cursor after a parameterized query. ```python http_cur.description ``` -------------------------------- ### Fetching Results as Tuples Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/_sources/getting-started.rst.txt Shows how to configure the connection to retrieve query results as standard Python tuples. This is the default behavior. ```python with s2.connect(results_type='tuples') as conn: with conn.cursor() as cur: cur.execute('show variables like "auto%"') for row in cur.fetchall(): print(row) ``` -------------------------------- ### Query with Parameter Substitution via HTTP Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Executes a query with parameter substitution using the HTTP connection. This ensures safe handling of dynamic query parameters. ```python http_cur.execute('select name, hireDate from employees where name like %s', ['%Rhona%']) ``` -------------------------------- ### Fetch Query Results Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/src/getting-started.rst Demonstrates different methods for fetching query results: fetchone (single row), fetchall (all rows), and fetchmany (specified number of rows). ```python # Fetch a single row # row = cur.fetchone() # Fetch all remaining rows # all_rows = cur.fetchall() # Fetch a specified number of rows # some_rows = cur.fetchmany(size=10) ``` -------------------------------- ### Fetch Results as Dictionaries Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Configures the connection to return query results as dictionaries instead of the default tuples. This allows accessing columns by name. ```python conn = s2.connect(conn_url, results_type='dicts') ``` -------------------------------- ### Connect to SingleStoreDB using a URL Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/src/getting-started.rst Connects to SingleStoreDB using a connection URL, similar to SQLAlchemy. This method also works for the Data API. ```python conn = s2.connect('user:password@host:port/database') ``` ```python conn = s2.connect('https://user:password@host:port/database') ``` -------------------------------- ### Fetch All Results Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Executes a SELECT query and fetches all resulting rows at once. This is useful for smaller result sets where loading all data into memory is feasible. ```python cur = conn.cursor() cur.execute('select name from employees') cur.fetchall() ``` -------------------------------- ### Create Workspace Group Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Creates a new workspace group with a specified name, region, admin password, and firewall rules. This organizes related workspaces. ```python wg = wm.create_workspace_group( 'Demo Workspace Group', region=[x for x in wm.regions if x.name.startswith('US')][0], admin_password=password, firewall_ranges=['0.0.0.0/0'], ) wg ``` -------------------------------- ### Specify Additional Connection Parameters Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/src/getting-started.rst Demonstrates how to specify additional connection parameters like 'local_infile' either within the connection URL or as keyword arguments. ```python conn = s2.connect('https://user:password@host:port/database?local_infile=True') ``` ```python conn = s2.connect('https://host:port/database', user='...', password='...', local_infile=True) ``` -------------------------------- ### Access Global Server Variables Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Retrieves and displays the current global server variables as a dictionary. This allows inspection of the database's configuration. ```python dict(conn.globals) ``` -------------------------------- ### Access Query Description Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Retrieves metadata about the columns returned by the last executed query. This includes information like column name, type, and size. ```python cur.description ``` -------------------------------- ### Fetching Results as Dictionaries Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/_sources/getting-started.rst.txt Demonstrates retrieving query results as dictionaries, where column names serve as keys. This is achieved by setting `results_type` to 'dicts'. ```python with s2.connect(results_type='dicts') as conn: with conn.cursor() as cur: cur.execute('show variables like "auto%"') for row in cur.fetchall(): print(row) ``` -------------------------------- ### Connect to Workspace and Show Databases Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Establishes a connection to a workspace using provided credentials and executes 'show databases' to list available databases. Uses a context manager for the connection and cursor. ```python with ws.connect(user='admin', password=password) as conn: with conn.cursor() as cur: cur.execute('show databases') print(cur.fetchall()) ``` -------------------------------- ### Query Data via HTTP Connection Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Executes a SELECT query using a cursor connected via HTTP. This demonstrates data retrieval over the HTTP API. ```python http_cur.execute('select name from employees') ``` -------------------------------- ### Execute Query with Named Parameter Substitution Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/src/getting-started.rst Executes a query using named parameter substitution (e.g., %(name)s). The values are provided as a dictionary to the execute method. ```python with conn.cursor() as cur: cur.execute('show variables like %(pattern)s', dict(pattern='auto%')) for row in cur.fetchall(): print(row) ``` -------------------------------- ### Execute Queries and Fetch Results Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/_sources/getting-started.rst.txt Shows how to execute a SQL query using a cursor and fetch all results using `fetchall()`. This is a fundamental operation for interacting with the database. ```python with conn.cursor() as cur: cur.execute('show variables like "auto%"') for row in cur.fetchall(): print(row) ``` -------------------------------- ### Get Current Clusters Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Retrieves a list of workspace groups associated with the current SingleStoreDB cluster. This provides an overview of the cluster's structure. ```python wm.workspace_groups ``` -------------------------------- ### Start SingleStoreDB Free Tier Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/_sources/generated/singlestoredb.server.free_tier.start.rst.txt Initiates a SingleStoreDB free tier instance. This function is part of the `singlestoredb.server.free_tier` module and is used to provision and start a new free tier database. ```python import singlestoredb.server.free_tier # Start a new free tier instance singlestoredb.server.free_tier.start() ``` -------------------------------- ### Insert Data From DataFrame Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Inserts data into the 'salaries' table using executemany with a pandas DataFrame. ```python import pandas as pd df = pd.DataFrame( [ (1, 885219), (2, 451519), (3, 288905), (4, 904312), (5, 919124), (6, 101538), (7, 355077), (8, 900436), (9, 41557), (10, 556263), ], columns=['employeeId', 'salary']) cur.executemany(r'insert into salaries (employeeId, salary) ' r'values (%s, %s)', df) ``` -------------------------------- ### Start SingleStoreDB in Cloud Free Tier Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/_sources/api.rst.txt Starts a SingleStoreDB server instance using the Cloud Free Tier. This provides a way to run SingleStoreDB without local Docker installation, though with fewer features than the Docker option. ```python from singlestoredb.server import free_tier s2db = free_tier.start() with s2db.connect() as conn: with conn.cursor() as cur: cur.execute('SHOW DATABASES') for line in cur: print(line) ``` -------------------------------- ### Terminate Workspace Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Terminates a SingleStoreDB workspace. The 'wait_on_terminated=True' parameter ensures the operation completes before the script continues. ```python ws.terminate(wait_on_terminated=True) ``` -------------------------------- ### Create Database Cursor Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Creates a cursor object from an active database connection to execute SQL commands. ```python cur = conn.cursor() ``` -------------------------------- ### Start SingleStoreDB in Cloud Free Tier Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/src/api.rst Starts a SingleStoreDB server instance in the Cloud Free Tier. This provides a way to access SingleStoreDB services without local Docker setup, though with fewer features compared to the Docker interface. ```python from singlestoredb.server import free_tier # Start the server in Cloud Free Tier s2db = free_tier.start() ``` -------------------------------- ### Connect to SingleStoreDB using DB-API Parameters Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/_sources/getting-started.rst.txt Establishes a connection to SingleStoreDB using standard DB-API parameters like host, port, user, password, and database. This method is compatible with the Python DB-API specification. ```python import singlestoredb as s2 conn = s2.connect(host='...', port='...', user='...', password='...', database='...') ``` -------------------------------- ### Fetch All Results via HTTP Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Fetches all rows from a query executed over the HTTP connection. The results are stored in the 'df' variable. ```python df = http_cur.fetchall() df ``` -------------------------------- ### Create HTTP Cursor Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Creates a cursor object for executing queries over an HTTP connection. Cursors are used to interact with the database. ```python http_cur = http_conn.cursor() ``` -------------------------------- ### Fetching Results - fetchone, fetchall, fetchmany Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/_sources/getting-started.rst.txt Explains the different methods for fetching query results: `fetchone` for a single row, `fetchall` for all rows, and `fetchmany` for a specified number of rows. This allows for efficient handling of large result sets. ```APIDOC Cursor.fetchone() - Fetches a single row of data. Cursor.fetchall() - Fetches all remaining rows of a query result. Cursor.fetchmany(size=None) - Fetches the next set of rows of a query result. - Parameters: - size (int, optional): The number of rows to fetch. If None, fetches a default number of rows. ``` -------------------------------- ### Read Global Server Variable Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Reads the current value of the 'enable_external_functions' global server variable. This confirms the setting after modification. ```python conn.globals.enable_external_functions ``` -------------------------------- ### SingleStoreDB Docker Initialization Parameters Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/generated/singlestoredb.server.docker.start.html Defines the parameters used to configure and initialize a SingleStoreDB instance running in a Docker container. These parameters allow customization of the server's environment, startup behavior, and default connection settings. ```APIDOC SingleStoreDB: __init__(server_dir: str = None, global_vars: dict = None, init_sql: str = None, image: str = None, database: str = None) Parameters: server_dir (str, optional): Path to the server directory. Defaults to None. global_vars (dict, optional): Global variables to set in the SingleStoreDB server. Defaults to None. init_sql (str, optional): Path to an SQL file to run on startup. Defaults to None. image (str, optional): Docker image to use. Defaults to None. database (str, optional): Default database to connect to. Defaults to None. ``` -------------------------------- ### Insert Data Using Positional Parameters Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Inserts data into the 'employees' table using positional parameters (%s) and a list of tuples. ```python cur.executemany(r'insert into employees (id, deptId, managerId, name, hireDate, state) ' r'values (%s, %s, %s, %s, %s, %s)', [ (1, 2, None, "Karly Steele", "2011-08-25", "NY"), (2, 1, 1, "Rhona Nichols", "2008-09-11", "TX"), (3, 4, 2, "Hedda Kent", "2005-10-27", "TX"), (4, 2, 1, "Orli Strong", "2001-07-01", "NY"), (5, 1, 1, "Leonard Haynes", "2011-05-30", "MS"), (6, 1, 5, "Colette Payne", "2002-10-22", "MS"), (7, 3, 4, "Cooper Hatfield", "2010-08-19", "NY"), (8, 2, 4, "Timothy Battle", "2001-01-21", "NY"), (9, 3, 1, "Doris Munoz", "2008-10-22", "NY"), (10, 4, 2, "Alea Wiggins", "2007-08-21", "TX"), ] ) ``` -------------------------------- ### Getting Started - Result Type Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/index.html Explains the type of results returned by query executions, typically as tuples representing rows. ```python import singlestoredb as s2 conn = s2.connect(host='127.0.0.1', user='root', password='your_password', database='test_db') cursor = conn.cursor() cursor.execute("SELECT id, name FROM users WHERE id = 1") result = cursor.fetchone() # Result is typically a tuple print(type(result)) print(result[0]) # Access by index print(result['name']) # Access by column name if available ``` -------------------------------- ### Start SingleStoreDB Docker Container Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/_sources/generated/singlestoredb.server.docker.start.rst.txt The `start` function initiates a SingleStoreDB Docker container. It handles the necessary Docker commands to pull the image if it doesn't exist and then run the container with appropriate configurations. This function is essential for setting up a local SingleStoreDB instance for development or testing purposes. ```python from singlestoredb.server.docker import start # Start a SingleStoreDB Docker container start() # You can also specify arguments like port mappings, volumes, etc. # start(port_mappings={'3306': 3306}) ``` -------------------------------- ### Query with Parameter Substitution Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Executes a query using parameter substitution to safely include dynamic values. It uses the '%s' format, compatible with the underlying mysql.connector and the HTTP API's question mark format. ```python cur.execute('select name, hireDate from employees where name like %s', ['%Rhona%']) ``` -------------------------------- ### Access HTTP Cursor Description Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Retrieves metadata for the query results obtained through the HTTP connection. Similar to the standard cursor description. ```python http_cur.description ``` -------------------------------- ### Parameter Substitution - Positional Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/_sources/getting-started.rst.txt Demonstrates using positional parameter substitution (e.g., %s) in SQL queries. Values are provided as a list or tuple to the `execute` method. Escaping and quoting are handled automatically. ```python with conn.cursor() as cur: cur.execute('show variables like %s', ['auto%']) for row in cur.fetchall(): print(row) ``` -------------------------------- ### Modify Global Server Variable Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Sets a global server variable, 'enable_external_functions', to True. This demonstrates how to modify server settings programmatically. ```python conn.globals.enable_external_functions = True ``` -------------------------------- ### Install SingleStoreDB Python SDK Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/README.md Installs the SingleStoreDB Python SDK package from PyPI using pip. ```bash pip install singlestoredb ``` -------------------------------- ### Execute SELECT Query Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/examples/getting-started.ipynb Executes a simple SELECT query to retrieve data from the 'employees' table. This is a basic operation for fetching data. ```python cur.execute('select name from employees') ``` -------------------------------- ### Add SHOW FUSION HELP Command Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/whatsnew.html Introduces the `SHOW FUSION HELP` command and its documentation for Fusion SQL handlers. ```python # Conceptual example of using SHOW FUSION HELP import singlestoredb as s2 conn = s2.connect() cursor = conn.cursor() cursor.execute("SHOW FUSION HELP") help_text = cursor.fetchall() print(help_text) ``` -------------------------------- ### Standard Database Connection Example Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/generated/singlestoredb.connect.html Demonstrates a basic connection to a SingleStoreDB database using default or common parameters. ```python import singlestoredb as s2 # Example of a standard database connection conn = s2.connect(host='127.0.0.1', port=3306, user='root', password='password') # You can then execute queries using the connection object # cursor = conn.cursor() # cursor.execute("SELECT @@version") # print(cursor.fetchone()) # conn.close() ``` -------------------------------- ### Example: Accessing and Modifying Configuration Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/src/api.rst Illustrates how to use the `describe_option` function and the `singlestoredb.options` object to get, set, and verify the 'local_infile' configuration setting. ```python import singlestoredb as s2 s2.describe_option('local_infile') s2.options.local_infile s2.options.local_infile = True s2.describe_option('local_infile') s2.options.local_infile = False ``` -------------------------------- ### Specify Additional Connection Parameters Source: https://github.com/singlestore-labs/singlestoredb-python/blob/main/docs/_sources/getting-started.rst.txt Demonstrates how to specify additional connection parameters, such as 'local_infile', either within the connection URL or as keyword arguments during connection. ```python conn = s2.connect('https://user:password@host:port/database?local_infile=True') ``` ```python conn = s2.connect('https://host:port/database', user='...', password='...', local_infile=True) ```