{"id":14986656,"url":"https://github.com/kemingy/defspec","last_synced_at":"2025-04-11T21:31:33.144Z","repository":{"id":218208994,"uuid":"745519146","full_name":"kemingy/defspec","owner":"kemingy","description":"Create the OpenAPI spec and document from dataclass, attrs, etc.","archived":false,"fork":false,"pushed_at":"2025-01-19T13:32:13.000Z","size":43,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-06T07:17:23.014Z","etag":null,"topics":["openapi","openapi-spec","redoc","scalar","swagger"],"latest_commit_sha":null,"homepage":"","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/kemingy.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-19T14:09:52.000Z","updated_at":"2025-01-19T13:18:37.000Z","dependencies_parsed_at":"2024-01-20T13:27:56.624Z","dependency_job_id":"b93487fd-fb76-4602-a4c2-34fee063e3d4","html_url":"https://github.com/kemingy/defspec","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"895868af68310db1df557ab8bfa7af8a0ad9522b"},"previous_names":["kemingy/defspec"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kemingy%2Fdefspec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kemingy%2Fdefspec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kemingy%2Fdefspec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kemingy%2Fdefspec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kemingy","download_url":"https://codeload.github.com/kemingy/defspec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248482959,"owners_count":21111408,"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-spec","redoc","scalar","swagger"],"created_at":"2024-09-24T14:13:17.718Z","updated_at":"2025-04-11T21:31:33.136Z","avatar_url":"https://github.com/kemingy.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DefSpec\n\n[![Python Check](https://github.com/kemingy/defspec/actions/workflows/check.yml/badge.svg)](https://github.com/kemingy/defspec/actions/workflows/check.yml)\n[![PyPI](https://img.shields.io/pypi/v/defspec.svg)](https://pypi.org/project/defspec/)\n\nCreate the OpenAPI spec and document from `dataclass`, `attrs`, `msgspec`, etc.\n\n## Why not ...\n\n\u003e [!NOTE]\n\u003e There are also lots of other projects can generate the OpenAPI document or even validate the data. This project is **not** intended to replace them.\n\nThis project is a legacy of a private initiative. During the development, I discovered that using [`msgspec`](https://github.com/jcrist/msgspec) could elegantly define and generate the API schema. The OpenAPI component can be utilized to generate the API documentation for various projects. As a result, I made the decision to extract it and transform it into a public project.\n\nYou can use this project as a low-level component or a drop-in module when you don't want to introduce too many other dependencies.\n\n## Installation\n\n```bash\npip install defspec\n# to enable the offline feature\npip install defspec[offline]\n```\n\n## Examples\n\n- `flask`: [examples/flask](examples/flask_openapi.py)\n- `falcon`: [examples/falcon](examples/falcon_openapi.py)\n- `offline`: [examples/offline](examples/offline_openapi.py)\n\nYou can run the above examples and open the OpenAPI document in your browser:\n\n- `swagger`: http://127.0.0.1:8000/openapi/swagger\n- `redoc`: http://127.0.0.1:8000/openapi/redoc\n- `scalar`: http://127.0.0.1:8000/openapi/scalar\n\n## Usage\n\n```python\nfrom dataclasses import dataclass\nfrom typing import List\n\nfrom defspec import OpenAPI\n\n\n@dataclass\nclass User:\n    name: str\n    age: int\n\n\nopenapi = OpenAPI()\nopenapi.register_route(\"/\", method=\"get\", summary=\"Hello World\")\nopenapi.register_route(\n    \"/users\", method=\"post\", summary=\"Get all the user info\", response_type=List[User]\n)\n\n# get the OpenAPI spec\nprint(openapi.to_dict())\n# get the OpenAPI spec bytes\nwith open(\"openapi.json\", \"wb\") as f:\n    f.write(openapi.to_json())\n\n# serve as a HTTP server\nopenapi.serve_as_http_daemon(port=8000, run_in_background=True)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkemingy%2Fdefspec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkemingy%2Fdefspec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkemingy%2Fdefspec/lists"}