{"id":17305103,"url":"https://github.com/seandstewart/que","last_synced_at":"2025-07-16T11:35:24.322Z","repository":{"id":57459328,"uuid":"170600622","full_name":"seandstewart/que","owner":"seandstewart","description":"Que: SQL for Sneks 🐍","archived":false,"fork":false,"pushed_at":"2020-06-22T22:16:05.000Z","size":64,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-06T16:49:53.620Z","etag":null,"topics":["dbapi","python","python3","python37","query-builder","query-engine","sql"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seandstewart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-14T00:28:52.000Z","updated_at":"2022-07-12T01:08:13.000Z","dependencies_parsed_at":"2022-09-10T15:41:07.473Z","dependency_job_id":null,"html_url":"https://github.com/seandstewart/que","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seandstewart%2Fque","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seandstewart%2Fque/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seandstewart%2Fque/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seandstewart%2Fque/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seandstewart","download_url":"https://codeload.github.com/seandstewart/que/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245750667,"owners_count":20666214,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dbapi","python","python3","python37","query-builder","query-engine","sql"],"created_at":"2024-10-15T11:54:40.858Z","updated_at":"2025-03-26T23:22:48.788Z","avatar_url":"https://github.com/seandstewart.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Que: SQL for Sneks 🐍\n================\n[![image](https://img.shields.io/pypi/v/que-py.svg)](https://pypi.org/project/que-py/)\n[![image](https://img.shields.io/pypi/l/que-py.svg)](https://pypi.org/project/que-py/)\n[![image](https://img.shields.io/pypi/pyversions/que-py.svg)](https://pypi.org/project/que-py/)\n[![image](https://img.shields.io/github/languages/code-size/seandstewart/que.svg?style=flat)](https://github.com/seandstewart/que)\n[![image](https://img.shields.io/travis/seandstewart/que.svg)](https://travis-ci.org/seandstewart/que)\n[![codecov](https://codecov.io/gh/seandstewart/que/branch/master/graph/badge.svg)](https://codecov.io/gh/seandstewart/que)\n\nQue allows you to get generate your SQL queries on the fly, without the\noverhead of a fully-fledged ORM.\n\nMotivations\n--------\nQue was born out of a need for dynamically generated SQL for an ASGI web\nservice. I found my self wishing for the convenience of dynamic querying\nwith an ORM such as SQLAlchemy, but the performance of a fully\nasynchronous database client. Que attempts to fill this void. Choose the\nconnection client you prefer and let Que worry about the SQL.\n\n\nWhat Is It?\n---------\nQue looks to solve a single purpose: generate SQL-compliant queries in \npure-Python. Que has absolutely no hard dependendencies and does not\nenforce the use of a specific database client or dialect.\n\nStill want to use SQLAlchemy for your connection? Go for it. Want to use\nPyMySQL or psycopg2? Que won't stop you. Want to use an asyncio\nframework such as aiopg? You have excellent taste! This library was\nwritten just for you.\n\n\nDesign\n-----\nThe focus of Que is *simplicity*, just look at what it takes for a \nsimple `SELECT`:\n\n```python\n\u003e\u003e\u003e import que\n\u003e\u003e\u003e select = que.Select(table='foo')\n\u003e\u003e\u003e select\nSelect(table='foo', schema=None, filters=FilterList([]), fields=FieldList([]))\n\u003e\u003e\u003e sql, args = select.to_sql()\n\u003e\u003e\u003e print(sql)\nSELECT\n  *\nFROM\n  foo\n\n```\n\nQue works with the DBAPI client of your choice by parametrizing your sql\nand formatting your arguments for you:\n\n```python\n\u003e\u003e\u003e import que\n\u003e\u003e\u003e fields = [que.Field('bar')]\n\u003e\u003e\u003e filters = [que.Filter(que.Field('id', 1))]\n\u003e\u003e\u003e select = que.Select(table='foo', filters=filters, fields=fields)\n\u003e\u003e\u003e sql, args = select.to_sql()\n\u003e\u003e\u003e print(sql)\nSELECT\n  bar\nFROM\n  foo\nWHERE\n  id = :1\n\n\u003e\u003e\u003e args\n[1]\n\u003e\u003e\u003e sql, args = select.to_sql(style=que.NameParamStyle.NAME)\n\u003e\u003e\u003e print(sql)\nSELECT\n  bar\nFROM\n  foo\nWHERE\n  id = :id\n\n\u003e\u003e\u003e args\n{'id': 1}\n\n```\n\nQue works to normalize the API for your SQL operations, so that \ninitializing an `INSERT` or `UPDATE` is functionally the same as\ninitializing a `SELECT`:\n\n```python\n\u003e\u003e\u003e import que\n\u003e\u003e\u003e import dataclasses\n\u003e\u003e\u003e import datetime\n\u003e\u003e\u003e\n\u003e\u003e\u003e @dataclasses.dataclass\n... class Foo:\n...     bar: str\n...     id: int = None\n...     created: datetime.datetime = None\n... \n\u003e\u003e\u003e new_foo = Foo('blah')\n\u003e\u003e\u003e fields = que.data_to_fields(new_foo, exclude=None)\n\u003e\u003e\u003e insert = que.Insert(table='foo', fields=fields)\n\u003e\u003e\u003e sql, args = insert.to_sql(que.NameParamStyle.NAME)\n\u003e\u003e\u003e print(sql)\nINSERT INTO\n  foo (:colbar)\nVALUES\n  (:valbar)\n\n\u003e\u003e\u003e args\n{'colbar': 'bar', 'valbar': 'blah'}\n\n```\n \nQuickStart\n--------\nQue has no dependencies and is exceptionally light-weight (currently\nonly ~30Kb!), comprising of only a few hundred lines of code.\nInstallation is as simple as `pip3 install que-py`.\n\nThen you're good to go! `import que` and rock on 🤘\n\n\nExamples\n-------\nA simple client for generating your SQL and inserting new entries:\n```python\nimport dataclasses\nimport sqlite3\n\nimport que\n\n@dataclasses.dataclass\nclass Spam:\n    flavor: str\n    id: int = None\n    created_on: int = None\n    \n\nclass SpamClient:\n    \"\"\"A database client for tracking spam flavors.\"\"\"\n\n    def __init__(self):\n        self.conn = sqlite3.connect('sqlite://spam.db')\n    \n    def insert_spam(self, spam: Spam):\n        fields = que.data_to_fields(spam, exclude=None)\n        insert = que.Insert('spam', fields=fields)\n        sql, args = insert.to_sql()\n        return self.conn.execute(sql, args)\n    \n    def get_spam(self, **kwargs):\n        fields = que.data_to_fields(kwargs)\n        filters = [que.Filter(x) for x in fields]\n        select = que.Select('spam', filters=filters)\n        return self.conn.execute(*select.to_sql())\n    \n    def update_spam(self, spam: Spam):\n        fields = [que.Field('flavor', spam.flavor)]\n        filters = [que.Filter(que.Field('id', spam.id))]\n        update = que.Update('spam', filters=filters, fields=fields)\n        return self.conn.execute(*update.to_sql())\n    \n    def delete_spam(self, spam: Spam):\n        filters = [que.Filter(que.Field('id', spam.id))]\n        delete = que.Delete('spam', filters=filters)\n        return self.conn.execute(*delete.to_sql())\n```\n\nDocumentation\n----------\nFull documentation coming soon!\n\nHappy Querying 🐍\n\n\nHow to Contribute\n-----------------\n1.  Check for open issues or open a fresh issue to start a discussion\n    around a feature idea or a bug. \n2.  Create a branch on Github for your issue or fork \n    [the repository](https://github.com/seandstewart/que) on GitHub to\n    start making your changes to the **master** branch.\n3.  Write a test which shows that the bug was fixed or that the feature\n    works as expected.\n4.  Send a pull request and bug the maintainer until it gets merged and\n    published. :)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseandstewart%2Fque","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseandstewart%2Fque","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseandstewart%2Fque/lists"}