Skip to main content

A library for converting between BSON and JSON.

Project description

Info:

See github for the latest source.

Author:

Shane Harvey <shane.harvey@mongodb.com>

About

A fast BSON to MongoDB Extended JSON converter for Python.

Installation

python-bsonjs can be installed with pip:

$ python -m pip install python-bsonjs

Examples

>>> import bsonjs
>>> bson_bytes = bsonjs.loads('{"hello": "world"}')
>>> bson_bytes
'\x16\x00\x00\x00\x02hello\x00\x06\x00\x00\x00world\x00\x00'
>>> bsonjs.dumps(bson_bytes)
'{ "hello" : "world" }'

Using bsonjs with pymongo to insert a RawBSONDocument.

>>> import bsonjs
>>> from pymongo import MongoClient
>>> from bson.raw_bson import RawBSONDocument
>>> client = MongoClient("localhost", 27017, document_class=RawBSONDocument)
>>> db = client.test
>>> bson_bytes = bsonjs.loads('{"_id": 1, "x": 2}')
>>> bson_bytes
'\x15\x00\x00\x00\x10_id\x00\x01\x00\x00\x00\x10x\x00\x02\x00\x00\x00\x00'
>>> result = db.test.insert_one(RawBSONDocument(bson_bytes))
>>> result.inserted_id  # NOTE: inserted_id is None
>>> result.acknowledged
True
>>> raw_doc = db.test.find_one({'x': 2})
>>> raw_doc.raw == bson_bytes
True
>>> bsonjs.dumps(raw_doc.raw)
'{ "_id" : 1, "x" : 2 }'

Speed

bsonjs is roughly 10-15x faster than PyMongo’s json_util at decoding BSON to JSON and encoding JSON to BSON. See benchmark.py:

$ python benchmark.py
Timing: bsonjs.dumps(b)
10000 loops, best of 3: 0.110911846161
Timing: json_util.dumps(bson.BSON(b).decode())
10000 loops, best of 3: 1.46571397781
bsonjs is 13.22x faster than json_util

Timing: bsonjs.loads(j)
10000 loops, best of 3: 0.0628039836884
Timing: bson.BSON().encode(json_util.loads(j))
10000 loops, best of 3: 0.683200120926
bsonjs is 11.72x faster than json_util

Installing From Source

python-bsonjs supports CPython 2.6, 2.7, and 3.3+.

Compiler

You must build python-bsonjs separately for each version of Python. On Windows this means you must use the same C compiler your Python version was built with.

Source

Note that this repository contains a git submodule. You must initialize the submodule by using:

$ git clone --recursive https://github.com/mongodb-labs/python-bsonjs.git

Or, if your version of git does not have clone --recursive:

$ git clone https://github.com/mongodb-labs/python-bsonjs.git
$ cd python-bsonjs
$ git submodule update --init --recursive

Install

Once you have the source properly downloaded, build and install the package:

$ python setup.py install

Test

To run the test suite:

