Skip to main content

data_serialize

This library allows reading and writing binary to string

Installation

pip3 install data_serialize

serialize and deserialize

#
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()

Metadata

Release files for data-serialize 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for data-serialize 0.4.1
File Interpreter ABI Platform Actions
data_serialize-0.4.1-py3-none-any.whl Python 3 none any Details for data_serialize-0.4.1-py3-none-any.whl

Release files / data_serialize-0.4.1-py3-none-any.whl

Download URL data_serialize-0.4.1-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
305c3b3ee0de99436250aa9f8845cb6e1d5afd242bdaa4528e130a9d8fbcac56
BLAKE2b-256 checksum
How to use checksums
f5a4ea0efb08903f6e9215a85677f7c461a2815a53f761a0b101176005c01ae1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.2

Security for data-serialize 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page