{"id":23089538,"url":"https://github.com/janthmueller/swizzle","last_synced_at":"2025-08-16T08:31:54.725Z","repository":{"id":247288884,"uuid":"825461193","full_name":"janthmueller/swizzle","owner":"janthmueller","description":"Swizzle is a Python package that enhances attribute access, allowing for flexible retrieval of multiple attributes based on specified arrangements of their names.","archived":false,"fork":false,"pushed_at":"2024-11-03T14:58:28.000Z","size":54,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-03T16:47:38.935Z","etag":null,"topics":["attributes","clean-code","decorator","namedtuple","python","python3","swizzled","swizzling","tuple"],"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/janthmueller.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-07-07T20:51:59.000Z","updated_at":"2024-11-03T14:58:31.000Z","dependencies_parsed_at":"2024-08-01T21:33:10.180Z","dependency_job_id":"5d6bd84b-a44c-4c48-82f8-dab63aede63e","html_url":"https://github.com/janthmueller/swizzle","commit_stats":null,"previous_names":["janthmueller/swizzle"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janthmueller%2Fswizzle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janthmueller%2Fswizzle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janthmueller%2Fswizzle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janthmueller%2Fswizzle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janthmueller","download_url":"https://codeload.github.com/janthmueller/swizzle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230023947,"owners_count":18161240,"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":["attributes","clean-code","decorator","namedtuple","python","python3","swizzled","swizzling","tuple"],"created_at":"2024-12-16T20:37:53.131Z","updated_at":"2025-08-16T08:31:54.714Z","avatar_url":"https://github.com/janthmueller.png","language":"Python","readme":"# Swizzle\r\n\r\n[![PyPI Latest Release](https://img.shields.io/pypi/v/swizzle.svg)](https://pypi.org/project/swizzle/)\r\n[![Pepy Total Downloads](https://img.shields.io/pepy/dt/swizzle)](https://pepy.tech/project/swizzle)\r\n[![GitHub License](https://img.shields.io/github/license/janthmueller/swizzle)](https://github.com/janthmueller/swizzle/blob/main/LICENSE)\r\n\r\n## Overview\r\n\r\n**Swizzle** is a Python utility for flexible attribute manipulation. You can retrieve and assign multiple attributes of an object in any order or combination using simple attribute syntax.\r\n\r\nIt works with regular classes, `dataclass`, `Enum`, and other objects. The goal is to make working with objects that have multiple fields more flexible and expressive.\r\n\r\n---\r\n\r\n## Installation\r\n\r\n### From PyPI\r\n\r\n```bash\r\npip install swizzle\r\n```\r\n\r\n### From GitHub\r\n\r\n```bash\r\npip install git+https://github.com/janthmueller/swizzle.git\r\n```\r\n\r\n---\r\n\r\n## Getting Started\r\n\r\n### Basic Usage with the `@swizzle` Decorator\r\n\r\n```python\r\nimport swizzle\r\n\r\n@swizzle\r\nclass Vector:\r\n    def __init__(self, x, y, z):\r\n        self.x = x\r\n        self.y = y\r\n        self.z = z\r\n\r\nv = Vector(1, 2, 3)\r\nprint(v.yzx)  # Output: Vector(y=2, z=3, x=1)\r\n```\r\n\r\n### Swizzled Setters\r\n\r\n```python\r\n@swizzle(setter=True)\r\nclass Vector:\r\n    def __init__(self, x, y, z):\r\n        self.x = x\r\n        self.y = y\r\n        self.z = z\r\n\r\nv = Vector(1, 2, 3)\r\nv.zyx = 9, 8, 7\r\nprint(v.zyx)  # Output: Vector(z=9, y=8, x=7)\r\n```\r\n\r\n### Custom Separators\r\n\r\nFor objects with multiple fields, combining attribute names without a separator can become hard to read. You can define a separator to make expressions clearer:\r\n\r\n```python\r\nimport swizzle\r\n\r\n@swizzle(sep='_')\r\nclass Person:\r\n    def __init__(self, name, age, city, country):\r\n        self.name = name\r\n        self.age = age\r\n        self.city = city\r\n        self.country = country\r\n\r\np = Person(\"Jane\", 30, \"Berlin\", \"Germany\")\r\n\r\n# Access multiple attributes clearly using underscores\r\nprint(p.name_age_city_country)  \r\n# Output: Person(name='Jane', age=30, city='Berlin', country='Germany')\r\n```\r\n\r\nWithout a separator, `p.nameagecitycountry` is harder to read. Using `sep='_'` keeps your attribute combinations clear and expressive.\r\n\r\n### Swizzled Named Tuples\r\n\r\nInspired by `namedtuple`, `swizzledtuple` is the default output type for swizzled attributes.\r\n\r\n```python\r\nfrom swizzle import swizzledtuple\r\n\r\nVector = swizzledtuple('Vector', 'x y z')\r\nv = Vector(1, 2, 3)\r\n\r\nprint(v.yzx)        # Output: Vector(y=2, z=3, x=1)\r\nprint(v.yzx.xxzyzz) # Output: Vector(x=1, x=1, z=3, y=2, z=3, z=3)\r\n```\r\n\r\n### Using Swizzle with `dataclass`\r\n\r\n```python\r\nfrom dataclasses import dataclass\r\nimport swizzle\r\n\r\n@swizzle\r\n@dataclass\r\nclass Point:\r\n    x: int\r\n    y: int\r\n    z: int\r\n\r\np = Point(1, 2, 3)\r\nprint(p.zxy)  # Output: Point(z=3, x=1, y=2)\r\n```\r\n\r\n### Swizzling Enums with `meta=True`\r\n\r\n```python\r\nfrom enum import IntEnum\r\nimport swizzle\r\n\r\n@swizzle(meta=True)\r\nclass Axis(IntEnum):\r\n    X = 1\r\n    Y = 2\r\n    Z = 3\r\n\r\nprint(Axis.YXZ)  # Output: Axis(Y=\u003cAxis.Y: 2\u003e, X=\u003cAxis.X: 1\u003e, Z=\u003cAxis.Z: 3\u003e)\r\n```\r\n\r\n---\r\n\r\n## Documentation and Advanced Usage\r\n\r\nFor more advanced features, custom settings, and examples, see the full documentation: [Swizzle Docs](https://janthmueller.github.io/swizzle/swizzle.html)\r\n\r\n---\r\n\r\n## Feedback and Use Cases\r\n\r\nSwizzle was built to explore flexible attribute manipulation in Python. Feedback and suggestions are welcome. I would love to hear:\r\n\r\n* Interesting use cases you discover\r\n* Ideas for improvements or additional features\r\n\r\nFeel free to open an issue or PR if you try it out.\r\n\r\n---\r\n\r\n## License\r\n\r\nMIT License. See [LICENSE](https://github.com/janthmueller/swizzle/blob/main/LICENSE)\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanthmueller%2Fswizzle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanthmueller%2Fswizzle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanthmueller%2Fswizzle/lists"}