{"id":13424665,"url":"https://github.com/dmontagu/fastapi_client","last_synced_at":"2025-04-06T03:08:21.234Z","repository":{"id":36037512,"uuid":"200362987","full_name":"dmontagu/fastapi_client","owner":"dmontagu","description":"FastAPI client generator","archived":false,"fork":false,"pushed_at":"2023-07-06T21:45:13.000Z","size":128,"stargazers_count":337,"open_issues_count":11,"forks_count":44,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-30T12:34:55.465Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmontagu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.TXT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-08-03T10:35:23.000Z","updated_at":"2025-03-15T01:38:00.000Z","dependencies_parsed_at":"2024-01-03T02:29:54.025Z","dependency_job_id":"b141f04d-6217-420f-aeef-d680198be55d","html_url":"https://github.com/dmontagu/fastapi_client","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmontagu%2Ffastapi_client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmontagu%2Ffastapi_client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmontagu%2Ffastapi_client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmontagu%2Ffastapi_client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmontagu","download_url":"https://codeload.github.com/dmontagu/fastapi_client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247427006,"owners_count":20937201,"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":[],"created_at":"2024-07-31T00:00:57.523Z","updated_at":"2025-04-06T03:08:21.211Z","avatar_url":"https://github.com/dmontagu.png","language":"Python","readme":"# FastAPI-based API Client Generator\n\n**Generate a mypy- and IDE-friendly API client from an OpenAPI spec.**\n\n* Sync and async interfaces are both available\n* Comes with support for the OAuth2.0 password flow\n* Easily extended, with built-in support for request middleware\n* Designed for integration with FastAPI, but should work with most OpenAPI specs\n* Makes use of https://github.com/OpenAPITools/openapi-generator\n\nLook inside `example/client` to see an example of the generated output!\n\n----\n\n*Warning: This is still in the proof-of-concept phase, and should not yet be considered to have a stable interface.* \n* Some OpenAPI features (like discriminator fields) are not yet supported.\n* While the goal is to support any OpenAPI spec, it is most likely to work well with specs generated by FastAPI.\n\nIf you try this out, please help me by reporting any issues you notice!\n\n## Client library usage\n\n```python\nfrom client.api_client import ApiClient, AsyncApis, SyncApis\nfrom client.models import Pet\n\nclient = ApiClient(host=\"http://localhost\")\nsync_apis = SyncApis(client)\nasync_apis = AsyncApis(client)\n\npet_1 = sync_apis.pet_api.get_pet_by_id(pet_id=1)\nassert isinstance(pet_1, Pet)\n\nasync def get_pet_2() -\u003e Pet:\n    pet_2 = await async_apis.pet_api.get_pet_by_id(pet_id=2)\n    assert isinstance(pet_2, Pet)\n    return pet_2\n```\n\nThe example generated client library is contained in `example/client`.\n\nGenerated clients will have the following dependencies:\n\n* `pydantic` for models\n* `httpx` for networking\n* `fastapi` for `jsonable_encoder` and OAuth models (I hope to eventually remove this as a dependency)\n* `typing_extensions` for Enums via `Literal` (I eventually hope to replace this with standard enums)\n\nMore examples of usage (including auth) are contained in `example/usage_example.py`. \n\n## Generating the client library\n\nUsing the generator looks like\n```bash\n./scripts/generate.sh -i \u003copenapi_json\u003e -p \u003cpackage_name\u003e -o \u003coutput_path\u003e\n  [-n \u003cimport_name\u003e] [--include-auth]\n  [--] [*openapi-generator-args]\n```\nand will produce a client library at `\u003coutput_path\u003e/\u003cpackage_name\u003e`.\n\nThe OpenAPI json input can be either a URL or a local file path.\n\nFor example, running\n```bash\n./scripts/generate.sh \\\n  -i https://petstore.swagger.io/v2/swagger.json \\\n  -p client \\\n  -o generated \\\n  -n example.client \\\n  --include-auth\n```\nproduces the example client (along with the OAuth2.0 password flow client), places it in `generated/client`, and\nmakes any generated client-referencing imports start with `example.client`.\n\n(Note: to prevent accidental overwrites, you would need to manually remove `generated/client` if it already exists.)\n\n### With FastAPI\n\n* To generate a client for a default FastAPI app running on localhost (NOT inside a docker container):\n\n        ./scripts/generate.sh -i http://localhost/openapi.json -p my_client -o generated\n\n* Since the generator runs inside docker, if your server is also running in a docker container on the same machine,\n[you may need to provide a special hostname](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach).\nPassing the `--map-localhost` argument will make the script attempt to perform this automatically:\n \n        ./scripts/generate.sh --map-localhost -i http://localhost/openapi.json -p my_client -o generated\n        # Transforms the input to http://host.docker.internal/openapi.json \n\n### With package metadata\n\nIf you want generate not only a code, but also a package metadata (e.g. setup.py) for publishing or distributing \nautogenerated client you can use a `--with-meta` flag.\n\n### Generation details\n\n* The only local dependencies for generation are `docker` and standard command line tools.\n* `openapi-generator` is used to generate the code from the openapi spec\n    * The custom templates are located in `openapi-python-templates`\n* `autoflake`, `isort`, and `black` are used to format the code after generation\n\n\n## Contributing\n\nThere are a variety of make rules for setup/testing; here are some highlights:\n* `make develop`: Sets up the local development environment.\n* `make regenerate`: Regenerates the example client from the example's openapi.json and the templates.\n    * Note: *This will overwrite changes!* Make sure you commit (or edit the templates) before running this.\n* `make`: Checks that isort, black, flake8, mypy, and pytest all pass\n* `make testcov`: Generates a coverage report for the tests.\n \nPull requests are welcome and appreciated!\n","funding_links":[],"categories":["Third-Party Extensions","Python","Packages","HarmonyOS"],"sub_categories":["Developer Tools","Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmontagu%2Ffastapi_client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmontagu%2Ffastapi_client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmontagu%2Ffastapi_client/lists"}