{"id":50172226,"url":"https://github.com/robertbetts/swagger-dialect","last_synced_at":"2026-05-24T23:38:40.625Z","repository":{"id":57677689,"uuid":"489960739","full_name":"robertbetts/swagger-dialect","owner":"robertbetts","description":"SQLAlchemy Swagger definition reflection ","archived":false,"fork":false,"pushed_at":"2022-05-09T08:45:02.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-24T23:38:37.787Z","etag":null,"topics":["dbapi","python","sqlalchemy","swagger","swagger-codegen"],"latest_commit_sha":null,"homepage":"","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/robertbetts.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":"2022-05-08T14:06:03.000Z","updated_at":"2025-11-24T15:20:07.000Z","dependencies_parsed_at":"2022-09-10T17:20:45.529Z","dependency_job_id":null,"html_url":"https://github.com/robertbetts/swagger-dialect","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/robertbetts/swagger-dialect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertbetts%2Fswagger-dialect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertbetts%2Fswagger-dialect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertbetts%2Fswagger-dialect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertbetts%2Fswagger-dialect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertbetts","download_url":"https://codeload.github.com/robertbetts/swagger-dialect/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertbetts%2Fswagger-dialect/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33455025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-24T19:21:36.376Z","status":"ssl_error","status_checked_at":"2026-05-24T19:21:10.562Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["dbapi","python","sqlalchemy","swagger","swagger-codegen"],"created_at":"2026-05-24T23:38:39.333Z","updated_at":"2026-05-24T23:38:40.619Z","avatar_url":"https://github.com/robertbetts.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swagger-dialect\nSQLAlchemy Swagger definition reflection \n\n*Swagger_DBAPI* : DBAPI compatible class that returns Swagger model definitions as:\n* Tables\n* Columns\n* Foreign key relationships\n\nVery important to Note, currently a primary key identity column `id` is added to each extracted table definition\n\n*SwaggerDialect* : SQLAlchemy dialect which can translate the schema extraction via Swagger_DBAPI into valid SQLAlchemy MetaData\n\nPython 10 support only as use is made of the new match statement syntax\n\nHere is an example where Python code is generated for SQLAlchemy from the Swagger definitions. (sqlacodegen\u003e=3.0rc1)\n\n```python\nimport logging\nimport argparse\nimport sys\nfrom contextlib import ExitStack\nfrom typing import TextIO\nfrom sqlalchemy.engine import create_engine\nfrom sqlalchemy.schema import MetaData\nfrom sqlacodegen.generators import DeclarativeGenerator\n\nfrom swagger_dialect import register_swagger_dialect\n\nLOGGING_FORMAT = \"[%(levelname)1.1s %(asctime)s.%(msecs)03d %(process)d %(module)s:%(lineno)d %(name)s] %(message)s\"\n\nregister_swagger_dialect()\n\n\ndef get_args():\n    parser = argparse.ArgumentParser(\n        description=\"Generates SQLAlchemy model code from an existing database.\"\n    )\n    parser.add_argument(\n        \"--option\", nargs=\"*\", help=\"options passed to the generator class\"\n    )\n    parser.add_argument(\n        \"--version\", action=\"store_true\", help=\"print the version number and exit\"\n    )\n    parser.add_argument(\n        \"--schemas\", help=\"load tables from the given schemas (comma separated)\"\n    )\n    parser.add_argument(\n        \"--tables\", help=\"tables to process (comma-separated, default: all)\"\n    )\n    parser.add_argument(\"--noviews\", action=\"store_true\", help=\"ignore views\")\n    parser.add_argument(\"--outfile\", help=\"file to write output to (default: stdout)\")\n    return parser.parse_args()\n\n\ndef run_reflection(url, model_file_name=None):\n\n    # Use reflection to fill in the metadata\n    engine = create_engine(url)\n    metadata = MetaData()\n    tables = None\n    incl_views = False\n    schemas = [None]\n    for schema in schemas:\n        metadata.reflect(engine, schema, incl_views, tables)\n\n    args = get_args()\n    generator = DeclarativeGenerator(metadata, engine, set(args.option or ()))\n\n    # Open the target file (if given)\n    with ExitStack() as stack:\n        outfile: TextIO\n        if model_file_name:\n            outfile = open(model_file_name, \"w\", encoding=\"utf-8\")\n            stack.enter_context(outfile)\n        else:\n            outfile = sys.stdout\n        outfile.write(generator.generate())\n\nif __name__ == \"__main__\":\n    run_reflection(url='swagger://MyAppSwagger.yaml', model_file_name=\"generated_model.py\")\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertbetts%2Fswagger-dialect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertbetts%2Fswagger-dialect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertbetts%2Fswagger-dialect/lists"}