fast-serializer


Namefast-serializer JSON
Version 0.8.4 PyPI version JSON
download
home_pagehttps://github.com/breezechime/fast-serializer
Summarypython 数据类验证器和序列化框架
upload_time2024-07-14 14:18:31
maintainerNone
docs_urlNone
author且听风铃、我是指针*、ZDLAY、KYZ
requires_python>=3.6
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastSerializer - 快速序列化器

用于将 Python 数据类对象序列化为 JSON 数据格式,也可以将JSON字典/字符串反序列化为 Python数据类对象。
原则上来说FastSerializer可以序列化任意对象。

# 注意:当前快速序列化器还未完成,请等此消息没有后再使用,但是可以进行测试。

## ✨ 特点

* **🚀快速**:在Python提供非常高的性能因为它使用了dataclass,并且FastSerializer非常轻量,不占用太多空间。
* **💎优雅**:精心设计,FastSerializer的设计模式可以让你减少冗余的代码。
* **📦简单**:你可以定义合适的数据类结构,其它都交给FastSerializer和自定义的装饰器重写。
* **💪强大**:支持任意复杂的对象(具有深度继承层次结构和泛型类型的)。
* **👍兼容**:FastSerializer原始就支持很多其它的数据类库,比如:Pydantic、Dataclass、SqlalchemyOrm、自定义等。


## 📦 安装
```shell
$ pip install fast-serializer
```

## 💡 一个简单的例子

```python
from typing import List
from fast_serializer import FastDataclass, field

class Address(FastDataclass):
    """地址"""
    detail_address: str
    
    
class User(FastDataclass):
    """用户"""
    nickname: str = field(required=True)
    age: int = None
    address_list: List[Address]


# 数据
data = {'nickname': 'Lao Da', 'address_list': [{'detail_address': 'China'}]}

# JSON字典到Python对象反序列化的用法
user = User(**data)
print(user)  # 提供了Repr

print(user.nickname)
#> 'Lao Da'
```


### 👩‍💻 目录结构

