{"id":14986691,"url":"https://github.com/jdkandersson/openalchemy","last_synced_at":"2025-08-21T12:30:47.894Z","repository":{"id":35056927,"uuid":"201582900","full_name":"jdkandersson/OpenAlchemy","owner":"jdkandersson","description":"Define SQLAlchemy models using the OpenAPI specification.","archived":false,"fork":false,"pushed_at":"2023-03-01T00:59:37.000Z","size":3547,"stargazers_count":48,"open_issues_count":29,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-01T15:13:44.839Z","etag":null,"topics":["openapi","openapi-specification","openapi3","python","python3","sqlalchemy","sqlalchemy-models","sqlalchemy-python"],"latest_commit_sha":null,"homepage":"https://openapi-sqlalchemy.readthedocs.io/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jdkandersson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null},"funding":{"github":"jdkandersson"}},"created_at":"2019-08-10T05:09:36.000Z","updated_at":"2024-04-24T05:01:32.000Z","dependencies_parsed_at":"2023-08-27T10:30:23.023Z","dependency_job_id":"a5bf9351-09e3-4b52-acd5-74ef7163f1e3","html_url":"https://github.com/jdkandersson/OpenAlchemy","commit_stats":{"total_commits":2094,"total_committers":15,"mean_commits":139.6,"dds":"0.15568290353390635","last_synced_commit":"28b32ed4320c19c93d3636f0b5ef059b5345ad4d"},"previous_names":["jdkandersson/openapi-sqlalchemy"],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdkandersson%2FOpenAlchemy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdkandersson%2FOpenAlchemy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdkandersson%2FOpenAlchemy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdkandersson%2FOpenAlchemy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jdkandersson","download_url":"https://codeload.github.com/jdkandersson/OpenAlchemy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230511482,"owners_count":18237658,"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":["openapi","openapi-specification","openapi3","python","python3","sqlalchemy","sqlalchemy-models","sqlalchemy-python"],"created_at":"2024-09-24T14:13:21.750Z","updated_at":"2024-12-19T23:14:59.878Z","avatar_url":"https://github.com/jdkandersson.png","language":"Python","readme":"# OpenAlchemy\n\n![Code Quality Status](https://github.com/jdkandersson/OpenAlchemy/workflows/Code%20quality%20checks/badge.svg)\n![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/anderssonpublic/anderssonpublic/1)\n[![Documentation Status](https://readthedocs.org/projects/openapi-sqlalchemy/badge/?version=latest)](https://openapi-sqlalchemy.readthedocs.io/en/latest/?badge=latest)\n![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/jdkandersson/OpenAlchemy)\n![Code Climate technical debt](https://img.shields.io/codeclimate/tech-debt/jdkandersson/OpenAlchemy)\n![LGTM Grade](https://img.shields.io/lgtm/grade/python/github/jdkandersson/OpenAlchemy)\n\nTranslates an OpenAPI schema to SQLAlchemy models.\n\nSupports OpenAPI 3.0 and 3.1.\n\n## Installation\n\n```bash\npython -m pip install OpenAlchemy\n# To be able to load YAML file\npython -m pip install OpenAlchemy[yaml]\n```\n\n## Example\n\nFor example, given the following OpenAPI specification:\n\n```yaml\n# ./examples/simple/example-spec.yml\nopenapi: \"3.0.0\"\n\ninfo:\n  title: Test Schema\n  description: API to illustrate OpenAlchemy MVP.\n  version: \"0.1\"\n\npaths:\n  /employee:\n    get:\n      summary: Used to retrieve all employees.\n      responses:\n        200:\n          description: Return all employees from the database.\n          content:\n            application/json:\n              schema:\n                type: array\n                items:\n                  \"$ref\": \"#/components/schemas/Employee\"\n\ncomponents:\n  schemas:\n    Employee:\n      description: Person that works for a company.\n      type: object\n      x-tablename: employee\n      properties:\n        id:\n          type: integer\n          description: Unique identifier for the employee.\n          example: 0\n          x-primary-key: true\n          x-autoincrement: true\n        name:\n          type: string\n          description: The name of the employee.\n          example: David Andersson\n          x-index: true\n        division:\n          type: string\n          description: The part of the company the employee works in.\n          example: Engineering\n          x-index: true\n        salary:\n          type: number\n          description: The amount of money the employee is paid.\n          example: 1000000.00\n      required:\n        - id\n        - name\n        - division\n```\n\nThe SQLALchemy models file then becomes:\n\n```python\n# models.py\nfrom open_alchemy import init_yaml\n\ninit_yaml(\"./examples/simple/example-spec.yml\")\n```\n\nThe _Base_ and _Employee_ objects can be accessed:\n\n```python\nfrom open_alchemy.models import Base\nfrom open_alchemy.models import Employee\n```\n\nWith the _models_filename_ parameter a file is auto generated with type hints\nfor the SQLAlchemy models at the specified location, for example:\n[type hinted models example](examples/simple/models_auto.py). This adds support\nfor IDE auto complete, for example for the model initialization:\n\n![autocomplete init](examples/simple/models_autocomplete_init.png)\n\nand for properties and methods available on an instance:\n\n![autocomplete instance](examples/simple/models_autocomplete_instance.png)\n\nAn extensive set of examples with a range of features is here:\n\n[examples for main features](examples)\n\nAn example API has been defined using connexion and Flask here:\n\n[example connexion app](examples/app)\n\n## Documentation\n\n[Read the Docs](https://openapi-sqlalchemy.readthedocs.io/en/latest/)\n\n## Buy me a coffee\n\n[![Buy Me A Coffee](https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png)](https://www.buymeacoffee.com/jdkandersson)\n\n## Features\n\n- initializing from JSON,\n- initializing from YAML,\n- build a package with the models for distribution, packaged as sdist or wheel,\n- automatically generate a models file,\n- `integer` (32 and 64 bit),\n- `number` (float only),\n- `boolean`,\n- `string`,\n- `password`,\n- `byte`,\n- `binary`,\n- `date`,\n- `date-time`,\n- generic JSON data,\n- `$ref` references for columns and models,\n- remote `$ref` to other files on the same file system\n  (_not supported on Windows_),\n- remote `$ref` to other files at a URL,\n- primary keys,\n- auto incrementing,\n- indexes,\n- composite indexes,\n- unique constraints,\n- composite unique constraints,\n- column nullability,\n- foreign keys,\n- default values for columns (both application and database side),\n- many to one relationships,\n- one to one relationships,\n- one to many relationships,\n- many to many relationships,\n- many to many relationships with custom association tables,\n- custom foreign keys for relationships,\n- back references for relationships,\n- `allOf` inheritance for columns and models,\n- joined and single table inheritance,\n- `from_str` model methods to construct from JSON string,\n- `from_dict` model methods to construct from dictionaries,\n- `to_str` model methods to convert instances to JSON string,\n- `__str__` model methods to support the python `str` function,\n- `__repr__` model methods to support the python `repr` function,\n- `to_dict` model methods to convert instances to dictionaries,\n- `readOnly` and `writeOnly` for influence the conversion to and from\n  dictionaries,\n- exposing created models under `open_alchemy.models` removing the need for\n  `models.py` files,\n- ability to mix in arbitrary classes into a model,\n- can use the short `x-` prefix or a namespaced `x-open-alchemy-` prefix for\n  extension properties and\n- grouping models into schemas.\n\n## Contributing\n\nFork and checkout the repository. To install:\n\n```bash\npoetry install\n```\n\nTo run tests:\n\n```bash\npoetry run pytest\n```\n\nMake your changes and raise a pull request.\n\n## Compiling Docs\n\n```bash\npoetry shell\ncd docs\nmake html\n```\n\nThis creates the `index.html` file in `docs/build/html/index.html`.\n\n## Release Commands\n\n```bash\nrm -r dist/*\npoetry build\npoetry publish\n```\n","funding_links":["https://github.com/sponsors/jdkandersson","https://www.buymeacoffee.com/jdkandersson"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdkandersson%2Fopenalchemy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdkandersson%2Fopenalchemy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdkandersson%2Fopenalchemy/lists"}