b3buf


Nameb3buf JSON
Version 1.0.8 PyPI version JSON
download
home_pagehttps://github.com/oddy/b3
SummaryB3 is a binary serializer which is easy like json, compact like msgpack, powerful like protobuf, and handles datetimes in python
upload_time2022-09-23 00:12:15
maintainer
docs_urlNone
authorBeau Butler
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            

# B3 = Better Binary Buffers

B3 is a data serializer, it packs data structures to bytes & vice versa. It has:
* The schema power of protobuf, without the setup/compiler pain,
* The quick-start ease of json.dumps, but with support for datetimes,
* The compactness of msgpack, but without a large zoo of data types. 

With B3 you can fast-start with schema-less data (like json), and move to schemas (like protobuf) later & stay compatible. Or have ad-hoc json-like clients talk to rigorous protobuf-like servers without pain & suffering.

The small number of lovingly-handcrafted data types means often the only choice you need make is between Fast or Compact.

This version is pure python, no dependencies apart from Six (and pytest for the tests).
Tested working in python 3.8 & 2.7 on windows & linux.

## Version

B3 is now version 1.x, it is out of beta.

__The wire format and existing core data types are now *frozen* and *will not change*.__

* Except for the unused core types 10,11,12 which may have a type assigned in future, and
* Except for SCHEDs unfinished named-timezone support, which needs py3.10+)

(v1.x is not backward compatible with beta 0.9.x versions) 

## Installing

```
pip install b3buf

>>> import b3
```

### Getting Started

You can pack lists of things (like json.dumps):

```
import b3
list_data = [ None,  b"foo",  u"bar",  True,  -69,  2.318,  46j,  [1,2,3],  {4:5, 6:7},
              decimal.Decimal("13.37"), datetime.datetime.now() ]

list_buf = b3.pack(list_data)

out_list = b3.unpack(list_buf)
```
Complex numbers, decimal numbers, and dates and times all work.

You can pack dicts of things:

```
dict_data = { 1:1, u"2":u"2", b"3":b"3" }

dict_buf = b3.pack(dict_data)

out_dict = b3.unpack(dict_buf, 0)
```
Byte keys are supported as well as string and number keys

You can save on slicing when unpacking by giving unpack a start index


### Schema Packing
You can make messages using a "type, name, tag_number" schema (like protobuf)

```
SCHEMA = (
    (b3.B3_BYTES,   "bytes1",  1),
    (b3.B3_UVARINT, "number1", 2),
    )
```

Schema packing/unpacking is to and from python Dicts.
```
sch_data = dict(bytes1=b"foo", number1=69)

sch_buf = b3.schema_pack(SCHEMA, sch_data)

out_sch = b3.schema_unpack(SCHEMA, sch_buf)
```


## Tests

B3 ships with an extensive test suite, using pytest. 

```
pip install pytest
cd /your/site-packages/b3
pytest 
```

## More Info

See the tests, and examples.py in the tests folder for more examples (including how to nest schemas)

See datatypes.py for the available data types.

See wire_format.md for an overview of the wire format.


## Licensing

