{"id":27016385,"url":"https://github.com/ponytailer/pydantic-client","last_synced_at":"2025-04-04T15:19:54.476Z","repository":{"id":184948960,"uuid":"671367124","full_name":"ponytailer/pydantic-client","owner":"ponytailer","description":"Http client base pydantic, with requests,  aiohttp and httpx","archived":false,"fork":false,"pushed_at":"2024-10-30T03:14:24.000Z","size":175,"stargazers_count":13,"open_issues_count":5,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-30T05:13:27.557Z","etag":null,"topics":["aiohttp","http-client","httpx","pydantic","requests"],"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/ponytailer.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":"2023-07-27T06:50:49.000Z","updated_at":"2024-10-30T03:14:27.000Z","dependencies_parsed_at":"2023-07-31T04:42:48.876Z","dependency_job_id":"0c5f6de8-a8a1-43cc-90f8-4163196c0bf8","html_url":"https://github.com/ponytailer/pydantic-client","commit_stats":null,"previous_names":["ponytailer/pydantic-client"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ponytailer%2Fpydantic-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ponytailer%2Fpydantic-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ponytailer%2Fpydantic-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ponytailer%2Fpydantic-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ponytailer","download_url":"https://codeload.github.com/ponytailer/pydantic-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198427,"owners_count":20900082,"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":["aiohttp","http-client","httpx","pydantic","requests"],"created_at":"2025-04-04T15:19:53.965Z","updated_at":"2025-04-04T15:19:54.451Z","avatar_url":"https://github.com/ponytailer.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pydantic-client\n\n[![codecov](https://codecov.io/gh/ponytailer/pydantic-client/branch/main/graph/badge.svg?token=CZX5V1YP22)](https://codecov.io/gh/ponytailer/pydantic-client) [![Upload Python Package](https://github.com/ponytailer/pydantic-client/actions/workflows/python-publish.yml/badge.svg)](https://github.com/ponytailer/pydantic-client/actions/workflows/python-publish.yml)\n\nHttp client base pydantic with requests, aiohttp and httpx, support the json response or file(bytes).\n\n\n#### If you like this project, please star it.\n\n### How to install\n\n\u003e only support `requests`:\n\u003e\u003e pip install pydantic-client\n\n\u003e support `aiohttp` and `requests`:\n\u003e\u003e pip install \"pydantic-client[aiohttp]\"\n\n\u003e support `httpx(async)` and `requests`:\n\u003e\u003e pip install \"pydantic-client[httpx]\"\n\n\u003e support all:\n\u003e\u003e pip install \"pydantic-client[all]\"\n\n### How to use\n\n```python\nfrom pydantic import BaseModel\n\nfrom pydantic_client import delete, get, post, put, pydantic_client_manager\nfrom pydantic_client import ClientConfig\n\n\nclass Book(BaseModel):\n    name: str\n    age: int\n\n\n@pydantic_client_manager.register(\n    ClientConfig(\n        base_url=\"https://example.com\",\n        headers={\"Authorization\": \"Bearer abcdefg\"},\n        timeout=10\n    )\n)\nclass WebClient:\n\n    @get(\"/books/{book_id}?query={query}\")\n    def get_book(self, book_id: int, query: str) -\u003e Book:\n        ...\n\n    @post(\"/books\", form_body=True)\n    def create_book_form(self, book: Book) -\u003e Book:\n        \"\"\" will post the form with book\"\"\"\n        ...\n\n    @put(\"/books/{book_id}\")\n    def change_book(self, book_id: int, book: Book) -\u003e Book:\n        \"\"\"will put the json body\"\"\"\n        ...\n\n    @delete(\"/books/{book_id}\")\n    def change_book(self, book_id: int, request_headers: dict = None) -\u003e Book:\n        ...\n\n\nclient = pydantic_client_manager.get()\n# will get the book with book_id=1\nbook: Book = client.get_book(1)\n\n# request_headers will overwrite the headers in client_config\nclient.change_book(1, request_headers={\"Authorization\": \"Bearer abcdefg\"})\n\n```\n\nAnd see the examples.\n\n\n\u003cdetails\u003e\n\u003csummary\u003e Change Log \u003c/summary\u003e\n\n### v1.0.7: genearte client and schema code from swagger\n\n```shell\npydantic-client parse your-swagger-file.yaml\n```\nyou will get the code from output, above:\n\n```python\nfrom typing import Optional\nfrom pydantic import BaseModel\n\n\nclass FunctionAnalysisRequest(BaseModel):\n    project_name: str\n    struct_code: str\n    struct_level_code: str\n    struct_name: Optional[str]\n    function_type: str\n\n\n\nclass HTTPValidationError(BaseModel):\n    detail: list[str]\n\n\n\nclass LoseEffectRequest(BaseModel):\n    struct_name: Optional[str]\n    function_description: Optional[str]\n\n\n\nclass LoseEffectResponse(BaseModel):\n    failure_type_code: Optional[str]\n    failure_description: Optional[str]\n\n\nclass WebClient:\n\n    @get(\"/fmea-agent/v1/hello\")\n    def get_fmea_agent_v1_hello(self):\n        ...\n\n    @post(\"/fmea-agent/v1/function_analysis\")\n    def post_fmea_agent_v1_function_analysis(self, function_analysis_request: FunctionAnalysisRequest):\n        ...\n\n    @post(\"/fmea-agent/v1/lose_effect_analysis/{lose_id}\")\n    def post_fmea_agent_v1_lose_effect_analysis(self, lose_id: int, name: Optional[str], lose_effect_request: LoseEffectRequest):\n        ...\n```\n\n\n### v1.0.5: support file response type.\n\n```python\nfrom pydantic_client.schema.file import File\nfrom pydantic_client import post\n\n@post(\"/download\")\ndef download_file(self) -\u003e File:\n    # you will get the bytes content of the file\n    ...\n\n```\n\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fponytailer%2Fpydantic-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fponytailer%2Fpydantic-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fponytailer%2Fpydantic-client/lists"}