excel-serializer


Nameexcel-serializer JSON
Version 1.1.4 PyPI version JSON
download
home_pageNone
SummaryDump/Load Excel files to/from Python objects
upload_time2025-07-08 10:38:05
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT License Copyright (c) 2025 Alexandre Manuel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords excel xlsx serializer deserializer dump load
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Excel Serializer

![Example](https://github.com/alexandre-tsu-manuel/excel-serializer/raw/main/example.png)

Excel Serializer is a Python package that provides a set of functions and classes to serialize and deserialize Python objects to and from Excel files. The API is designed to be intuitive and familiar, closely mirroring the interface of the built-in `json` module. This makes it easy to configure and use for developers who are already accustomed to working with JSON serialization.

## Key Features

- **load**: Deserialize an Excel file to a Python object.
- **loadw**: Deserialize an openpyxl workbook to a Python object.
- **dump**: Serialize a Python object to an Excel file.
- **dumpw**: Serialize a Python object to an openpyxl workbook.

## Dependencies

- **openpyxl**: This module relies on the `openpyxl` library for reading from and writing to Excel files. Ensure that `openpyxl` is installed in your environment to use this module.

## Installation

You can install the package using pip:

```sh
pip install excel-serializer
```

## Builtin types

This module has four builtin types:
- `List`: A list of values.
- `Tuple`: A tuple of values.
- `Dict`: A dictionary of key-value pairs.
- `DictList`: A list of dictionaries all having the same keys.

You can easily add your own types by subclassing `ExcelEncoder` and `ExcelDecoder` classes. See how to do so in examples
below.

## Usage

### Encoding basic Python object hierarchies

```python
import excel_serializer as es

data = {'name': 'John', 'age': 30, 'city': 'New York'}
es.dump(data, 'data.xlsx')
```

### Decoding Excel files

```python
import excel_serializer as es

data = es.load('data.xlsx')
print(data)
# Output: {'name': 'John', 'age': 30, 'city': 'New York'}
```

### Using a custom encoder

You can either convert the custom object to a built-in type:
```python
import excel_serializer as es

class CustomEncoder(es.ExcelEncoder):
    def default(self, obj):
        if isinstance(obj, set):
            return list(obj)
        return super()._default(obj)

data = {'numbers': {1, 2, 3}}
es.dump(data, 'data.xlsx', cls=CustomEncoder)
```

or implement a custom encoder to handle the serialization of the custom object:
```python
import excel_serializer as es

class CustomEncoder(es.ExcelEncoder):
    def write_set(self, sheet, type_cell, st):
        cols = ('Value',)
        type_cell.value = f'Set {type_cell.value}'
        sheet.append((type_cell,))
        sheet.append(cols)
        for i, e in enumerate(st):
            sheet.append((i + 1, self.encode(sheet, i + 3, 2, str(i + 1), e)))
        return 2 + len(st), 1, cols
    
    def write_custom_type(self, sheet, type_cell, obj):
        if isinstance(obj, set):
            return self.write_set(sheet, type_cell, obj)
        return super().write_custom_type(sheet, type_cell, obj)

data = {'numbers': {1, 2, 3}}
es.dump(data, 'data.xlsx', cls=CustomEncoder)
```

### Using a custom decoder

```python
import excel_serializer as es

class CustomDecoder(es.ExcelDecoder):
    def read_set(self, sheet_name, rows):
        headers = next(rows)
        if len(headers) != 1:
            raise es.ExcelDecodeError(f'Invalid list headers. Expected 1, found {len(headers)}',
                                   self.workbook, sheet_name, 2, len(headers) + 1)
        if headers[0].value != 'Value':
            raise es.ExcelDecodeError(f'Invalid list headers. Expected "Value", found "{headers[0].value}"',
                                      self.workbook, sheet_name, 2, 1)
        return set(self.read_value(row[0]) for row in rows)
    
    def read_custom_type(self, sheet_type, sheet_name, rows):
        if sheet_type == 'Set':
            return self.read_set(sheet_name, rows)
        return super().read_custom_type(sheet_type, sheet_name, rows)

data = es.load('data.xlsx', cls=CustomDecoder)
print(data)
# Output: {'numbers': {1, 2, 3}}
```

## License

This project is licensed under the MIT License. See the `LICENSE` file for details.

## Author

Alexandre 'Tsu' Manuel - [tsu@sulvia.fr](mailto:tsu@sulvia.fr)

## Links

- [Homepage](https://github.com/alexandre-tsu-manuel/excel-serializer)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "excel-serializer",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "excel, xlsx, serializer, deserializer, dump, load",
    "author": null,
    "author_email": "Alexandre 'Tsu' Manuel <tsu@sulvia.fr>",
    "download_url": "https://files.pythonhosted.org/packages/42/aa/0f8ed6c9c9a92c5361e99652b8e587b2883e51639eb3a15420c80984ae0d/excel_serializer-1.1.4.tar.gz",
    "platform": null,
    "description": "# Excel Serializer\n\n![Example](https://github.com/alexandre-tsu-manuel/excel-serializer/raw/main/example.png)\n\nExcel Serializer is a Python package that provides a set of functions and classes to serialize and deserialize Python objects to and from Excel files. The API is designed to be intuitive and familiar, closely mirroring the interface of the built-in `json` module. This makes it easy to configure and use for developers who are already accustomed to working with JSON serialization.\n\n## Key Features\n\n- **load**: Deserialize an Excel file to a Python object.\n- **loadw**: Deserialize an openpyxl workbook to a Python object.\n- **dump**: Serialize a Python object to an Excel file.\n- **dumpw**: Serialize a Python object to an openpyxl workbook.\n\n## Dependencies\n\n- **openpyxl**: This module relies on the `openpyxl` library for reading from and writing to Excel files. Ensure that `openpyxl` is installed in your environment to use this module.\n\n## Installation\n\nYou can install the package using pip:\n\n```sh\npip install excel-serializer\n```\n\n## Builtin types\n\nThis module has four builtin types:\n- `List`: A list of values.\n- `Tuple`: A tuple of values.\n- `Dict`: A dictionary of key-value pairs.\n- `DictList`: A list of dictionaries all having the same keys.\n\nYou can easily add your own types by subclassing `ExcelEncoder` and `ExcelDecoder` classes. See how to do so in examples\nbelow.\n\n## Usage\n\n### Encoding basic Python object hierarchies\n\n```python\nimport excel_serializer as es\n\ndata = {'name': 'John', 'age': 30, 'city': 'New York'}\nes.dump(data, 'data.xlsx')\n```\n\n### Decoding Excel files\n\n```python\nimport excel_serializer as es\n\ndata = es.load('data.xlsx')\nprint(data)\n# Output: {'name': 'John', 'age': 30, 'city': 'New York'}\n```\n\n### Using a custom encoder\n\nYou can either convert the custom object to a built-in type:\n```python\nimport excel_serializer as es\n\nclass CustomEncoder(es.ExcelEncoder):\n    def default(self, obj):\n        if isinstance(obj, set):\n            return list(obj)\n        return super()._default(obj)\n\ndata = {'numbers': {1, 2, 3}}\nes.dump(data, 'data.xlsx', cls=CustomEncoder)\n```\n\nor implement a custom encoder to handle the serialization of the custom object:\n```python\nimport excel_serializer as es\n\nclass CustomEncoder(es.ExcelEncoder):\n    def write_set(self, sheet, type_cell, st):\n        cols = ('Value',)\n        type_cell.value = f'Set {type_cell.value}'\n        sheet.append((type_cell,))\n        sheet.append(cols)\n        for i, e in enumerate(st):\n            sheet.append((i + 1, self.encode(sheet, i + 3, 2, str(i + 1), e)))\n        return 2 + len(st), 1, cols\n    \n    def write_custom_type(self, sheet, type_cell, obj):\n        if isinstance(obj, set):\n            return self.write_set(sheet, type_cell, obj)\n        return super().write_custom_type(sheet, type_cell, obj)\n\ndata = {'numbers': {1, 2, 3}}\nes.dump(data, 'data.xlsx', cls=CustomEncoder)\n```\n\n### Using a custom decoder\n\n```python\nimport excel_serializer as es\n\nclass CustomDecoder(es.ExcelDecoder):\n    def read_set(self, sheet_name, rows):\n        headers = next(rows)\n        if len(headers) != 1:\n            raise es.ExcelDecodeError(f'Invalid list headers. Expected 1, found {len(headers)}',\n                                   self.workbook, sheet_name, 2, len(headers) + 1)\n        if headers[0].value != 'Value':\n            raise es.ExcelDecodeError(f'Invalid list headers. Expected \"Value\", found \"{headers[0].value}\"',\n                                      self.workbook, sheet_name, 2, 1)\n        return set(self.read_value(row[0]) for row in rows)\n    \n    def read_custom_type(self, sheet_type, sheet_name, rows):\n        if sheet_type == 'Set':\n            return self.read_set(sheet_name, rows)\n        return super().read_custom_type(sheet_type, sheet_name, rows)\n\ndata = es.load('data.xlsx', cls=CustomDecoder)\nprint(data)\n# Output: {'numbers': {1, 2, 3}}\n```\n\n## License\n\nThis project is licensed under the MIT License. See the `LICENSE` file for details.\n\n## Author\n\nAlexandre 'Tsu' Manuel - [tsu@sulvia.fr](mailto:tsu@sulvia.fr)\n\n## Links\n\n- [Homepage](https://github.com/alexandre-tsu-manuel/excel-serializer)\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2025 Alexandre Manuel\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.\n        ",
    "summary": "Dump/Load Excel files to/from Python objects",
    "version": "1.1.4",
    "project_urls": {
        "Homepage": "https://github.com/alexandre-tsu-manuel/excel-serializer"
    },
    "split_keywords": [
        "excel",
        " xlsx",
        " serializer",
        " deserializer",
        " dump",
        " load"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3659c3e82a574390110874710301200374bfa2116e193f2701d8c71f55f29eec",
                "md5": "d20d42778bd076efe0fb7eda8937a57d",
                "sha256": "ba03fe5c683b768a73a54237dafc93e802bd228a52058737af0d748c59d085e1"
            },
            "downloads": -1,
            "filename": "excel_serializer-1.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d20d42778bd076efe0fb7eda8937a57d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 13765,
            "upload_time": "2025-07-08T10:38:03",
            "upload_time_iso_8601": "2025-07-08T10:38:03.880963Z",
            "url": "https://files.pythonhosted.org/packages/36/59/c3e82a574390110874710301200374bfa2116e193f2701d8c71f55f29eec/excel_serializer-1.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "42aa0f8ed6c9c9a92c5361e99652b8e587b2883e51639eb3a15420c80984ae0d",
                "md5": "a3024afb12d228e9dd297850551ff415",
                "sha256": "668d78c236e633f784d637751aaf513f93b57330587135809b6dddb13d9167e9"
            },
            "downloads": -1,
            "filename": "excel_serializer-1.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "a3024afb12d228e9dd297850551ff415",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 12507,
            "upload_time": "2025-07-08T10:38:05",
            "upload_time_iso_8601": "2025-07-08T10:38:05.167960Z",
            "url": "https://files.pythonhosted.org/packages/42/aa/0f8ed6c9c9a92c5361e99652b8e587b2883e51639eb3a15420c80984ae0d/excel_serializer-1.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-08 10:38:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alexandre-tsu-manuel",
    "github_project": "excel-serializer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "excel-serializer"
}
        
Elapsed time: 0.47296s