{"id":44131153,"url":"https://github.com/textbook/pydantic_json_patch","last_synced_at":"2026-02-25T19:14:05.277Z","repository":{"id":336753338,"uuid":"1151001733","full_name":"textbook/pydantic_json_patch","owner":"textbook","description":"Pydantic models for implementing JSON Patch","archived":false,"fork":false,"pushed_at":"2026-02-25T10:01:05.000Z","size":1395,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-25T14:27:21.497Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pypi.org/project/pydantic-json-patch/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/textbook.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"ko_fi":"textbook"}},"created_at":"2026-02-05T23:55:41.000Z","updated_at":"2026-02-25T10:01:19.000Z","dependencies_parsed_at":"2026-02-06T10:05:15.904Z","dependency_job_id":null,"html_url":"https://github.com/textbook/pydantic_json_patch","commit_stats":null,"previous_names":["textbook/pydantic_json_patch"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/textbook/pydantic_json_patch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textbook%2Fpydantic_json_patch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textbook%2Fpydantic_json_patch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textbook%2Fpydantic_json_patch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textbook%2Fpydantic_json_patch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/textbook","download_url":"https://codeload.github.com/textbook/pydantic_json_patch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textbook%2Fpydantic_json_patch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29835589,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T19:08:47.527Z","status":"ssl_error","status_checked_at":"2026-02-25T18:59:04.705Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":[],"created_at":"2026-02-08T22:11:23.019Z","updated_at":"2026-02-25T19:14:05.250Z","avatar_url":"https://github.com/textbook.png","language":"Python","funding_links":["https://ko-fi.com/textbook"],"categories":[],"sub_categories":[],"readme":"# Pydantic JSON Patch\n\n[![Python uv CI][ci-badge]][ci-page]\n[![Coverage Status][coverage-badge]][coverage-page]\n[![PyPI - Version][pypi-badge]][pypi-page]\n\n[Pydantic] models for implementing [JSON Patch].\n\n## Installation\n\n_Pydantic JSON Patch_ is published to [PyPI], and can be installed with e.g.:\n\n```shell\npip install pydantic-json-patch\n```\n\n## Models\n\nA model is provided for each of the six JSON Patch operations:\n\n- `AddOp`\n- `CopyOp`\n- `MoveOp`\n- `RemoveOp`\n- `ReplaceOp`\n- `TestOp`\n\nAs repeating the op is a bit awkward (`CopyOp(op=\"copy\", ...)`), a `create` factory method is available:\n\n```python\n\u003e\u003e\u003e from pydantic_json_patch import AddOp\n\u003e\u003e\u003e op = AddOp.create(path=\"/foo/bar\", value=123)\n\u003e\u003e\u003e op\nAddOp(op='add', path='/foo/bar', value=123)\n\u003e\u003e\u003e op.model_dump_json()\n'{\"op\":\"add\",\"path\":\"/foo/bar\",\"value\":123}'\n\n```\n\nThe operations that take a value (`AddOp`, `ReplaceOp`, and `TestOp`) are generic, so you can parameterize them with a specific value type:\n\n```python\n\u003e\u003e\u003e from pydantic_json_patch import ReplaceOp\n\u003e\u003e\u003e op = ReplaceOp[str].create(path=\"/foo/bar\", value=\"hello\")\n\u003e\u003e\u003e op\nReplaceOp[str](op='replace', path='/foo/bar', value='hello')\n\n```\n\nAdditionally, there are two compound models:\n\n- `Operation` is the union of all the operators; and\n- `JsonPatch` represents a list of that union type.\n\n### Pointer tokens\n\nThe `path` property (and `from` property, where present) of an operation is a [JSON Pointer].\nThis means that any `~` or `/` characters in property names need to be properly encoded.\nTo aid working with these, the models expose a read-only `path_tokens` property (and, where appropriate, `from_tokens`):\n\n```python\n\u003e\u003e\u003e from pydantic_json_patch import CopyOp\n\u003e\u003e\u003e op = CopyOp.model_validate_json('{\"op\":\"copy\",\"path\":\"/foo/bar~1new\",\"from\":\"/foo/bar~0old\"}')\n\u003e\u003e\u003e op\nCopyOp(op='copy', path='/foo/bar~1new', from_='/foo/bar~0old')\n\u003e\u003e\u003e op.path_tokens\n('foo', 'bar/new')\n\u003e\u003e\u003e op.from_tokens\n('foo', 'bar~old')\n\n```\n\nSimilarly, the `create` factory methods can accept sequences of tokens, and will encode them appropriately:\n\n```python\n\u003e\u003e\u003e from pydantic_json_patch import TestOp\n\u003e\u003e\u003e op = TestOp.create(path=(\"annotations\", \"scope/value\"), value=None)\n\u003e\u003e\u003e op\nTestOp(op='test', path='/annotations/scope~1value', value=None)\n\u003e\u003e\u003e op.model_dump_json()\n'{\"op\":\"test\",\"path\":\"/annotations/scope~1value\",\"value\":null}'\n\n```\n\n## FastAPI\n\nYou can use this package to validate a JSON Patch endpoint in a FastAPI application, for example:\n\n```python\nimport typing as tp\nfrom uuid import UUID\n\nfrom fastapi import Body, FastAPI\n\nfrom pydantic_json_patch import JsonPatch\n\napp = FastAPI()\n\n\n@app.patch(\"/resource/{resource_id}\")\ndef _(resource_id: UUID, operations: tp.Annotated[JsonPatch, Body()]) -\u003e ...:\n    ...\n```\n\nThis will provide a sensible example of the request body:\n\n[![Screenshot of Swagger UI request body example][swagger-example]][swagger-example]\n\nand list the models along with the other schemas:\n\n[![Screenshot of Swagger UI schema list][swagger-schemas]][swagger-schemas]\n\n## Development\n\nThis project uses [uv] for managing dependencies.\nHaving installed uv, you can set the project up for local development with:\n\n```shell\nuv sync\nuv run pre-commit install\n```\n\nThe pre-commit hooks will ensure that the code style checks (using [isort] and [ruff]) are applied.\n\n### Testing\n\nThe test suite uses [pytest] and can be run with:\n\n```shell\nuv run pytest\n```\n\nAdditionally, there is [ty] type-checking that can be run with:\n\n```shell\nuv run ty check\n```\n\n### FastAPI\n\nYou can preview the FastAPI/Swagger documentation by running:\n\n```shell\nuv run fastapi dev tests/app.py\n```\n\nand visiting the Documentation link that's logged in the console.\nThis will auto-restart as you make changes.\n\n  [ci-badge]: https://github.com/textbook/pydantic_json_patch/actions/workflows/push.yml/badge.svg\n  [ci-page]: https://github.com/textbook/pydantic_json_patch/actions/workflows/push.yml\n  [coverage-badge]: https://coveralls.io/repos/github/textbook/pydantic_json_patch/badge.svg?branch=main\n  [coverage-page]: https://coveralls.io/github/textbook/pydantic_json_patch?branch=main\n  [fastapi]: https://fastapi.tiangolo.com/\n  [isort]: https://pycqa.github.io/isort/\n  [json patch]: https://datatracker.ietf.org/doc/html/rfc6902/\n  [json pointer]: https://datatracker.ietf.org/doc/html/rfc6901/\n  [pydantic]: https://docs.pydantic.dev/latest/\n  [pypi]: https://pypi.org/\n  [pypi-badge]: https://img.shields.io/pypi/v/pydantic-json-patch?logo=python\u0026logoColor=white\u0026label=PyPI\n  [pypi-page]: https://pypi.org/project/pydantic-json-patch/\n  [pytest]: https://docs.pytest.org/en/stable/\n  [ruff]: https://docs.astral.sh/ruff/\n  [swagger-example]: https://github.com/textbook/pydantic_json_patch/blob/main/docs/swagger-example.png?raw=true\n  [swagger-schemas]: https://github.com/textbook/pydantic_json_patch/blob/main/docs/swagger-schemas.png?raw=true\n  [ty]: https://docs.astral.sh/ty/\n  [uv]: https://docs.astral.sh/uv/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftextbook%2Fpydantic_json_patch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftextbook%2Fpydantic_json_patch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftextbook%2Fpydantic_json_patch/lists"}