sqlty


Namesqlty JSON
Version 0.0.1.dev1 PyPI version JSON
download
home_pageNone
SummaryType-safe SQL queries for Python with automatic stub generation
upload_time2025-11-03 10:20:53
maintainerNone
docs_urlNone
authorNone
requires_python>=3.14
licenseMIT License Copyright (c) 2025 Jiri Kuncar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords code-generation mypy sql static-analysis stub-files type-hints type-safety
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SQLTy

> ⚠️ **Experimental Package**: This is an experimental project under active development. APIs may change without notice. Feedback and contributions are welcome!

Type-safe SQL queries for Python with automatic stub generation and runtime validation.

[![Python 3.14+](https://img.shields.io/badge/python-3.14+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

**Powered by [sqlglot](https://sqlglot.com)** - SQL parsing and analysis engine that makes type inference possible across multiple SQL dialects.

## Overview

SQLTy provides type-safe SQL query execution with automatic type inference and stub generation. Write SQL queries with explicit type casts, and let SQLTy generate precise type stubs for full mypy integration.

```python
from sqlty import SQLRegistry

class Query(SQLRegistry):
    pass

sql = Query.sql

# Type-safe query with automatic inference
query = sql("SELECT id::INTEGER, name::TEXT FROM users")
# Type: SQL[tuple[int, str]]

# Execute with full type safety
from sqlty.drivers.psycopg import execute
result = execute(conn, query, {})
# Type: Iterator[tuple[int, str]]

# Full mypy support
for user_id, name in result:
    print(f"User {user_id}: {name}")
```

## Features

- 🔒 **Type Safety**: Full mypy integration with precise type inference
- 🚀 **Automatic Stub Generation**: Analyze code and generate `.pyi` files automatically
- 🎯 **SQL Type Casts**: Use PostgreSQL-style `::TYPE` casts for explicit typing
- 📦 **Multi-Registry Support**: Organize queries into multiple registries
- 🔍 **Source Tracking**: Generated stubs include source location comments
- 🌐 **Multiple SQL Dialects**: Support for PostgreSQL, MySQL, SQLite, and more via sqlglot

## Quick Start

**Install:**

```bash
pip install sqlty
# or
uv add sqlty
```

**Write queries:**

See [advanced usage documentation](https://github.com/jirikuncar/sqlty/blob/main/docs/advanced-usage.md) for:

- Multi-registry and multiple schema support
- Configuration via pyproject.toml
- Full package example with stub generation and usage

```python
# queries.py
from sqlty import SQLRegistry

class Query(SQLRegistry):
    pass

sql = Query.sql
```

```python
# app.py
from queries import sql
from sqlty.drivers.psycopg import execute

query = sql("SELECT id::INTEGER, name::TEXT FROM users WHERE id = :id")
# Type: SQL[tuple[int, str]]

result = execute(conn, query, {"id": 123})
# Type: Iterator[tuple[int, str]]
```

**Generate stubs:**

```bash
sqlty . --mode=full
```

**Type check:**

```bash
mypy .
# Success: no issues found
```

### Pre-commit Hook

Automatically generate stubs on commit by adding to your `.pre-commit-config.yaml`:

```yaml
repos:
  - repo: https://github.com/jirikuncar/sqlty
    rev: v0.1.0  # Use the latest version
    hooks:
      - id: sqlty
        # Optional: customize with args
        # args: [".", "--mode=full", "--schema=schema.sql"]
```

## Documentation

📚 **[Complete Documentation](https://github.com/jirikuncar/sqlty/blob/main/docs/README.md)**

### Quick Links

- **[Installation Guide](https://github.com/jirikuncar/sqlty/blob/main/docs/installation.md)** - Setup instructions for pip, uv, poetry, and more
- **[User Guide](https://github.com/jirikuncar/sqlty/blob/main/docs/index.md)** - Complete guide with basic and advanced usage
- **[API Reference](https://github.com/jirikuncar/sqlty/blob/main/docs/api.md)** - Detailed API documentation for all classes and methods
- **[Examples Guide](https://github.com/jirikuncar/sqlty/blob/main/docs/examples.md)** - Step-by-step tutorials from basic to advanced

### Key Topics

- [Basic Usage](https://github.com/jirikuncar/sqlty/blob/main/docs/index.md#basic-usage) - Creating registries, writing queries, generating stubs
- [Multi-Registry Pattern](https://github.com/jirikuncar/sqlty/blob/main/docs/index.md#multi-registry-pattern) - Organizing queries for large applications
- [Type Inference](https://github.com/jirikuncar/sqlty/blob/main/docs/index.md#type-inference) - How SQLTy infers Python types from SQL
- [Internals](https://github.com/jirikuncar/sqlty/blob/main/docs/index.md#internals) - Architecture and implementation details

## Contributing

See **[DEVELOPMENT.md](https://github.com/jirikuncar/sqlty/blob/main/docs/DEVELOPMENT.md)** for development setup, workflows, and contribution guidelines.

## License

MIT License - see [LICENSE](https://github.com/jirikuncar/sqlty/blob/main/LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sqlty",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.14",
    "maintainer_email": null,
    "keywords": "code-generation, mypy, sql, static-analysis, stub-files, type-hints, type-safety",
    "author": null,
    "author_email": "Jiri Kuncar <jiri.kuncar@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/4d/e1/25fc4d9178767e05a5551a266467c5a7d3df18197fd4f44e81016a9a199f/sqlty-0.0.1.dev1.tar.gz",
    "platform": null,
    "description": "# SQLTy\n\n> \u26a0\ufe0f **Experimental Package**: This is an experimental project under active development. APIs may change without notice. Feedback and contributions are welcome!\n\nType-safe SQL queries for Python with automatic stub generation and runtime validation.\n\n[![Python 3.14+](https://img.shields.io/badge/python-3.14+-blue.svg)](https://www.python.org/downloads/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n**Powered by [sqlglot](https://sqlglot.com)** - SQL parsing and analysis engine that makes type inference possible across multiple SQL dialects.\n\n## Overview\n\nSQLTy provides type-safe SQL query execution with automatic type inference and stub generation. Write SQL queries with explicit type casts, and let SQLTy generate precise type stubs for full mypy integration.\n\n```python\nfrom sqlty import SQLRegistry\n\nclass Query(SQLRegistry):\n    pass\n\nsql = Query.sql\n\n# Type-safe query with automatic inference\nquery = sql(\"SELECT id::INTEGER, name::TEXT FROM users\")\n# Type: SQL[tuple[int, str]]\n\n# Execute with full type safety\nfrom sqlty.drivers.psycopg import execute\nresult = execute(conn, query, {})\n# Type: Iterator[tuple[int, str]]\n\n# Full mypy support\nfor user_id, name in result:\n    print(f\"User {user_id}: {name}\")\n```\n\n## Features\n\n- \ud83d\udd12 **Type Safety**: Full mypy integration with precise type inference\n- \ud83d\ude80 **Automatic Stub Generation**: Analyze code and generate `.pyi` files automatically\n- \ud83c\udfaf **SQL Type Casts**: Use PostgreSQL-style `::TYPE` casts for explicit typing\n- \ud83d\udce6 **Multi-Registry Support**: Organize queries into multiple registries\n- \ud83d\udd0d **Source Tracking**: Generated stubs include source location comments\n- \ud83c\udf10 **Multiple SQL Dialects**: Support for PostgreSQL, MySQL, SQLite, and more via sqlglot\n\n## Quick Start\n\n**Install:**\n\n```bash\npip install sqlty\n# or\nuv add sqlty\n```\n\n**Write queries:**\n\nSee [advanced usage documentation](https://github.com/jirikuncar/sqlty/blob/main/docs/advanced-usage.md) for:\n\n- Multi-registry and multiple schema support\n- Configuration via pyproject.toml\n- Full package example with stub generation and usage\n\n```python\n# queries.py\nfrom sqlty import SQLRegistry\n\nclass Query(SQLRegistry):\n    pass\n\nsql = Query.sql\n```\n\n```python\n# app.py\nfrom queries import sql\nfrom sqlty.drivers.psycopg import execute\n\nquery = sql(\"SELECT id::INTEGER, name::TEXT FROM users WHERE id = :id\")\n# Type: SQL[tuple[int, str]]\n\nresult = execute(conn, query, {\"id\": 123})\n# Type: Iterator[tuple[int, str]]\n```\n\n**Generate stubs:**\n\n```bash\nsqlty . --mode=full\n```\n\n**Type check:**\n\n```bash\nmypy .\n# Success: no issues found\n```\n\n### Pre-commit Hook\n\nAutomatically generate stubs on commit by adding to your `.pre-commit-config.yaml`:\n\n```yaml\nrepos:\n  - repo: https://github.com/jirikuncar/sqlty\n    rev: v0.1.0  # Use the latest version\n    hooks:\n      - id: sqlty\n        # Optional: customize with args\n        # args: [\".\", \"--mode=full\", \"--schema=schema.sql\"]\n```\n\n## Documentation\n\n\ud83d\udcda **[Complete Documentation](https://github.com/jirikuncar/sqlty/blob/main/docs/README.md)**\n\n### Quick Links\n\n- **[Installation Guide](https://github.com/jirikuncar/sqlty/blob/main/docs/installation.md)** - Setup instructions for pip, uv, poetry, and more\n- **[User Guide](https://github.com/jirikuncar/sqlty/blob/main/docs/index.md)** - Complete guide with basic and advanced usage\n- **[API Reference](https://github.com/jirikuncar/sqlty/blob/main/docs/api.md)** - Detailed API documentation for all classes and methods\n- **[Examples Guide](https://github.com/jirikuncar/sqlty/blob/main/docs/examples.md)** - Step-by-step tutorials from basic to advanced\n\n### Key Topics\n\n- [Basic Usage](https://github.com/jirikuncar/sqlty/blob/main/docs/index.md#basic-usage) - Creating registries, writing queries, generating stubs\n- [Multi-Registry Pattern](https://github.com/jirikuncar/sqlty/blob/main/docs/index.md#multi-registry-pattern) - Organizing queries for large applications\n- [Type Inference](https://github.com/jirikuncar/sqlty/blob/main/docs/index.md#type-inference) - How SQLTy infers Python types from SQL\n- [Internals](https://github.com/jirikuncar/sqlty/blob/main/docs/index.md#internals) - Architecture and implementation details\n\n## Contributing\n\nSee **[DEVELOPMENT.md](https://github.com/jirikuncar/sqlty/blob/main/docs/DEVELOPMENT.md)** for development setup, workflows, and contribution guidelines.\n\n## License\n\nMIT License - see [LICENSE](https://github.com/jirikuncar/sqlty/blob/main/LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2025 Jiri Kuncar  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Type-safe SQL queries for Python with automatic stub generation",
    "version": "0.0.1.dev1",
    "project_urls": {
        "Changelog": "https://github.com/jirikuncar/sqlty/releases",
        "Documentation": "https://github.com/jirikuncar/sqlty#readme",
        "Homepage": "https://github.com/jirikuncar/sqlty",
        "Issues": "https://github.com/jirikuncar/sqlty/issues",
        "Repository": "https://github.com/jirikuncar/sqlty"
    },
    "split_keywords": [
        "code-generation",
        " mypy",
        " sql",
        " static-analysis",
        " stub-files",
        " type-hints",
        " type-safety"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b9174d56240da9c6879c63e08958cf1730d83d2f4a22d6e2ac47be0fe072785d",
                "md5": "024b0764a87182f34d6355f1f7cc9652",
                "sha256": "113b70ae0e2157261e0136e72c3d6fd664feda17418462db9b8648f3a9676b42"
            },
            "downloads": -1,
            "filename": "sqlty-0.0.1.dev1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "024b0764a87182f34d6355f1f7cc9652",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.14",
            "size": 28008,
            "upload_time": "2025-11-03T10:20:52",
            "upload_time_iso_8601": "2025-11-03T10:20:52.192129Z",
            "url": "https://files.pythonhosted.org/packages/b9/17/4d56240da9c6879c63e08958cf1730d83d2f4a22d6e2ac47be0fe072785d/sqlty-0.0.1.dev1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4de125fc4d9178767e05a5551a266467c5a7d3df18197fd4f44e81016a9a199f",
                "md5": "e2ad9e3833dd5ae097a7470051366fa7",
                "sha256": "8de42c16c9fe871e62ac90ad89fec2fbef3ff8c86be047766240cc81df0a5710"
            },
            "downloads": -1,
            "filename": "sqlty-0.0.1.dev1.tar.gz",
            "has_sig": false,
            "md5_digest": "e2ad9e3833dd5ae097a7470051366fa7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.14",
            "size": 22531,
            "upload_time": "2025-11-03T10:20:53",
            "upload_time_iso_8601": "2025-11-03T10:20:53.345794Z",
            "url": "https://files.pythonhosted.org/packages/4d/e1/25fc4d9178767e05a5551a266467c5a7d3df18197fd4f44e81016a9a199f/sqlty-0.0.1.dev1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-11-03 10:20:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jirikuncar",
    "github_project": "sqlty",
    "github_not_found": true,
    "lcname": "sqlty"
}
        
Elapsed time: 3.02113s