singlestore-sql-validator
Attention: The code in this repository is intended for experimental use only and is not fully tested, documented, or supported by SingleStore. Visit the SingleStore Forums to ask questions about this repository.
singlestore-sql-validator is a Python library for validating SQL queries using the SingleStore Language Server (version 0.1.3 and later). It provides a convenient interface to check SQL syntax and semantics by communicating with a SingleStore language server instance over TCP or WebSocket (with optional TLS support).
Features
- Validate SQL queries for correctness using SingleStore's language server
- Supports TCP, WS, and WSS (WebSocket Secure) connections
- Flexible connection configuration (host/port or connection string)
- TLS/SSL support for secure connections
- Returns detailed validation results, including error tokens and suggestions
Installation
Install via pip (after cloning or packaging):
pip install singlestore-sql-validator
Or add to your pyproject.toml as a dependency.
Usage
from sql_validator import Validator, ConnectionMode
# Example: Connect using TCP
validator = Validator(
connection_mode=ConnectionMode.TCP,
server_host="localhost",
server_port=9000
)
# Example: Connect using a connection string
# validator = Validator(connection_string="tcp://localhost:9000")
result = validator.validate("SELECT * FROM my_table;")
if result.is_valid:
print("Query is valid!")
else:
print(f"Error: {result.error_token} at {result.error_token_position}")
if result.alternative_tokens:
print("Suggestions:", result.alternative_tokens)
API
Validator
Initialization
You can initialize a Validator in two ways:
-
By specifying
connection_mode,server_host, andserver_port:connection_mode:ConnectionMode.TCP,ConnectionMode.WS, orConnectionMode.WSSserver_host: Hostname of the language serverserver_port: Port numbertls: Enable TLS (for WSS or secure TCP)tls_ca_file: Path to CA certificate (optional)tls_insecure_skip_verify: Skip TLS verification (optional)
-
By providing a
connection_string(e.g.,tcp://localhost:9000,ws://host:port,wss://host:port)
Methods
validate(query: str, version: str = "") -> ValidationResult- Validates the given SQL query.
version(optional): Database version string (format:major.minor.build, or empty/"default").- Returns a
ValidationResultobject.
Static Methods
_validate_version(version: str) -> bool- Checks if the version string matches the required pattern (
major.minor.build).
- Checks if the version string matches the required pattern (
ValidationResult
is_valid:bool— Whether the query is validerror_token:Optional[str]— The token that caused the error (if any)error_token_position:Optional[TokenPosition]— Position of the error tokenalternative_tokens:Optional[CompletionList]— Suggestions for fixing the error
Example
from sql_validator import Validator
validator = Validator(connection_string="tcp://localhost:9000")
result = validator.validate("SELECT foo FROM bar;")
if result.is_valid:
print("Valid!")
else:
print("Invalid SQL:", result.error_token)
Notes
- This library is intended to be used with a running SingleStore Language Server instance (version 0.1.13 or later).
- It does not start or manage the server process itself.
- Documentation for the SingleStore Language Server can be found at: https://github.com/singlestore-labs/language-server
License
This project is licensed under the terms of the Apache License, Version 2.0.
Metadata
Release files for singlestore-sql-validator 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| singlestore_sql_validator-0.1.2.tar.gz | 11.0 kB | Without provenance | Details for singlestore_sql_validator-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| singlestore_sql_validator-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for singlestore_sql_validator-0.1.2-py3-none-any.whl |
Total release size: 23.7 kB
Release files / singlestore_sql_validator-0.1.2.tar.gz
| Download URL | singlestore_sql_validator-0.1.2.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
df0a147e492e6014d29dbd2598a948074a754db8882ab28ddabdf77e1a543631
|
|
BLAKE2b-256 checksum How to use checksums |
f764023c35df15f44a0f10efd6f8dc3f4c2130dbdd4bf5427b5feac675524dab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.11.15 Linux/6.17.0-1020-azure
|
Release files / singlestore_sql_validator-0.1.2-py3-none-any.whl
| Download URL | singlestore_sql_validator-0.1.2-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bdc96a348ee530e0a60d40930b5aa69811e910671b02c88aa416fa6cb1cabc14
|
|
BLAKE2b-256 checksum How to use checksums |
fabf2824ac519de439cfe6b70724e86a5c90639ba84aa44322956a6a68b5b1dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.11.15 Linux/6.17.0-1020-azure
|
Security for singlestore-sql-validator 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.