{"id":19383479,"url":"https://github.com/bontail/pystrector","last_synced_at":"2025-04-23T21:31:56.625Z","repository":{"id":254191702,"uuid":"845758326","full_name":"bontail/pystrector","owner":"bontail","description":"Package for displaying and changing core Python structures","archived":false,"fork":false,"pushed_at":"2025-02-22T14:05:39.000Z","size":208,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T00:46:09.548Z","etag":null,"topics":["c","python3","structures"],"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/bontail.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":"2024-08-21T21:52:43.000Z","updated_at":"2025-02-22T14:05:43.000Z","dependencies_parsed_at":"2024-08-22T00:15:38.272Z","dependency_job_id":"27fbbfcf-ab68-4765-aed0-7c8fd8bd6df7","html_url":"https://github.com/bontail/pystrector","commit_stats":null,"previous_names":["bontail/pystrector"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bontail%2Fpystrector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bontail%2Fpystrector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bontail%2Fpystrector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bontail%2Fpystrector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bontail","download_url":"https://codeload.github.com/bontail/pystrector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250517869,"owners_count":21443855,"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":["c","python3","structures"],"created_at":"2024-11-10T09:26:22.078Z","updated_at":"2025-04-23T21:31:56.620Z","avatar_url":"https://github.com/bontail.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Pystrector \u003cbr\u003e\n\n### The **Py**_(thon)_ **Str**_(uct)_ _(Refl)_**ector**\n\n![icon](docs/pystrector_icon.png)\n\n---\n\nThe package for displaying and modifying Python's internal structures. \u003cbr\u003e Do you want to see how Python objects are arranged inside? \u003cbr\u003e Then this package is for you.\n\n```python\nfrom pystrector import Binder\nbinder = Binder()\nsome_object = 1\nreflector = binder.bind(some_object)\nprint(reflector.ob_base.ob_refcnt.pretty_value)\n```\n\n---\n\n### Python\n\nTo install pystrector, enter the command.\n\n```shell\npython3 -m pip install pystrector\n```\n\n---\n\n### Git\n\n```shell\ngit clone https://github.com/bontail/pystrector.git\n```\n\n---\n\n### Documentation\n\n[Russian](./docs/README-RU.md)\n\nTo access the representation of the basic structures, you need to create an anchor object\n\n```python\nfrom pystrector import Binder\nbinder = Binder()\n```\n\nNow you can call the binding method to get a class object representing the structure\n\n```python\nsome_object = 1\nreflector = binder.bind(some_object)\n```\n\nThe display object has all the same fields as the internal structure\n\n```c\n// core structure\nstruct _longobject {\n     PyObject ob_base;\n    _PyLongValue long_value;\n};\n```\n\n```python\nclass _longobject(DataType, is_union=False):\n    ob_base = _object()\n    long_value = _PyLongValue()\n```\n\nIf an object contains an anonymous_var, then you can go straight to the fields of this object\n\n```python\nclass anonymous_1(DataType, is_union=True):\n    ob_refcnt = LongLong()\n    ob_refcnt_split = UnsignedInt[2]\n\n    \nclass _object(DataType, is_union=False):\n    anonymous_var_1 = anonymous_1()\n    ob_type = Pointer(datatype=\"_typeobject\")\n\n\nsome_object = 1\nreflector = binder.bind(some_object).cast_to(_object)\n# print(reflector.anonymous_var_1.ob_refcnt.pretty_value)\nprint(reflector.ob_refcnt.pretty_value)\n```\n\nFor each type, you can call pretty_value and bytes_value \u003cbr\u003e\n**pretty_value** - will result in the most similar type in Python \u003cbr\u003e\n**bytes_value** - always returns bytearray \u003cbr\u003e\n\n```python\nprint(reflector.long_value.lv_tag.pretty_value)\nprint(reflector.long_value.lv_tag.bytes_value)\n```\n\nYou can also set values \u003cbr\u003e\n**bytes_value** - accepts only bytearray \u003cbr\u003e\n**pretty_value** - accepts a similar Python type \u003cbr\u003e\n**without parameters** - takes another object from the mapper \u003cbr\u003e\n\n```python\nreflector.ob_base.ob_refcnt.bytes_value = bytearray(1)\nreflector.ob_base.ob_refcnt.pretty_value = 1000\nreflector.ob_base.ob_refcnt = binder.bind(7).ob_base.ob_refcnt\n```\n\nThere is also work with pointers and arrays as in C\n\n```python\nx = [1, 2, 3]\nprint(binder.bind(x).ob_item[j][1])\nprint(+(binder.bind(x).ob_item[j]))\nprint(+(binder.bind(x).ob_item[j] + 1))\n```\n\nYou can convert mappers of some data types to others\n\n```python\nfrom pystrector.core_datatypes import _longobject\n\nx = [1, 2, 3]\n\nbinder.bind(x).ob_item[0][0].cast_to(_longobject) # need to cast because list saves PyObjects\n```\n\nOr use auto cast (works only with PyObject)\n\n```python\nx = [1, 2, 3]\n\nbinder.bind(x).ob_item[0][0].cast()\n```\n\n\nMore examples can be seen in [tests](./tests)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbontail%2Fpystrector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbontail%2Fpystrector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbontail%2Fpystrector/lists"}