{"id":22344047,"url":"https://github.com/jacopodl/jschema2py","last_synced_at":"2026-05-09T06:37:11.560Z","repository":{"id":62572739,"uuid":"140569320","full_name":"jacopodl/JSchema2py","owner":"jacopodl","description":"jsonschema to python class converter","archived":false,"fork":false,"pushed_at":"2018-07-14T12:52:13.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-31T11:29:00.639Z","etag":null,"topics":["jschema2py","json","jsonschema","library","python3","schema"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jacopodl.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}},"created_at":"2018-07-11T12:03:09.000Z","updated_at":"2021-07-28T03:21:55.000Z","dependencies_parsed_at":"2022-11-03T18:26:40.637Z","dependency_job_id":null,"html_url":"https://github.com/jacopodl/JSchema2py","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacopodl%2FJSchema2py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacopodl%2FJSchema2py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacopodl%2FJSchema2py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacopodl%2FJSchema2py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jacopodl","download_url":"https://codeload.github.com/jacopodl/JSchema2py/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245632424,"owners_count":20647193,"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":["jschema2py","json","jsonschema","library","python3","schema"],"created_at":"2024-12-04T09:07:47.522Z","updated_at":"2026-05-09T06:37:11.516Z","avatar_url":"https://github.com/jacopodl.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSchema2py #\nJSchema2py is able to generate python classes starting from JSONSchema and provides the automatic support for types\nand constraints checking.\n\n## Installation\nThe package can be installed through pip:\n\n    $ pip install jschema2py\n\nor downloaded from [GitHub](https://github.com/jacopodl/jschema2py).\n\n## Examples\nFor example, given the following schema:\n```json\n{\n  \"title\": \"UserInfo\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"name\": {\n      \"type\": \"string\",\n      \"pattern\": \"^[^a-z0-9]\"\n    },\n    \"userName\": {\n      \"type\": \"string\"\n    },\n    \"age\": {\n      \"type\": \"integer\",\n      \"minimum\": 0,\n      \"maximum\": 100\n    }\n  }\n}\n```\njschema2py can easily convert it into python class in this way (Assume here that the schema is stored into variable \ncalled schema):\n```python\nfrom jschema2py import build_class\nUserInfo = build_class(schema)\nuser = UserInfo()\nuser.name = \"Jacopo\"\nuser.userName = \"JDL\"\nuser.age = 24\nprint(user)\n```\nvalidation will be performed on the object manipulation:\n```python\nuser.name = \"jacopo\" # raise ConstraintError (pattern: ^[^a-z0-9])\nuser.age = \"24\" # raise TypeError\n```\nThe object can be serialized into a JSON document:\n```python\njsdoc = str(user)\n```\n### Accessing generated classes\nIf one of the property of the schema refers to another object, you can access the class that represents the referred \nobject by using method get_class:\n```json\n{\n  \"title\": \"Nested\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"inner\": {\n      \"title\": \"Inner\",\n      \"type\": \"object\",\n      \"properties\": {\n        \"string\": {\n          \"type\": \"string\",\n          \"default\": \"I'm inner!\"\n        }\n      }\n    }\n  }\n}\n```\n```python\nfrom jschema2py import build_class\nNested = build_class(schema)\nnested = Nested()\nnested.inner = nested.get_class(\"inner\")() # Gets the class associated with the property \"inner\" \nprint(nested.inner.string)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacopodl%2Fjschema2py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacopodl%2Fjschema2py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacopodl%2Fjschema2py/lists"}