```shell
fast_serializer
│  .gitignore  git忽略文件
│  example.py 实例文件
│  README.md 阅读文件
└─fast_serializer 主包
    │  constants.py 常量定义
    │  dataclass_config.py 数据类的配置
    │  decorators.py 装饰器
    │  exceptions.py 异常
    │  fast_dataclass.py 快速数据类
    │  field.py 字段
    │  getter.py Getter样板生成(待开发Pycharm插件后支持)
    │  json_schema.py 
    │  serializer.py 序列化器
    │  utils.py 工具包
    │  validator.py 验证器
    │  __init__.py
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/breezechime/fast-serializer",
    "name": "fast-serializer",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "\u4e14\u542c\u98ce\u94c3\u3001\u6211\u662f\u6307\u9488*\u3001ZDLAY\u3001KYZ",
    "author_email": "breezechime@163.com",
    "download_url": "https://files.pythonhosted.org/packages/17/b0/51a14560901c35c26efefa580bba4cfaf410437afbbc4cadc386c764aab3/fast_serializer-0.8.4.tar.gz",
    "platform": null,
    "description": "# FastSerializer - \u5feb\u901f\u5e8f\u5217\u5316\u5668\n\n\u7528\u4e8e\u5c06 Python \u6570\u636e\u7c7b\u5bf9\u8c61\u5e8f\u5217\u5316\u4e3a JSON \u6570\u636e\u683c\u5f0f\uff0c\u4e5f\u53ef\u4ee5\u5c06JSON\u5b57\u5178/\u5b57\u7b26\u4e32\u53cd\u5e8f\u5217\u5316\u4e3a Python\u6570\u636e\u7c7b\u5bf9\u8c61\u3002\n\u539f\u5219\u4e0a\u6765\u8bf4FastSerializer\u53ef\u4ee5\u5e8f\u5217\u5316\u4efb\u610f\u5bf9\u8c61\u3002\n\n# \u6ce8\u610f\uff1a\u5f53\u524d\u5feb\u901f\u5e8f\u5217\u5316\u5668\u8fd8\u672a\u5b8c\u6210\uff0c\u8bf7\u7b49\u6b64\u6d88\u606f\u6ca1\u6709\u540e\u518d\u4f7f\u7528\uff0c\u4f46\u662f\u53ef\u4ee5\u8fdb\u884c\u6d4b\u8bd5\u3002\n\n## \u2728 \u7279\u70b9\n\n* **\ud83d\ude80\u5feb\u901f**\uff1a\u5728Python\u63d0\u4f9b\u975e\u5e38\u9ad8\u7684\u6027\u80fd\u56e0\u4e3a\u5b83\u4f7f\u7528\u4e86dataclass\uff0c\u5e76\u4e14FastSerializer\u975e\u5e38\u8f7b\u91cf\uff0c\u4e0d\u5360\u7528\u592a\u591a\u7a7a\u95f4\u3002\n* **\ud83d\udc8e\u4f18\u96c5**\uff1a\u7cbe\u5fc3\u8bbe\u8ba1\uff0cFastSerializer\u7684\u8bbe\u8ba1\u6a21\u5f0f\u53ef\u4ee5\u8ba9\u4f60\u51cf\u5c11\u5197\u4f59\u7684\u4ee3\u7801\u3002\n* **\ud83d\udce6\u7b80\u5355**\uff1a\u4f60\u53ef\u4ee5\u5b9a\u4e49\u5408\u9002\u7684\u6570\u636e\u7c7b\u7ed3\u6784\uff0c\u5176\u5b83\u90fd\u4ea4\u7ed9FastSerializer\u548c\u81ea\u5b9a\u4e49\u7684\u88c5\u9970\u5668\u91cd\u5199\u3002\n* **\ud83d\udcaa\u5f3a\u5927**\uff1a\u652f\u6301\u4efb\u610f\u590d\u6742\u7684\u5bf9\u8c61\uff08\u5177\u6709\u6df1\u5ea6\u7ee7\u627f\u5c42\u6b21\u7ed3\u6784\u548c\u6cdb\u578b\u7c7b\u578b\u7684\uff09\u3002\n* **\ud83d\udc4d\u517c\u5bb9**\uff1aFastSerializer\u539f\u59cb\u5c31\u652f\u6301\u5f88\u591a\u5176\u5b83\u7684\u6570\u636e\u7c7b\u5e93\uff0c\u6bd4\u5982\uff1aPydantic\u3001Dataclass\u3001SqlalchemyOrm\u3001\u81ea\u5b9a\u4e49\u7b49\u3002\n\n\n## \ud83d\udce6 \u5b89\u88c5\n```shell\n$ pip install fast-serializer\n```\n\n## \ud83d\udca1 \u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\n\n```python\nfrom typing import List\nfrom fast_serializer import FastDataclass, field\n\nclass Address(FastDataclass):\n    \"\"\"\u5730\u5740\"\"\"\n    detail_address: str\n    \n    \nclass User(FastDataclass):\n    \"\"\"\u7528\u6237\"\"\"\n    nickname: str = field(required=True)\n    age: int = None\n    address_list: List[Address]\n\n\n# \u6570\u636e\ndata = {'nickname': 'Lao Da', 'address_list': [{'detail_address': 'China'}]}\n\n# JSON\u5b57\u5178\u5230Python\u5bf9\u8c61\u53cd\u5e8f\u5217\u5316\u7684\u7528\u6cd5\nuser = User(**data)\nprint(user)  # \u63d0\u4f9b\u4e86Repr\n\nprint(user.nickname)\n#> 'Lao Da'\n```\n\n\n### \ud83d\udc69\u200d\ud83d\udcbb \u76ee\u5f55\u7ed3\u6784\n\n```shell\nfast_serializer\n\u2502  .gitignore  git\u5ffd\u7565\u6587\u4ef6\n\u2502  example.py \u5b9e\u4f8b\u6587\u4ef6\n\u2502  README.md \u9605\u8bfb\u6587\u4ef6\n\u2514\u2500fast_serializer \u4e3b\u5305\n    \u2502  constants.py \u5e38\u91cf\u5b9a\u4e49\n    \u2502  dataclass_config.py \u6570\u636e\u7c7b\u7684\u914d\u7f6e\n    \u2502  decorators.py \u88c5\u9970\u5668\n    \u2502  exceptions.py \u5f02\u5e38\n    \u2502  fast_dataclass.py \u5feb\u901f\u6570\u636e\u7c7b\n    \u2502  field.py \u5b57\u6bb5\n    \u2502  getter.py Getter\u6837\u677f\u751f\u6210\uff08\u5f85\u5f00\u53d1Pycharm\u63d2\u4ef6\u540e\u652f\u6301\uff09\n    \u2502  json_schema.py \n    \u2502  serializer.py \u5e8f\u5217\u5316\u5668\n    \u2502  utils.py \u5de5\u5177\u5305\n    \u2502  validator.py \u9a8c\u8bc1\u5668\n    \u2502  __init__.py\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "python \u6570\u636e\u7c7b\u9a8c\u8bc1\u5668\u548c\u5e8f\u5217\u5316\u6846\u67b6",
    "version": "0.8.4",
    "project_urls": {
        "Homepage": "https://github.com/breezechime/fast-serializer"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b98b898265cb3a88c43db3bd70414e5886b8c4bc0e8e77584ccd22c4249f19fc",
                "md5": "6c3b8d55dff9869b41705fb02d7476ab",
                "sha256": "efbdbb2b35d730820bb472fa747d2e21df4a165cf7c708ecaa69c9453ef95056"
            },
            "downloads": -1,
            "filename": "fast_serializer-0.8.4-cp311-cp311-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "6c3b8d55dff9869b41705fb02d7476ab",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.6",
            "size": 952787,
            "upload_time": "2024-07-14T14:18:25",
            "upload_time_iso_8601": "2024-07-14T14:18:25.459707Z",
            "url": "https://files.pythonhosted.org/packages/b9/8b/898265cb3a88c43db3bd70414e5886b8c4bc0e8e77584ccd22c4249f19fc/fast_serializer-0.8.4-cp311-cp311-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "17b051a14560901c35c26efefa580bba4cfaf410437afbbc4cadc386c764aab3",
                "md5": "435737cfca247d802195cf718f892ec1",
                "sha256": "9c3e9284b727b7a29472ade67e8130211e9d4abd1cdf70666d122b0acb29e43a"
            },
            "downloads": -1,
            "filename": "fast_serializer-0.8.4.tar.gz",
            "has_sig": false,
            "md5_digest": "435737cfca247d802195cf718f892ec1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 1387410,
            "upload_time": "2024-07-14T14:18:31",
            "upload_time_iso_8601": "2024-07-14T14:18:31.786698Z",
            "url": "https://files.pythonhosted.org/packages/17/b0/51a14560901c35c26efefa580bba4cfaf410437afbbc4cadc386c764aab3/fast_serializer-0.8.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-14 14:18:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "breezechime",
    "github_project": "fast-serializer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "fast-serializer"
}
        
Elapsed time: 0.59821s