{"id":31907895,"url":"https://github.com/davidohnee/pyaddict","last_synced_at":"2025-12-13T17:38:51.396Z","repository":{"id":62172714,"uuid":"558519898","full_name":"davidohnee/pyaddict","owner":"davidohnee","description":"pyaddict - yet another dict library","archived":false,"fork":false,"pushed_at":"2025-09-11T18:18:06.000Z","size":763,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-11T21:21:50.791Z","etag":null,"topics":["dict","json","list","mypy","pyaddict","pylint","python","python-library","typing"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/pyaddict/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidohnee.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,"zenodo":null}},"created_at":"2022-10-27T18:00:00.000Z","updated_at":"2025-09-11T18:16:17.000Z","dependencies_parsed_at":"2025-05-12T19:59:20.453Z","dependency_job_id":"f82f9385-0d75-4981-9b3e-c034c257c0eb","html_url":"https://github.com/davidohnee/pyaddict","commit_stats":null,"previous_names":["davidohnee/pyaddict","dxstiny/pyaddict"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/davidohnee/pyaddict","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidohnee%2Fpyaddict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidohnee%2Fpyaddict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidohnee%2Fpyaddict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidohnee%2Fpyaddict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidohnee","download_url":"https://codeload.github.com/davidohnee/pyaddict/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidohnee%2Fpyaddict/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279015909,"owners_count":26085777,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["dict","json","list","mypy","pyaddict","pylint","python","python-library","typing"],"created_at":"2025-10-13T15:18:28.270Z","updated_at":"2025-10-13T15:18:30.269Z","avatar_url":"https://github.com/davidohnee.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pyaddict\n\n[![PyPI version](https://badge.fury.io/py/pyaddict.svg)](https://badge.fury.io/py/pyaddict)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/pyaddict.svg)](https://pypi.python.org/pypi/pyaddict/)\n[![PyPI license](https://img.shields.io/pypi/l/pyaddict.svg)](https://pypi.python.org/pypi/pyaddict/)\n\n## Description\nYet another python library to safely work with json data. It implements many useful features such as optional chaining, schema validation, type casting, safe indexing and default values.\n\n## Installation\n```bash\npip install pyaddict\n```\n\n## Usage\n```python\nfrom pyaddict import JDict, JList\nfrom pyaddict.schema import Object, String, Integer, Array\n\njdict = JDict({\n    \"name\": \"John\",\n    \"age\": 30,\n    \"cars\": [\n        {\"model\": \"BMW 230\", \"mpg\": 27.5},\n        {\"model\": \"Ford Edge\", \"mpg\": 24.1}\n    ]\n})\n\n# dicts\nprint(jdict.ensure(\"name\", str))  # John\nprint(jdict.ensure(\"age\", int))  # 30\nprint(jdict.ensure(\"age\", str))  # \"\"\nprint(jdict.ensureCast(\"age\", str))  # \"30\"\nprint(jdict.optionalGet(\"age\", str)) # None\nprint(jdict.optionalCast(\"age\", str))  # \"30\"\nprint(jdict.optionalGet(\"gender\", str)) # None\nprint(jdict.optionalCast(\"gender\", str)) # None\nprint(jdict.ensure(\"gender\", str)) # \"\"\n\n# lists\ncars = jdict.ensureCast(\"cars\", JList)\nprint(cars.assertGet(1, dict))  # {'model': 'Ford Edge', 'mpg': 24.1}\nprint(cars.assertGet(2, dict))  # AssertionError\n\n# iterators\nfor car in cars.iterator().ensureCast(JDict):\n    print(car.ensureCast(\"model\", str)) # BMW 230, Ford Edge\n\n# chaining\nchain = jdict.chain()\nprint(chain.ensureCast(\"cars[1].mpg\", str))  # \"24.1\"\nprint(chain.ensureCast(\"cars[2].mpg\", str))  # \"\"\n# or via direct access (returns Optional[Any]!)\nprint(chain[\"cars[2].mpg\"])  # IndexError\nprint(chain[\"cars[2]?.mpg\"])  # None\n\n# schema validation\nschema = Object({\n    \"name\": String(),\n    \"age\": String().coerce(),\n    \"dogs\": Array(String()).min(1).optional()\n}).withAdditionalProperties()\nprint(schema.error(jdict)) # None\n\nbadSchema = Object({\n    \"name\": String().min(5),\n    \"age\": Float(),\n    \"cars\": Object()\n})\nprint(badSchema.error(jdict)) # ValidationError(expected 4 to be greater than or equal to 5, name: min)\n\nstaticSchema = Object({\n    \"name\": \"John\",\n    \"age\": 30,\n    \"cars\": [\n        {\"model\": \"BMW 230\", \"mpg\": 27.5},\n        {\"model\": \"Ford Edge\", \"mpg\": 24.1}\n    ]\n})\nprint(staticSchema.error(jdict)) # None\n\nmixedSchema = Object({\n    \"name\": String().enum(\"John\"),\n    \"age\": 30,\n    \"dogs\": Array(String()).min(1).optional()\n}).withAdditionalProperties()\nprint(mixedSchema.error(jdict)) # None\n```\n\nThe library is fully typed and thus can be used with mypy \u0026 pylint. Check out the [wiki](https://github.com/dxstiny/pyaddict/wiki) for more information.\n\n## When to use\nWhen working with json data, it is common to have to deal with missing keys, wrong types, etc. This library provides a simple way to deal with these issues. Additionally, it provides easy-to-use typing support for mypy and pylint and detailed documentation.\nStarting with version 1.0.0, pyaddict includes a schema validation feature inspired by [zod](https://github.com/colinhacks/zod). It is especially useful when validating user input, e.g. in web applications.\n\n## License\n[MIT](LICENSE)\n\n## Author\n[dxstiny](https://github.com/dxstiny)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidohnee%2Fpyaddict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidohnee%2Fpyaddict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidohnee%2Fpyaddict/lists"}