{"id":37633227,"url":"https://github.com/parantapa/sqlpygen","last_synced_at":"2026-01-16T11:00:22.076Z","repository":{"id":57470621,"uuid":"406494932","full_name":"parantapa/sqlpygen","owner":"parantapa","description":"Generated Type Annotated Python from Annotated SQL","archived":false,"fork":false,"pushed_at":"2023-05-29T20:41:10.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2023-09-30T19:45:40.610Z","etag":null,"topics":[],"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/parantapa.png","metadata":{"files":{"readme":"README.rst","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":"2021-09-14T19:22:26.000Z","updated_at":"2021-10-11T18:02:42.000Z","dependencies_parsed_at":"2023-02-08T01:15:42.481Z","dependency_job_id":null,"html_url":"https://github.com/parantapa/sqlpygen","commit_stats":null,"previous_names":[],"tags_count":4,"template":null,"template_full_name":null,"purl":"pkg:github/parantapa/sqlpygen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parantapa%2Fsqlpygen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parantapa%2Fsqlpygen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parantapa%2Fsqlpygen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parantapa%2Fsqlpygen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parantapa","download_url":"https://codeload.github.com/parantapa/sqlpygen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parantapa%2Fsqlpygen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478106,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T06:30:42.265Z","status":"ssl_error","status_checked_at":"2026-01-16T06:30:16.248Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-01-16T11:00:16.237Z","updated_at":"2026-01-16T11:00:22.066Z","avatar_url":"https://github.com/parantapa.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"SqlPyGen: Generate Type Annotated Python from Annotated SQL\n===========================================================\n\nsqlpygen is a utility to generate\ntype annotated Python code from annotated SQL.\n\nThe current version of the tool only supports\ngenerating code for SQLite3.\n\nInstallation\n------------\n\nYou can install SqlPyGen using pip.\n\n.. code:: bash\n\n   $ pip install sqlpygen\n\nExample Usage\n-------------\n\nWhen using sqlpygen to generate Python code from SQL,\none creates an annotated SQL file.\n\n.. code:: sql\n\n  # example1.sql\n  # This is an example annotated sql file.\n\n  # Lines starting with # are ignored by SqlPyGen.\n  # Lines starting with -- are used to provide SqlPyGen with annotations.\n\n  # Using the \"module\" annotation\n  # we name the python module to be generated.\n  -- module: example1\n\n  # We use \"schema\" annotations to annotate\n  # create table and create index sql statements.\n  # The statements are given a name which is used in the generated code\n  # to produce better error messages.\n  # All SQL statements must end with a semicolon.\n  -- schema: table_stocks\n\n  CREATE TABLE stocks (\n      date text,\n      trans text,\n      symbol text,\n      qty real,\n      price real\n  ) ;\n\n  # Here we annotate a query.\n  # The name of the query is used as the name of the function that is generated.\n  # The query parameters are named and annotated with types.\n  # The names can then be used in the query.\n  # Since this query doesn't specify a return annotation,\n  # SqlPyGen assumes that this SQL statement doesn't return anything.\n  # The types here are builtin Python types.\n  # By marking types ! at their end, we inform SqlPyGen,\n  # that the specific parameter may never by None.\n  -- query: insert_into_stocks\n  -- params: (date: str!, trans: str!, symbol: str!, qty: float, price: float)\n\n  INSERT INTO stocks VALUES (:date, :trans, :symbol, :qty, :price) ;\n\n  # Here we annotate a query with no parameters\n  # but one that returns some columns.\n  # The return annotation defines a row type that SqlPyGen will define\n  # and return instances of.\n  # In this case SqlPyGen will generate a Python dataclass called StockRow.\n  # The \"return*\" annotation tells SqlPyGen that this query may return\n  # zero or more rows.\n  # The following query is annotated with \"return?\",\n  # tells SqlPyGen that it will return zero or exactly one row.\n  -- query: select_from_stocks\n  -- return*: StockRow(date: str, trans: str, symbol: str, qty: float, price: float)\n\n  SELECT * FROM stocks ;\n\n  -- query: count_stocks\n  -- return?: int!\n\n  SELECT COUNT(*) FROM stocks ;\n\nCopy and save the above file as ``example1.sql``.\n\nNext use the following command to generate the python code.\n\n.. code:: bash\n\n   $ sqlpygen -i example1.sql -o example1.py -d sqlite3\n\nTo check the syntax of the sql statements are correct\none can execute the generated python file.\n\n.. code:: bash\n\n  $ python example1.py\n  Query insert_into_stocks is syntactically valid.\n  Query select_from_stocks is syntactically valid.\n  Query count_stocks is syntactically valid.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparantapa%2Fsqlpygen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparantapa%2Fsqlpygen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparantapa%2Fsqlpygen/lists"}