pySQLY - SQL with YAML
Overview
pySQLY is a Python library that enables developers to write database queries using YAML syntax instead of traditional SQL. This approach simplifies database interactions, enhances readability, and provides a consistent interface across multiple database systems.
Key Features
- Multi-Database Support: Works with SQLite, MariaDB/MySQL, PostgreSQL, Oracle, and Microsoft SQL Server
- YAML-Based Syntax: Intuitive, structured query format that reduces syntax errors
- Unified Interface: Single API to interact with different database systems
- CLI Support: Run SQLY queries directly from the command line
- Type Safety: Leverages Python type annotations for better IDE support and error checking
Installation
Install pySQLY from PyPI:
pip install pysqly
To include support for specific databases, use the optional extras:
# For MariaDB/MySQL support
pip install "pysqly[mariadb]"
# For PostgreSQL support
pip install "pysqly[postgres]"
# For Oracle support
pip install "pysqly[oracle]"
# For Microsoft SQL Server support
pip install "pysqly[mssql]"
# For all database support
pip install "pysqly[all]"
Dependencies
pySQLY core requires only PyYAML. Additional database drivers are installed based on your needs:
- SQLite: Built into Python standard library
- MariaDB/MySQL:
mysql-connector-python - PostgreSQL:
psycopg2 - Oracle:
cx_Oracle - Microsoft SQL Server:
pyodbc
Quick Start
Basic Query Example
from pysqly import SQLYExecutor
# Connect to a SQLite database
executor = SQLYExecutor("path/to/database.db", "sqlite")
# Define your query in YAML format
query = """
select:
- username
- email
- created_at
from: users
where:
- field: active
operator: "="
value: true
- field: last_login
operator: ">"
value: "2023-01-01"
"""
# Execute the query
results = executor.execute(query)
print(results)
Using the CLI
sqly-cli "select: [username, email]\nfrom: users\nwhere:\n - field: active\n operator: '='\n value: true" --db_type sqlite --datasource "path/to/database.db"
Documentation
- API Documentation - Detailed library API reference
- Examples - More usage examples and patterns
- Contributing - Guidelines for contributing to pySQLY
- Code of Conduct - Our community standards
- Security Policy - Reporting vulnerabilities and security practices
- Design Document - Architecture and design patterns
- Changelog - Version history and changes
Project Structure
pySQLY/
├── src/
│ └── pysqly/ # Main package directory
│ ├── __init__.py # Package exports and version
│ ├── cli.py # Command-line interface
│ ├── core/ # Core functionality
│ │ ├── __init__.py
│ │ ├── executor.py # Main SQLY executor
│ │ ├── parser.py # YAML to SQL parser
│ │ └── utils.py # Helper utilities
│ ├── errors/ # Error handling
│ │ ├── __init__.py
│ │ ├── base.py # Base error class
│ │ ├── execution.py # Execution errors
│ │ └── parse.py # Parsing errors
│ └── connectors/ # Database connectors
│ ├── __init__.py
│ ├── interface.py # Connector interface
│ ├── base.py # Base connector implementation
│ ├── factory.py # Connector factory
│ ├── database.py # Database connection manager
│ ├── sqlite.py # SQLite connector
│ ├── mariadb.py # MariaDB connector
│ ├── postgres.py # PostgreSQL connector
│ ├── oracle.py # Oracle connector
│ └── mssql.py # MS SQL Server connector
├── tests/ # Test directory
│ ├── __init__.py
│ ├── conftest.py # Test fixtures and configuration
│ ├── test_parser.py # Parser tests
│ └── test_utils.py # Utilities tests
├── pyproject.toml # Project metadata and dependencies
├── setup.py # Setup script (for backwards compatibility)
├── requirements.txt # Development dependencies
├── MANIFEST.in # Package manifest
├── LICENSE # MIT license
├── README.md # This file
├── API.md # API documentation
├── EXAMPLES.md # Usage examples
├── CONTRIBUTING.md # Contribution guidelines
├── CODE_OF_CONDUCT.md # Code of conduct
├── SECURITY.md # Security policy
├── DESIGN.md # Architecture design
└── CHANGELOG.md # Version history
SQLY Query Format
SQLY queries use YAML syntax to represent SQL operations:
# Basic SELECT query
select:
- column1
- column2
from: table_name
where:
- field: column1
operator: "="
value: some_value
See the Examples document for more complex query patterns.
Why Choose pySQLY?
- Simplified Database Access: Write database queries in a more readable format
- Database Agnostic: Switch between database systems without changing your query syntax
- Reduced SQL Injection Risk: Parameter binding is handled automatically
- Improved Productivity: Less boilerplate code and more intuitive query structure
- Easy Integration: Works with your existing Python applications
License
pySQLY is distributed under the MIT License.
Metadata
Release files for pysqly 0.58.0
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 |
|---|---|---|---|---|
| pysqly-0.58.0.tar.gz | 26.2 kB | Without provenance | Details for pysqly-0.58.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pysqly-0.58.0-py3-none-any.whl | Python 3 | none | any | Details for pysqly-0.58.0-py3-none-any.whl |
Total release size: 45.5 kB
Release files / pysqly-0.58.0.tar.gz
| Download URL | pysqly-0.58.0.tar.gz |
|---|---|
| Size | 26.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
96419eb5267b5870832bad99e676fff1701578142f8c92259e82acc346f63d64
|
|
BLAKE2b-256 checksum How to use checksums |
d0093d5457b9d29f35d8d231f678a3a4957826e53c4e0ecb758bc6254422f333
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pysqly-0.58.0-py3-none-any.whl
| Download URL | pysqly-0.58.0-py3-none-any.whl |
|---|---|
| Size | 19.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
376d801093f441cd022bbbf3a94b7f581fe2219aba884959ea619e79617f8aea
|
|
BLAKE2b-256 checksum How to use checksums |
246170df87b1dd11fe9189442086d9e6bd58e6401c7001643fcfd27891a7c54a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for pysqly 0.58.0
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.