$ python setup.py test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-bsonjs-0.1.1.tar.gz (142.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

python_bsonjs-0.1.1-cp35-cp35m-win_amd64.whl (54.2 kB view details)

Uploaded CPython 3.5mWindows x86-64

python_bsonjs-0.1.1-cp35-cp35m-win32.whl (48.5 kB view details)

Uploaded CPython 3.5mWindows x86

python_bsonjs-0.1.1-cp35-cp35m-manylinux1_x86_64.whl (256.5 kB view details)

Uploaded CPython 3.5m

python_bsonjs-0.1.1-cp35-cp35m-manylinux1_i686.whl (235.0 kB view details)

Uploaded CPython 3.5m

python_bsonjs-0.1.1-cp35-cp35m-macosx_10_6_intel.whl (156.9 kB view details)

Uploaded CPython 3.5mmacOS 10.6+ Intel (x86-64, i386)

python_bsonjs-0.1.1-cp34-cp34m-win_amd64.whl (67.7 kB view details)

Uploaded CPython 3.4mWindows x86-64

python_bsonjs-0.1.1-cp34-cp34m-win32.whl (61.3 kB view details)

Uploaded CPython 3.4mWindows x86

python_bsonjs-0.1.1-cp34-cp34m-manylinux1_x86_64.whl (256.3 kB view details)

Uploaded CPython 3.4m

python_bsonjs-0.1.1-cp34-cp34m-manylinux1_i686.whl (234.8 kB view details)

Uploaded CPython 3.4m

python_bsonjs-0.1.1-cp34-cp34m-macosx_10_6_intel.whl (156.8 kB view details)

Uploaded CPython 3.4mmacOS 10.6+ Intel (x86-64, i386)

python_bsonjs-0.1.1-cp33-cp33m-win_amd64.whl (67.7 kB view details)

Uploaded CPython 3.3mWindows x86-64

python_bsonjs-0.1.1-cp33-cp33m-win32.whl (61.3 kB view details)

Uploaded CPython 3.3mWindows x86

python_bsonjs-0.1.1-cp33-cp33m-manylinux1_x86_64.whl (256.2 kB view details)

Uploaded CPython 3.3m

python_bsonjs-0.1.1-cp33-cp33m-manylinux1_i686.whl (234.8 kB view details)

Uploaded CPython 3.3m

python_bsonjs-0.1.1-cp27-cp27mu-manylinux1_x86_64.whl (255.2 kB view details)

Uploaded CPython 2.7mu

python_bsonjs-0.1.1-cp27-cp27mu-manylinux1_i686.whl (234.6 kB view details)

Uploaded CPython 2.7mu

python_bsonjs-0.1.1-cp27-cp27m-win_amd64.whl (67.4 kB view details)

Uploaded CPython 2.7mWindows x86-64

python_bsonjs-0.1.1-cp27-cp27m-win32.whl (61.0 kB view details)

Uploaded CPython 2.7mWindows x86

python_bsonjs-0.1.1-cp27-cp27m-manylinux1_x86_64.whl (255.2 kB view details)

Uploaded CPython 2.7m

python_bsonjs-0.1.1-cp27-cp27m-manylinux1_i686.whl (234.6 kB view details)

Uploaded CPython 2.7m

python_bsonjs-0.1.1-cp27-cp27m-macosx_10_11_intel.whl (143.1 kB view details)

Uploaded CPython 2.7mmacOS 10.11+ Intel (x86-64, i386)

python_bsonjs-0.1.1-cp26-cp26mu-manylinux1_x86_64.whl (255.2 kB view details)

Uploaded CPython 2.6mu

python_bsonjs-0.1.1-cp26-cp26mu-manylinux1_i686.whl (234.6 kB view details)

Uploaded CPython 2.6mu

python_bsonjs-0.1.1-cp26-cp26m-win_amd64.whl (67.7 kB view details)

Uploaded CPython 2.6mWindows x86-64

python_bsonjs-0.1.1-cp26-cp26m-win32.whl (61.0 kB view details)

Uploaded CPython 2.6mWindows x86

python_bsonjs-0.1.1-cp26-cp26m-manylinux1_x86_64.whl (255.2 kB view details)

Uploaded CPython 2.6m

python_bsonjs-0.1.1-cp26-cp26m-manylinux1_i686.whl (234.6 kB view details)

Uploaded CPython 2.6m

python_bsonjs-0.1.1-cp26-cp26m-macosx_10_11_intel.whl (143.1 kB view details)

Uploaded CPython 2.6mmacOS 10.11+ Intel (x86-64, i386)

File details

Details for the file python-bsonjs-0.1.1.tar.gz.

File metadata

  • Download URL: python-bsonjs-0.1.1.tar.gz
  • Upload date:
  • Size: 142.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for python-bsonjs-0.1.1.tar.gz
Algorithm Hash digest
SHA256 be529edebd4d4878765f16d8f542aecd17f767330ea5fbbf865c5d5ba87cd603
MD5 ddf058535e08be7671a5550ffba89923
BLAKE2b-256 711a9473a290eae27a0cb97e6ab57c55f6f7d68a7ea97dd78007a3ae8ced845c

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 328514599ffb62454383861e2be95e9eadeb0230402ed454367e7b05ab9d2dcf
MD5 0b52e2462d684fe9ab710cd2debf32a2
BLAKE2b-256 dc821e126cbe16ba1b4bde988ab2120d2300d2681af39d2fc7bd52f67e31fe8e

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 6efcae1cc5271cb9ca74a130cbbe6491d45398cacada13a4a8530219d07763f9
MD5 671a7e645760711dc3fde7def93f6eea
BLAKE2b-256 c25e94e46d807afe53a8126575848d5dd24797b1e80db2c789fdbe2aa26dc40a

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6ee8e445113f15b014c91604a5dac4b0157b2581adbadd626fb32abe336461a2
MD5 967ba38441f2b989ae3d9467117e99b4
BLAKE2b-256 8d8b7cb8d801e650e477b2b83680b4da02fcee36ee65281871123d1faace54ba

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 ef924e3f330ebc2583eaabee1eb61bafc9684f413ae12e1d3112bc96a52fc910
MD5 9604c50afd65ac6f13715de11709f095
BLAKE2b-256 af5b89b5b16f9d72afdab6487c425236e694dbb0f1381d5532e4ba3fdd978f8e

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 547fab7f064ee79812da8947203080709664237c835e863fb3424ac50ce42f2a
MD5 e312dd35f819191d50b028ed6c7443cc
BLAKE2b-256 d309c0304d8d39666db8dce9d0e30becfe360b2a1a7762712b5a832f7adda0a3

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp34-cp34m-win_amd64.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 9a5515042a90abe7d0e3a317f6317dbeb22795443c4368111c14be5ec0b4d3bb
MD5 647e02aef00afc5174a48fc787c9487f
BLAKE2b-256 0b812bd96106d9620644df54b7d26f2d1804ae912f82bcddcce78e56affab73f

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp34-cp34m-win32.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 2a98928de6119a53b42ddb1a50f4bb123b3131cadd4ad49b32fc725c44c2385d
MD5 dffac71b1e3ae02c58d57c2de0fd5db6
BLAKE2b-256 08cd73004484d750b73fc1990dc814034a267cddd36557e928aa4d181a0c6783

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 62e96a3a06f20840f27882dcfc1a83210b98dd5c31bcfe1474ddc2da89b00bfd
MD5 507ffdb08c5023803bcfbb4b301b7481
BLAKE2b-256 07e2c12be041d9201f12989b721b2ba82842a87f8797c7ab490bc83bfe33d606

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp34-cp34m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 dc954dfc364b21cd3af500efa40069eea2d4af271b3984dca8737aff852d897d
MD5 32597773132ee5f33f064aa046f34a36
BLAKE2b-256 abe528763352dde37988255d848b84b1891e139cf1056666092231a36a6e1af6

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp34-cp34m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp34-cp34m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 694875b2512e10271fbda903f424e105b433488f126b53622d03335920f0d7c3
MD5 403d4a53c8ef10e435f48f58fd95b0ef
BLAKE2b-256 87d618639ada8d7039c0da1fc302149c962bac073905eba73e5a2029191ea597

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp33-cp33m-win_amd64.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp33-cp33m-win_amd64.whl
Algorithm Hash digest
SHA256 e5fb180cde0a762cd129bd38a6ed5f8400ff10460e0b53c7746bfe85c924a2d5
MD5 4e94df284c63d2cee8a88d1174d61b17
BLAKE2b-256 519b3df34b8ef32fd97d8a09b33e9a109e6ff7d18bdaeb84f1abfe1b9fec7a38

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp33-cp33m-win32.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp33-cp33m-win32.whl
Algorithm Hash digest
SHA256 042a33b851a8e90f66fd26e29fffc972bae58890a02c8e3410d8938e43bfe059
MD5 15359d897e6e72022607ccaeeb9c2c33
BLAKE2b-256 21f5194908c7e786cd3938e8f9b7fc2556bb965ec0e0a360691f7c15282ddfe3

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp33-cp33m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp33-cp33m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6793455aaaf6d97200fa45e678f9b5369c05d0b6aa4e335b894f4f7a1ad9819a
MD5 e1b00fe3dda6db4f27240af8e92926d3
BLAKE2b-256 f98530b2fb12053748ce5111cefacb6c1eb8a782a1b1e02736549701fcfebaa5

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp33-cp33m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp33-cp33m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 4f7f2cee31dcb29b545c5efc03e5fe374efa0396d3da901af21825a79a30c175
MD5 8d40b7384c85eeca877193540ed88abd
BLAKE2b-256 fe1cc3fad6344f9cb553c2a75f29ea48affb6489cd7610169d3db74051f0cf0e

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7dc33639d68381a6111332b0db0164715ce7c6565b115411346865212602bda1
MD5 17da9029ceeb8e7a362b6114387fa02c
BLAKE2b-256 c0533501d794002df424b731a0b7a5a7bc67dd347524974ac06a376384c5177f

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp27-cp27mu-manylinux1_i686.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 4c2870317cbe58d0702adad3fcd8e5ed654038a6877edb3627642cbd16b629f7
MD5 b5d385fb643a3ede9b3c11b912a5a089
BLAKE2b-256 61c7a124f72964fa917bfb72ec890e8c21e2cd9b95ed9cb2e57f96706be2c1e7

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 5a2697894ca1418078c7bc2f390ecbaed473eed22f020b649ea624003718d499
MD5 8bbce5831ed0d9c29b6a34a68bcc89c5
BLAKE2b-256 fcbc8fe6b941c1a1eb74a1f86d8061c894019267034e11960378089112186f28

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp27-cp27m-win32.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 11b428ff9b7d5ceaf6e2d9677f2f705a09a844333f055ccd4d4bb70977354139
MD5 642c206a79a7e3bfe04ddb052154bdef
BLAKE2b-256 3fd0f7f5428bc4b70bd066fb1b4be92f81b2bff17a5f50c87ec70e6b548a78d2

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7cb2209bdb7bd0a3eeb75ab357a3950d08739e8f943277bd03bddfdf8bbb0ee6
MD5 6d0b656ea30f64bfeb994b3b5b4fb053
BLAKE2b-256 e55e120939a0fb1ba82024d6d64e2c045cbd9461c4f72fe6f67bb2fe81ce3657

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp27-cp27m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 a37898cfeca2ef9952c9f0b38bb02d45803c280b9d77c3aa1c64801bfb24a7cd
MD5 cecec748468688767f85a0e2b94d795d
BLAKE2b-256 e488471b01274a430dfeb74caa7273fd8b4af7cd5e43bbc3f5738277d98671ba

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp27-cp27m-macosx_10_11_intel.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp27-cp27m-macosx_10_11_intel.whl
Algorithm Hash digest
SHA256 853bdb9bc051760c687e9ec8fdc144b4f5e4670de48934a0b6c0491a8cb0f295
MD5 b73de848804644b9c2c6257d00d0871c
BLAKE2b-256 db565ddbebb9f057483da4252d7041530bc52d0ecfbaab81bc292306dfe421c2

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp26-cp26mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp26-cp26mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b5194140109e0a2a7b6d324f369449b623b83276d38b87de3c75dbac24d22f0c
MD5 a31524b4f55d2bd95d81a61438c189ce
BLAKE2b-256 e8f7339c203c3440054ee71d2b64f624515872cd53213251bffd53a24041072a

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp26-cp26mu-manylinux1_i686.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp26-cp26mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 815ee0967fad87f05776ed8f5029a6856eb1436d871c290ae191911d7feae6c8
MD5 e8706b6dde671b1fd4c9242063281060
BLAKE2b-256 7d8eede459979bd32c0c8eb10097637d0d093f470f5d58e7f63c1f325ca81e7d

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp26-cp26m-win_amd64.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp26-cp26m-win_amd64.whl
Algorithm Hash digest
SHA256 caf89f832a709c2b9d0b5597f8f688eafda81f9287fe5268e2c1e558a0ec8087
MD5 d024f77d85a88daff67e74d59700da57
BLAKE2b-256 7b8bd1b12d4c88eac71bda6c196a77b43bb01d9b3589a5aa4b5830af563f3883

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp26-cp26m-win32.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp26-cp26m-win32.whl
Algorithm Hash digest
SHA256 bf13e0eefa358b68d85f9278d5dbdeecfdf60a65755ef891c6ef927bef47bd96
MD5 950b6b7e3bb575d8b6bdeb9354f7e13f
BLAKE2b-256 c6cf1fa4e4b2285576ba58888320ea10beeffa1f3529652138a0032247b2255a

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp26-cp26m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp26-cp26m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b57772e8ef5adffe9d7bed6c0a368ff56c3676dadc156e51bfd35b0c350fca4a
MD5 1e01e1c3d15df2a271e495f2e2c20cee
BLAKE2b-256 7441bc73c484dc58af460dfcbb751ebe4f981dee8cd1a6071ae5299bfa2b7b4f

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp26-cp26m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp26-cp26m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 0eefd12831749961cd7e3f5d34d7986ef6b6bd65307db37f159e7a57e0aa1826
MD5 a15916d2f1c19fdcd0e5030f2a128b85
BLAKE2b-256 8dbdce91ff40e990700cade754e887760a11b5aeda9957035f47811c692df639

See more details on using hashes here.

File details

Details for the file python_bsonjs-0.1.1-cp26-cp26m-macosx_10_11_intel.whl.

File metadata

File hashes

Hashes for python_bsonjs-0.1.1-cp26-cp26m-macosx_10_11_intel.whl
Algorithm Hash digest
SHA256 f1892cb3e0eae65ed02e39d46333c07d061500871c6d1c4a510ecab4ba70bfa0
MD5 1e6279e647cd10e5557fb1e57fe4de2e
BLAKE2b-256 02ac2b014e5c048291eda2285943b61771775dac0726c36883dfe408400b333b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page