{"id":13709295,"url":"https://github.com/selik/destructure","last_synced_at":"2025-05-06T15:32:35.498Z","repository":{"id":62567812,"uuid":"59872072","full_name":"selik/destructure","owner":"selik","description":"Easy declarative schema validation with optional name-binding. Gives Python a switch/case.","archived":false,"fork":false,"pushed_at":"2016-08-24T13:53:22.000Z","size":24,"stargazers_count":9,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-13T19:39:48.590Z","etag":null,"topics":[],"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/selik.png","metadata":{"files":{"readme":"README.rst","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":"2016-05-28T01:39:55.000Z","updated_at":"2023-10-18T23:33:07.000Z","dependencies_parsed_at":"2022-11-03T17:02:12.479Z","dependency_job_id":null,"html_url":"https://github.com/selik/destructure","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/selik%2Fdestructure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selik%2Fdestructure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selik%2Fdestructure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selik%2Fdestructure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/selik","download_url":"https://codeload.github.com/selik/destructure/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252713029,"owners_count":21792416,"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-08-02T23:00:37.721Z","updated_at":"2025-05-06T15:32:31.189Z","avatar_url":"https://github.com/selik.png","language":"Python","readme":"#################\n   destructure\n#################\n\nEasy declarative schema validation with optional name-binding.\n\n.. code:: python\n\n    \u003e\u003e\u003e from destructure import Binding, match\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e o = Binding()\n    \u003e\u003e\u003e schema = {\n    ...     'string': str,\n    ...     'any': ...,\n    ...     'binding': o.name,\n    ...     'sequence': [1, 2, ...],\n    ...     'mapping': {'a': int, ...: ...},\n    ... }\n    \u003e\u003e\u003e data = {\n    ...     'string': 'a',\n    ...     'any': 5j,\n    ...     'binding': 42,\n    ...     'sequence': [1, 2, 3, 4],\n    ...     'mapping': {'a': 1, 'b': 2, 'c': 3},\n    ... }\n    \u003e\u003e\u003e guard = lambda : o.name \u003e 10\n    \u003e\u003e\u003e data == match(schema, data, guard)\n    True\n    \u003e\u003e\u003e o.name\n    42\n\n\nPick between several schemas with a handy ``Switch.case``.\n\n.. code:: python\n\n    \u003e\u003e\u003e from destructure import Binding, Switch\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e o = Binding()\n    \u003e\u003e\u003e schema1 = [1, o.x, 3]\n    \u003e\u003e\u003e schema2 = [2, 4, o.x]\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e s = Switch([2, 4, 6])\n    \u003e\u003e\u003e if s.case(schema1):\n    ...     print(o.x)\n    ... elif s.case(schema2):\n    ...     print(o.x)\n    ... else:\n    ...     print('otherwise')\n    6\n\nSchemas may include many kinds of objects, though to make use of\nEllipses or Binding, the class must support keyword arguments and\ncannot be too strict with parameter type-checking.\n\n.. code:: python\n\n    \u003e\u003e\u003e class Foo:\n    ...     def __init__(self, bar):\n    ...         self.bar = bar\n    \u003e\u003e\u003e bind = Binding()\n    \u003e\u003e\u003e schema = Foo(bar=bind.x)\n    \u003e\u003e\u003e result = match(schema, Foo(bar=1))\n    \u003e\u003e\u003e bind.x\n    1\n\n\nSee some `example scripts`_ for a practical usage, in context.\n\n.. _`example scripts`: http://github.com/selik/destructure/tree/master/examples\n","funding_links":[],"categories":["Libraries in Python","Data validation"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselik%2Fdestructure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fselik%2Fdestructure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselik%2Fdestructure/lists"}