The code in this project is licensed under MIT license. See LICENSE.txt.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/oddy/b3",
    "name": "b3buf",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Beau Butler",
    "author_email": "beau.butler@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b1/98/f91ba8b4333c32536995495536399a14ce9e0068fc4dac5b94e93b142f42/b3buf-1.0.8.tar.gz",
    "platform": null,
    "description": "\ufeff\n\n# B3 = Better Binary Buffers\n\nB3 is a data serializer, it packs data structures to bytes & vice versa. It has:\n* The schema power of protobuf, without the setup/compiler pain,\n* The quick-start ease of json.dumps, but with support for datetimes,\n* The compactness of msgpack, but without a large zoo of data types. \n\nWith B3 you can fast-start with schema-less data (like json), and move to schemas (like protobuf) later & stay compatible. Or have ad-hoc json-like clients talk to rigorous protobuf-like servers without pain & suffering.\n\nThe small number of lovingly-handcrafted data types means often the only choice you need make is between Fast or Compact.\n\nThis version is pure python, no dependencies apart from Six (and pytest for the tests).\nTested working in python 3.8 & 2.7 on windows & linux.\n\n## Version\n\nB3 is now version 1.x, it is out of beta.\n\n__The wire format and existing core data types are now *frozen* and *will not change*.__\n\n* Except for the unused core types 10,11,12 which may have a type assigned in future, and\n* Except for SCHEDs unfinished named-timezone support, which needs py3.10+)\n\n(v1.x is not backward compatible with beta 0.9.x versions) \n\n## Installing\n\n```\npip install b3buf\n\n>>> import b3\n```\n\n### Getting Started\n\nYou can pack lists of things (like json.dumps):\n\n```\nimport b3\nlist_data = [ None,  b\"foo\",  u\"bar\",  True,  -69,  2.318,  46j,  [1,2,3],  {4:5, 6:7},\n              decimal.Decimal(\"13.37\"), datetime.datetime.now() ]\n\nlist_buf = b3.pack(list_data)\n\nout_list = b3.unpack(list_buf)\n```\nComplex numbers, decimal numbers, and dates and times all work.\n\nYou can pack dicts of things:\n\n```\ndict_data = { 1:1, u\"2\":u\"2\", b\"3\":b\"3\" }\n\ndict_buf = b3.pack(dict_data)\n\nout_dict = b3.unpack(dict_buf, 0)\n```\nByte keys are supported as well as string and number keys\n\nYou can save on slicing when unpacking by giving unpack a start index\n\n\n### Schema Packing\nYou can make messages using a \"type, name, tag_number\" schema (like protobuf)\n\n```\nSCHEMA = (\n    (b3.B3_BYTES,   \"bytes1\",  1),\n    (b3.B3_UVARINT, \"number1\", 2),\n    )\n```\n\nSchema packing/unpacking is to and from python Dicts.\n```\nsch_data = dict(bytes1=b\"foo\", number1=69)\n\nsch_buf = b3.schema_pack(SCHEMA, sch_data)\n\nout_sch = b3.schema_unpack(SCHEMA, sch_buf)\n```\n\n\n## Tests\n\nB3 ships with an extensive test suite, using pytest. \n\n```\npip install pytest\ncd /your/site-packages/b3\npytest \n```\n\n## More Info\n\nSee the tests, and examples.py in the tests folder for more examples (including how to nest schemas)\n\nSee datatypes.py for the available data types.\n\nSee wire_format.md for an overview of the wire format.\n\n\n## Licensing\n\nThe code in this project is licensed under MIT license. See LICENSE.txt.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "B3 is a binary serializer which is easy like json, compact like msgpack, powerful like protobuf, and handles datetimes in python",
    "version": "1.0.8",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "b36f1131437cfbc17b180b5032738079",
                "sha256": "a30aba9beb4719474c4d5a222932586943e8ca76b5b89a62f53488ed55e2d0f9"
            },
            "downloads": -1,
            "filename": "b3buf-1.0.8-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b36f1131437cfbc17b180b5032738079",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 44204,
            "upload_time": "2022-09-23T00:12:14",
            "upload_time_iso_8601": "2022-09-23T00:12:14.079731Z",
            "url": "https://files.pythonhosted.org/packages/ef/bf/6e4bd5b63bd730593cad056b024ce9f9af3470e2fa3251a3cb10f9b30506/b3buf-1.0.8-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "c6a3ed2f9ef5ee7a75a345ea4ba7c7a2",
                "sha256": "d5b88328e1791772b12f3c8d7f68028d92a1cdab2583e85ea337e0ebf99fc1df"
            },
            "downloads": -1,
            "filename": "b3buf-1.0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "c6a3ed2f9ef5ee7a75a345ea4ba7c7a2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 39170,
            "upload_time": "2022-09-23T00:12:15",
            "upload_time_iso_8601": "2022-09-23T00:12:15.499458Z",
            "url": "https://files.pythonhosted.org/packages/b1/98/f91ba8b4333c32536995495536399a14ce9e0068fc4dac5b94e93b142f42/b3buf-1.0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-09-23 00:12:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "oddy",
    "github_project": "b3",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "b3buf"
}
        
Elapsed time: 0.43772s