data-serialize


Namedata-serialize JSON
Version 0.2.2 PyPI version JSON
download
home_pagehttps://github.com/ssbuild/fastdatasets
Summarydata serialize
upload_time2023-07-31 05:12:31
maintainer
docs_urlNone
authorssbuild
requires_python
licenseMIT
keywords data_serialize serialize deserialize
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # data_serialize

This library allows reading and writing binary to string 

## Installation

```pip3 install data_serialize```


## serialize and deserialize

```python
#
import data_serialize
import numpy as np


def test_feature():
    val1 = data_serialize.Int64List(value=[1, 2, 3] * 20)
    val2 = data_serialize.FloatList(value=[1, 2, 3] * 20)
    val3 = data_serialize.BytesList(value=[b'The china', b'boy'])

    featrue = data_serialize.Features(feature=
    {
        "item_0": data_serialize.Feature(int64_list=val1),
        "item_1": data_serialize.Feature(float_list=val2),
        "item_2": data_serialize.Feature(bytes_list=val3)
    }
    )

    example = data_serialize.Example(features=featrue)

    # 序列化
    serialize = example.SerializeToString()
    print(serialize)

    # 反序列化
    example = data_serialize.Example()
    example.ParseFromString(serialize)
    print(example)


def test_numpyobject():
    a = np.random.randint(0, 21128, size=(10,), dtype=np.int64)
    b = np.random.rand(3, 4)
    c = np.asarray(b'The china')

    val1 = data_serialize.NumpyObject(
        header='',
        dtype=str(a.dtype),
        shape=list(a.shape),
        int64=a.reshape((-1,)).tolist(),
    )
    val2 = data_serialize.NumpyObject(
        header='',
        dtype=str(b.dtype),
        shape=list(b.shape),
        float64=b.reshape((-1,)).tolist(),
    )
    val3 = data_serialize.NumpyObject(
        header='',
        dtype=str(c.dtype),
        shape=list(c.shape),
        bytes=c.tobytes(),
    )

    example = data_serialize.NumpyObjectMap(numpyobjects={
        "item_0": val1,
        "item_1": val2,
        "item_2": val3}
    )
    # 序列化
    serialize = example.SerializeToString()
    print(serialize)

    # 反序列化
    example = data_serialize.NumpyObjectMap()
    example.ParseFromString(serialize)
    print(example)


test_feature()

test_numpyobject()


```




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ssbuild/fastdatasets",
    "name": "data-serialize",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "data_serialize,serialize,deserialize",
    "author": "ssbuild",
    "author_email": "9727464@qq.com",
    "download_url": "",
    "platform": null,
    "description": "# data_serialize\n\nThis library allows reading and writing binary to string \n\n## Installation\n\n```pip3 install data_serialize```\n\n\n## serialize and deserialize\n\n```python\n#\nimport data_serialize\nimport numpy as np\n\n\ndef test_feature():\n    val1 = data_serialize.Int64List(value=[1, 2, 3] * 20)\n    val2 = data_serialize.FloatList(value=[1, 2, 3] * 20)\n    val3 = data_serialize.BytesList(value=[b'The china', b'boy'])\n\n    featrue = data_serialize.Features(feature=\n    {\n        \"item_0\": data_serialize.Feature(int64_list=val1),\n        \"item_1\": data_serialize.Feature(float_list=val2),\n        \"item_2\": data_serialize.Feature(bytes_list=val3)\n    }\n    )\n\n    example = data_serialize.Example(features=featrue)\n\n    # \u5e8f\u5217\u5316\n    serialize = example.SerializeToString()\n    print(serialize)\n\n    # \u53cd\u5e8f\u5217\u5316\n    example = data_serialize.Example()\n    example.ParseFromString(serialize)\n    print(example)\n\n\ndef test_numpyobject():\n    a = np.random.randint(0, 21128, size=(10,), dtype=np.int64)\n    b = np.random.rand(3, 4)\n    c = np.asarray(b'The china')\n\n    val1 = data_serialize.NumpyObject(\n        header='',\n        dtype=str(a.dtype),\n        shape=list(a.shape),\n        int64=a.reshape((-1,)).tolist(),\n    )\n    val2 = data_serialize.NumpyObject(\n        header='',\n        dtype=str(b.dtype),\n        shape=list(b.shape),\n        float64=b.reshape((-1,)).tolist(),\n    )\n    val3 = data_serialize.NumpyObject(\n        header='',\n        dtype=str(c.dtype),\n        shape=list(c.shape),\n        bytes=c.tobytes(),\n    )\n\n    example = data_serialize.NumpyObjectMap(numpyobjects={\n        \"item_0\": val1,\n        \"item_1\": val2,\n        \"item_2\": val3}\n    )\n    # \u5e8f\u5217\u5316\n    serialize = example.SerializeToString()\n    print(serialize)\n\n    # \u53cd\u5e8f\u5217\u5316\n    example = data_serialize.NumpyObjectMap()\n    example.ParseFromString(serialize)\n    print(example)\n\n\ntest_feature()\n\ntest_numpyobject()\n\n\n```\n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "data serialize",
    "version": "0.2.2",
    "project_urls": {
        "Homepage": "https://github.com/ssbuild/fastdatasets"
    },
    "split_keywords": [
        "data_serialize",
        "serialize",
        "deserialize"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d049cc5477783f464563093fab28f73e647b1a78d5b5bc472fc7b69a1cf2f991",
                "md5": "ae6fe99ab53bc6cafeec13ceb68abbe8",
                "sha256": "92483125fb996d656441e1c33a80b13979d984b4c9749d2a3465f2ec13262a06"
            },
            "downloads": -1,
            "filename": "data_serialize-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ae6fe99ab53bc6cafeec13ceb68abbe8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 12518,
            "upload_time": "2023-07-31T05:12:31",
            "upload_time_iso_8601": "2023-07-31T05:12:31.604405Z",
            "url": "https://files.pythonhosted.org/packages/d0/49/cc5477783f464563093fab28f73e647b1a78d5b5bc472fc7b69a1cf2f991/data_serialize-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-31 05:12:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ssbuild",
    "github_project": "fastdatasets",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "data-serialize"
}
        
Elapsed time: 0.13282s