Path: blob/main/singlestoredb/config.py
469 views
#!/usr/bin/env python1"""SingleStoreDB package options."""2import functools3import os45from . import auth6from .utils.config import check_bool # noqa: F4017from .utils.config import check_dict_str_str # noqa: F4018from .utils.config import check_float # noqa: F4019from .utils.config import check_int # noqa: F40110from .utils.config import check_optional_bool # noqa: F40111from .utils.config import check_str # noqa: F40112from .utils.config import check_url # noqa: F40113from .utils.config import describe_option # noqa: F40114from .utils.config import get_default # noqa: F40115from .utils.config import get_option # noqa: F40116from .utils.config import get_suboptions # noqa: F40117from .utils.config import option_context # noqa: F40118from .utils.config import options # noqa: F40119from .utils.config import register_option # noqa: F40120from .utils.config import reset_option # noqa: F40121from .utils.config import set_option # noqa: F401222324#25# Connection options26#27register_option(28'host', 'string', check_str, '127.0.0.1',29'Specifies the database host name or IP address.',30environ=['SINGLESTOREDB_HOST', 'SINGLESTOREDB_URL'],31)3233register_option(34'port', 'int', check_int, 0,35'Specifies the database port number.',36environ='SINGLESTOREDB_PORT',37)3839register_option(40'http_port', 'int', check_int, 0,41'Specifies the database port number for the HTTP API.',42environ='SINGLESTOREDB_HTTP_PORT',43)4445register_option(46'user', 'string', check_str, None,47'Specifies the database user name.',48environ='SINGLESTOREDB_USER',49)5051register_option(52'password', 'string', check_str, None,53'Specifies the database user password.',54environ='SINGLESTOREDB_PASSWORD',55)5657register_option(58'driver', 'string', check_str, 'mysql',59'Specifies the Python DB-API module to use for communicating'60'with the database.',61environ='SINGLESTOREDB_DRIVER',62)6364register_option(65'database', 'string', check_str, None,66'Name of the database to connect to.',67environ='SINGLESTOREDB_DATABASE',68)6970register_option(71'pure_python', 'bool', check_optional_bool, None,72'Should the driver use a pure Python implementation? If the value is '73'`None`, the C extension will be used if it exists, and pure python '74'will be used otherwise. If the value is `False`, the pure python '75'implementation will be used. If the value is `True` and the C extension '76'exists, it will be used. If the value is `True` and the C extension '77'doesn\'t exist or can\'t be loaded, a `NotSupportedError` is raised.',78environ='SINGLESTOREDB_PURE_PYTHON',79)8081register_option(82'charset', 'string', check_str, 'utf8mb4',83'Specifies the character set for the session.',84environ='SINGLESTOREDB_CHARSET',85)8687register_option(88'encoding_errors', 'string', check_str, 'strict',89'Specifies the error handling behavior for decoding string values.',90environ='SINGLESTOREDB_ENCODING_ERRORS',91)9293register_option(94'local_infile', 'bool', check_bool, False,95'Should it be possible to load local files?',96environ='SINGLESTOREDB_LOCAL_INFILE',97)9899register_option(100'multi_statements', 'bool', check_bool, False,101'Should it be possible use multiple statements in one query?',102environ='SINGLESTOREDB_MULTI_STATEMENTS',103)104105register_option(106'client_found_rows', 'bool', check_bool, False,107'Should affected_rows in OK_PACKET indicate the '108'number of matched rows instead of changed?',109environ='SINGLESTOREDB_CLIENT_FOUND_ROWS',110)111112register_option(113'ssl_key', 'str', check_str, None,114'File containing SSL key',115environ='SINGLESTOREDB_SSL_KEY',116)117118register_option(119'ssl_cert', 'str', check_str, None,120'File containing SSL certificate',121environ='SINGLESTOREDB_SSL_CERT',122)123124register_option(125'ssl_ca', 'str', check_str, None,126'File containing SSL certificate authority',127environ='SINGLESTOREDB_SSL_CA',128)129130register_option(131'ssl_cipher', 'str', check_str, 'HIGH',132'Sets the SSL cipher list',133environ='SINGLESTOREDB_SSL_CIPHER',134)135136register_option(137'tls_sni_servername', 'str', check_str, None,138'Sets TLS SNI servername',139environ='SINGLESTOREDB_TLS_SNI_SERVERNAME',140)141142register_option(143'ssl_disabled', 'bool', check_bool, False,144'Disable SSL usage',145environ='SINGLESTOREDB_SSL_DISABLED',146)147148register_option(149'ssl_verify_cert', 'bool', check_optional_bool, None,150'Verify the server\'s certificate',151environ='SINGLESTOREDB_SSL_VERIFY_CERT',152)153154register_option(155'ssl_verify_identity', 'bool', check_optional_bool, None,156'Verify the server\'s identity',157environ='SINGLESTOREDB_SSL_VERIFY_IDENTITY',158)159160register_option(161'program_name', 'string', check_str, None,162'Name of the program',163)164165register_option(166'conn_attrs', 'dict', check_dict_str_str, None,167'Additional connection attributes for telemetry',168)169170register_option(171'credential_type', 'str',172functools.partial(173check_str, valid_values=[174auth.PASSWORD,175auth.JWT,176auth.BROWSER_SSO,177],178),179None,180'Type of authentication method to use.',181environ='SINGLESTOREDB_CREDENTIAL_TYPE',182)183184register_option(185'sso_browser', 'str', check_str, None,186'Browser to use for single sign-on. This should be a web browser name '187'registered with Python\'s webbrowser module.',188environ='SINGLESTOREDB_SSO_BROWSER',189)190191register_option(192'autocommit', 'bool', check_bool, True,193'Enable autocommits',194environ='SINGLESTOREDB_AUTOCOMMIT',195)196197register_option(198'buffered', 'bool', check_bool, True,199'Should query results be buffered before processing?',200environ='SINGLESTOREDB_BUFFERED',201)202203register_option(204'parse_json', 'bool', check_bool, True,205'Parse JSON values into Python objects?',206environ='SINGLESTOREDB_PARSE_JSON',207)208209register_option(210'connect_timeout', 'int', check_int, 10,211'The timeout for connecting to the database in seconds. '212'(default: 10, min: 1, max: 31536000)',213environ='SINGLESTOREDB_CONNECT_TIMEOUT',214)215216register_option(217'nan_as_null', 'bool', check_bool, False,218'Should NaN values be treated as NULLs in query parameter substitutions '219'including uploaded data?',220environ='SINGLESTOREDB_NAN_AS_NULL',221)222223register_option(224'inf_as_null', 'bool', check_bool, False,225'Should Inf values be treated as NULLs in query parameter substitutions '226'including uploaded data?',227environ='SINGLESTOREDB_INF_AS_NULL',228)229230register_option(231'track_env', 'bool', check_bool, False,232'Should connections track the SINGLESTOREDB_URL environment variable?',233environ='SINGLESTOREDB_TRACK_ENV',234)235236register_option(237'enable_extended_data_types', 'bool', check_bool, True,238'Should extended data types (BSON, vector) be enabled?',239environ='SINGLESTOREDB_ENABLE_EXTENDED_DATA_TYPES',240)241242register_option(243'vector_data_format', 'string',244functools.partial(245check_str,246valid_values=['json', 'binary'],247),248'binary',249'Format for vector data values',250environ='SINGLESTOREDB_VECTOR_DATA_FORMAT',251)252253register_option(254'fusion.enabled', 'bool', check_bool, False,255'Should Fusion SQL queries be enabled?',256environ='SINGLESTOREDB_FUSION_ENABLED',257)258259#260# Query results options261#262register_option(263'results.type', 'string',264functools.partial(265check_str,266valid_values=[267'tuple', 'tuples', 'namedtuple', 'namedtuples',268'dict', 'dicts', 'structsequence', 'structsequences',269'numpy', 'pandas', 'polars', 'arrow', 'pyarrow',270],271),272'tuples',273'What form should the query results take?',274environ='SINGLESTOREDB_RESULTS_TYPE',275)276277register_option(278'results.arraysize', 'int', check_int, 1,279'Number of result rows to download in `fetchmany` calls.',280environ='SINGLESTOREDB_RESULTS_ARRAYSIZE',281)282283284#285# Workspace manager options286#287register_option(288'management.token', 'string', check_str, None,289'Specifies the authentication token for the management API.',290environ=['SINGLESTOREDB_MANAGEMENT_TOKEN'],291)292293register_option(294'management.base_url', 'string', check_str, 'https://api.singlestore.com',295'Specifies the base URL for the management API.',296environ=['SINGLESTOREDB_MANAGEMENT_BASE_URL'],297)298299register_option(300'management.version', 'string', check_str, 'v1',301'Specifies the version for the management API.',302environ=['SINGLESTOREDB_MANAGEMENT_VERSION'],303)304305306#307# External function options308#309register_option(310'external_function.url', 'string', check_str, 'http://localhost:8000/invoke',311'Specifies the URL of the external function application.',312environ=['SINGLESTOREDB_EXT_FUNC_URL'],313)314315register_option(316'external_function.app_mode', 'string',317functools.partial(318check_str,319valid_values=['remote', 'collocated', 'managed'],320),321'remote',322'Specifies the mode of operation of the external function application.',323environ=['SINGLESTOREDB_EXT_FUNC_APP_MODE'],324)325326register_option(327'external_function.data_format', 'string',328functools.partial(329check_str,330valid_values=['rowdat_1', 'json'],331),332'rowdat_1',333'Specifies the format for the data rows.',334environ=['SINGLESTOREDB_EXT_FUNC_DATA_FORMAT'],335)336337register_option(338'external_function.data_version', 'string', check_str, '1.0',339'Specifies the version of the data format.',340environ=['SINGLESTOREDB_EXT_FUNC_DATA_VERSION'],341)342343register_option(344'external_function.link_name', 'string', check_str, None,345'Specifies the link name to use for remote external functions.',346environ=['SINGLESTOREDB_EXT_FUNC_LINK_NAME'],347)348349register_option(350'external_function.link_config', 'string', check_str, None,351'Specifies the link config in JSON format.',352environ=['SINGLESTOREDB_EXT_FUNC_LINK_CONFIG'],353)354355register_option(356'external_function.link_credentials', 'string', check_str, None,357'Specifies the link credentials in JSON format.',358environ=['SINGLESTOREDB_EXT_FUNC_LINK_CREDENTIALS'],359)360361register_option(362'external_function.replace_existing', 'bool', check_bool, False,363'Should existing functions be replaced when registering external functions?',364environ=['SINGLESTOREDB_EXT_FUNC_REPLACE_EXISTING'],365)366367register_option(368'external_function.socket_path', 'string', check_str, None,369'Specifies the socket path for collocated external functions.',370environ=['SINGLESTOREDB_EXT_FUNC_SOCKET_PATH'],371)372373register_option(374'external_function.max_connections', 'int', check_int, 32,375'Specifies the maximum connections in a collocated external function ' +376'before reusing them.',377environ=['SINGLESTOREDB_EXT_FUNC_MAX_CONNECTIONS'],378)379380register_option(381'external_function.process_mode', 'string',382functools.partial(383check_str,384valid_values=['thread', 'subprocess'],385),386'subprocess',387'Specifies the method to use for concurrent handlers in ' +388'collocated external functions',389environ=['SINGLESTOREDB_EXT_FUNC_PROCESS_MODE'],390)391392register_option(393'external_function.single_thread', 'bool', check_bool, False,394'Should the collocated server run in single-thread mode?',395environ=['SINGLESTOREDB_EXT_FUNC_SINGLE_THREAD'],396)397398register_option(399'external_function.log_level', 'string',400functools.partial(401check_str,402valid_values=['info', 'debug', 'warning', 'error'],403),404'info',405'Logging level of external function server.',406environ=['SINGLESTOREDB_EXT_FUNC_LOG_LEVEL'],407)408409register_option(410'external_function.log_file', 'string', check_str, None,411'File path to write logs to instead of console.',412environ=['SINGLESTOREDB_EXT_FUNC_LOG_FILE'],413)414415register_option(416'external_function.name_prefix', 'string', check_str, '',417'Prefix to add to external function names.',418environ=['SINGLESTOREDB_EXT_FUNC_NAME_PREFIX'],419)420421register_option(422'external_function.name_suffix', 'string', check_str, '',423'Suffix to add to external function names.',424environ=['SINGLESTOREDB_EXT_FUNC_NAME_SUFFIX'],425)426427register_option(428'external_function.function_database', 'string', check_str, '',429'Database to use for the function definitions.',430environ=['SINGLESTOREDB_EXT_FUNC_FUNCTION_DATABASE'],431)432433register_option(434'external_function.connection', 'string', check_str,435os.environ.get('SINGLESTOREDB_URL') or None,436'Specifies the connection string for the database to register functions with.',437environ=['SINGLESTOREDB_EXT_FUNC_CONNECTION'],438)439440register_option(441'external_function.host', 'string', check_str, 'localhost',442'Specifies the host to bind the server to.',443environ=['SINGLESTOREDB_EXT_FUNC_HOST'],444)445446register_option(447'external_function.port', 'int', check_int, 8000,448'Specifies the port to bind the server to.',449environ=['SINGLESTOREDB_EXT_FUNC_PORT'],450)451452register_option(453'external_function.timeout', 'int', check_int, 24*60*60,454'Specifies the timeout in seconds for processing a batch of rows.',455environ=['SINGLESTOREDB_EXT_FUNC_TIMEOUT'],456)457458register_option(459'external_function.disable_metrics', 'bool', check_bool, False,460'Disable logging of function call metrics.',461environ=['SINGLESTOREDB_EXT_FUNC_DISABLE_METRICS'],462)463464register_option(465'external_function.app_name', 'string', check_str, None,466'Name for the external function application instance.',467environ=['SINGLESTOREDB_EXT_FUNC_APP_NAME'],468)469470#471# Debugging options472#473register_option(474'debug.queries', 'bool', check_bool, False,475'Print queries and parameters to stderr.',476environ='SINGLESTOREDB_DEBUG_QUERIES',477)478479register_option(480'debug.connection', 'bool', check_bool, False,481'Print connection tracing information.',482environ='SINGLESTOREDB_DEBUG_CONNECTION',483)484485486