semimutable


Namesemimutable JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryDrop-in replacement for Python's built-in `dataclasses` module, allowing for certain fields to be mutable while others remain immutable.
upload_time2025-08-07 13:35:54
maintainerNone
docs_urlNone
authorGlinte
requires_python>=3.12
licenseNone
keywords dataclasses
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Semimutable

[![Tests](https://github.com/Glinte/semimutable/actions/workflows/ci.yml/badge.svg)](https://github.com/Glinte/semimutable/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/Glinte/semimutable/branch/main/graph/badge.svg)](https://codecov.io/gh/Glinte/semimutable)

A dataclass drop-in that allows you to define individual fields as immutable.

## Usage

Simply replace all your `dataclasses` imports with `semimutable`, and use `field(frozen=True)` for the fields you want to be immutable.

`field` takes in the same parameters as `dataclasses.field`, with an extra `frozen` boolean flag that defaults to `False`. You can specify default values, default factories, and other options just like you would with a regular dataclass field.

Here is one example from our tests.

```python
from semimutable import dataclass, field

@dataclass
class Simple:
    x: int = field(frozen=True)
    y: int = 0 # normal, mutable field

def test_frozen_field_is_immutable():
    obj = Simple(x=1, y=2)
    with pytest.raises(TypeError):
        obj.x = 99

def test_non_frozen_field_is_mutable():
    obj = Simple(x=1, y=2)
    obj.y = 42
    assert obj.y == 42
```

## Credits

Parts of this library are derived from Python's standard library `dataclasses` module. The original implementation is distributed under the Python Software Foundation License. See `LICENSE.PSF` for the full license text.
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "semimutable",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "dataclasses",
    "author": "Glinte",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/ab/00/7ce6af378095896fa39feeeeb22a3f5c4e5ed11051000f3803541c4a6945/semimutable-0.1.0.tar.gz",
    "platform": null,
    "description": "# Semimutable\n\n[![Tests](https://github.com/Glinte/semimutable/actions/workflows/ci.yml/badge.svg)](https://github.com/Glinte/semimutable/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/Glinte/semimutable/branch/main/graph/badge.svg)](https://codecov.io/gh/Glinte/semimutable)\n\nA dataclass drop-in that allows you to define individual fields as immutable.\n\n## Usage\n\nSimply replace all your `dataclasses` imports with `semimutable`, and use `field(frozen=True)` for the fields you want to be immutable.\n\n`field` takes in the same parameters as `dataclasses.field`, with an extra `frozen` boolean flag that defaults to `False`. You can specify default values, default factories, and other options just like you would with a regular dataclass field.\n\nHere is one example from our tests.\n\n```python\nfrom semimutable import dataclass, field\n\n@dataclass\nclass Simple:\n    x: int = field(frozen=True)\n    y: int = 0 # normal, mutable field\n\ndef test_frozen_field_is_immutable():\n    obj = Simple(x=1, y=2)\n    with pytest.raises(TypeError):\n        obj.x = 99\n\ndef test_non_frozen_field_is_mutable():\n    obj = Simple(x=1, y=2)\n    obj.y = 42\n    assert obj.y == 42\n```\n\n## Credits\n\nParts of this library are derived from Python's standard library `dataclasses` module. The original implementation is distributed under the Python Software Foundation License. See `LICENSE.PSF` for the full license text.",
    "bugtrack_url": null,
    "license": null,
    "summary": "Drop-in replacement for Python's built-in `dataclasses` module, allowing for certain fields to be mutable while others remain immutable.",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/Glinte/semimutable",
        "Issues": "https://github.com/Glinte/semimutable/issues",
        "Repository": "https://github.com/Glinte/semimutable"
    },
    "split_keywords": [
        "dataclasses"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0245abc6f3606444f362d43a37a8c6cd8ac6af9b810b96507ed3f473e3d84359",
                "md5": "61d51d226595fde1a632dc6e2c986a86",
                "sha256": "38b253ca963c74d2c1b2d5ebe2cce10a87ff621d22d842eb4b5444a418bb4c43"
            },
            "downloads": -1,
            "filename": "semimutable-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "61d51d226595fde1a632dc6e2c986a86",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 8401,
            "upload_time": "2025-08-07T13:35:52",
            "upload_time_iso_8601": "2025-08-07T13:35:52.912946Z",
            "url": "https://files.pythonhosted.org/packages/02/45/abc6f3606444f362d43a37a8c6cd8ac6af9b810b96507ed3f473e3d84359/semimutable-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ab007ce6af378095896fa39feeeeb22a3f5c4e5ed11051000f3803541c4a6945",
                "md5": "164a720bf828160b9ba2a1915f2a8a3e",
                "sha256": "37e35ac442d103c367c87e1e219ef1afcc366729319a990324363ddb718cf31c"
            },
            "downloads": -1,
            "filename": "semimutable-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "164a720bf828160b9ba2a1915f2a8a3e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 43904,
            "upload_time": "2025-08-07T13:35:54",
            "upload_time_iso_8601": "2025-08-07T13:35:54.114401Z",
            "url": "https://files.pythonhosted.org/packages/ab/00/7ce6af378095896fa39feeeeb22a3f5c4e5ed11051000f3803541c4a6945/semimutable-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-07 13:35:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Glinte",
    "github_project": "semimutable",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "semimutable"
}
        
Elapsed time: 0.50894s