Skip to main content
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

Metadata

Release files for python-bsonjs 0.1.0

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

Source distribution (sdist)

Source distribution for python-bsonjs 0.1.0
File Size Uploaded
python-bsonjs-0.1.0.tar.gz 142.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for python-bsonjs 0.1.0
File
python_bsonjs-0.1.0-cp35-cp35m-manylinux1_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 Details
python_bsonjs-0.1.0-cp35-cp35m-manylinux1_i686.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-32 Details
python_bsonjs-0.1.0-cp35-cp35m-macosx_10_6_intel.whl CPython 3.5 CPython 3.5 pymalloc macOS 10.6+ Intel (x86-64, i386) Details
python_bsonjs-0.1.0-cp34-cp34m-manylinux1_x86_64.whl CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-64 Details
python_bsonjs-0.1.0-cp34-cp34m-manylinux1_i686.whl CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-32 Details
python_bsonjs-0.1.0-cp34-cp34m-macosx_10_6_intel.whl CPython 3.4 CPython 3.4 pymalloc macOS 10.6+ Intel (x86-64, i386) Details
python_bsonjs-0.1.0-cp33-cp33m-manylinux1_x86_64.whl CPython 3.3 CPython 3.3 pymalloc Linux glibc 2.5+ x86-64 Details
python_bsonjs-0.1.0-cp33-cp33m-manylinux1_i686.whl CPython 3.3 CPython 3.3 pymalloc Linux glibc 2.5+ x86-32 Details
python_bsonjs-0.1.0-cp27-cp27mu-manylinux1_x86_64.whl CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-64 Details
python_bsonjs-0.1.0-cp27-cp27mu-manylinux1_i686.whl CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-32 Details
python_bsonjs-0.1.0-cp27-cp27m-manylinux1_x86_64.whl CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.5+ x86-64 Details
python_bsonjs-0.1.0-cp27-cp27m-manylinux1_i686.whl CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.5+ x86-32 Details
python_bsonjs-0.1.0-cp27-cp27m-macosx_10_11_intel.whl CPython 2.7 CPython 2.7 pymalloc macOS 10.11+ Intel (x86-64, i386) Details
python_bsonjs-0.1.0-cp26-cp26mu-manylinux1_x86_64.whl CPython 2.6 CPython 2.6 pymalloc wide-unicode Linux glibc 2.5+ x86-64 Details
python_bsonjs-0.1.0-cp26-cp26mu-manylinux1_i686.whl CPython 2.6 CPython 2.6 pymalloc wide-unicode Linux glibc 2.5+ x86-32 Details
python_bsonjs-0.1.0-cp26-cp26m-manylinux1_x86_64.whl CPython 2.6 CPython 2.6 pymalloc Linux glibc 2.5+ x86-64 Details
python_bsonjs-0.1.0-cp26-cp26m-manylinux1_i686.whl CPython 2.6 CPython 2.6 pymalloc Linux glibc 2.5+ x86-32 Details
python_bsonjs-0.1.0-cp26-cp26m-macosx_10_11_intel.whl CPython 2.6 CPython 2.6 pymalloc macOS 10.11+ Intel (x86-64, i386) Details

Total release size: 4.2 MB

Release files / python-bsonjs-0.1.0.tar.gz

Download URL python-bsonjs-0.1.0.tar.gz
Size 142.0 kB
Tags Source
SHA-256 checksum
How to use checksums
09acbb7617c3d2e275e29a157cb40ff3e3c0561230581316d141eba7df3fc14f
BLAKE2b-256 checksum
How to use checksums
dd851897718b503b45f421450e4f0ed18bc11a179c8ffe1c67356a6ce6169c51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp35-cp35m-manylinux1_x86_64.whl

Download URL python_bsonjs-0.1.0-cp35-cp35m-manylinux1_x86_64.whl
Size 256.5 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
2911a930bf2c1799247af26651f6e4a1be40861de857486ad2f2ff2b9451fbf7
BLAKE2b-256 checksum
How to use checksums
e8fd9a87bab77f7db6002aa75dace17a39751c73aabe43ed9a825ce78c752b91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp35-cp35m-manylinux1_i686.whl

Download URL python_bsonjs-0.1.0-cp35-cp35m-manylinux1_i686.whl
Size 235.0 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
d63ed960c947f4c629be2356de66c01385a5f4c3253e4908a4ae65080c4ac4ce
BLAKE2b-256 checksum
How to use checksums
69a02a9324609862b4628e13408fc36ba3382ce71743be7c7aed96cdf28944a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp35-cp35m-macosx_10_6_intel.whl

Download URL python_bsonjs-0.1.0-cp35-cp35m-macosx_10_6_intel.whl
Size 156.9 kB
Tags CPython 3.5 CPython 3.5 pymalloc macOS 10.6+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
e1a20b0eb45a42ce22de23ef6462b36f8264fa2a2ddaec34f1004b5800b0e599
BLAKE2b-256 checksum
How to use checksums
f57645881e31017e88e7c90d65666a8c85f3c53c5e16a708236851f4a8a6633e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp34-cp34m-manylinux1_x86_64.whl

Download URL python_bsonjs-0.1.0-cp34-cp34m-manylinux1_x86_64.whl
Size 256.3 kB
Tags CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
6d0968ea150522e554f8c9e83b06c4b26de6a045d36188b9052f9adc007add86
BLAKE2b-256 checksum
How to use checksums
dbe6961e2720c99eec5f27c641df25322c10d1dad6b590dde9be54dddd189c4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp34-cp34m-manylinux1_i686.whl

Download URL python_bsonjs-0.1.0-cp34-cp34m-manylinux1_i686.whl
Size 234.8 kB
Tags CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
08ef69d103e7f0499bd924f164834f1a1251515bf4d865b4380f06f441b3f1de
BLAKE2b-256 checksum
How to use checksums
c96fc6675b645c1defaa0ec973677dcf3dc4c464c2b25ef69cecb125af5bcb81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp34-cp34m-macosx_10_6_intel.whl

Download URL python_bsonjs-0.1.0-cp34-cp34m-macosx_10_6_intel.whl
Size 156.8 kB
Tags CPython 3.4 CPython 3.4 pymalloc macOS 10.6+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
bb3d521a5c1cf741fe301b457ac5f149583326ec98d47984efeadad2bf578dc2
BLAKE2b-256 checksum
How to use checksums
3c24810020c55191e8f6befbbfddaa49a47d410c841d787477ed54d94ae320ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp33-cp33m-manylinux1_x86_64.whl

Download URL python_bsonjs-0.1.0-cp33-cp33m-manylinux1_x86_64.whl
Size 256.2 kB
Tags CPython 3.3 CPython 3.3 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
fda53c6a1b2332bf15cfaf638fb4b18a26f56cd1def555bd3617c6dabc24b47b
BLAKE2b-256 checksum
How to use checksums
96aebac24502a57dae8ff734441620ad4eb92ec68c71420a46971dc619ce5fa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp33-cp33m-manylinux1_i686.whl

Download URL python_bsonjs-0.1.0-cp33-cp33m-manylinux1_i686.whl
Size 234.8 kB
Tags CPython 3.3 CPython 3.3 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
2b5f8eabc9e5589d768f489b86ae87862550e3df1f1929242657f52927455ebd
BLAKE2b-256 checksum
How to use checksums
d57f6fb7ba5a2eebe94f63d7520a53fd8320ab17e2d48b5a498f9cf34e77d643
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp27-cp27mu-manylinux1_x86_64.whl

Download URL python_bsonjs-0.1.0-cp27-cp27mu-manylinux1_x86_64.whl
Size 255.2 kB
Tags CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
791422eda169d99815c029aaf2bd1239e07658d7a6651ed8a3dbb5e9f9256669
BLAKE2b-256 checksum
How to use checksums
effb7dd3a20a50c0af376246fa0c915bc343a838b048b0ca937666ee72bb7b9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp27-cp27mu-manylinux1_i686.whl

Download URL python_bsonjs-0.1.0-cp27-cp27mu-manylinux1_i686.whl
Size 234.6 kB
Tags CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
a4361b14599bb5dd5ac66f436ece3226e2f3c0b245506d2c462019f021fad117
BLAKE2b-256 checksum
How to use checksums
9c3765bc49ff82ee67e2bb0a3149d314831fdf9fb0250cf7dfecd476bcc74c9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp27-cp27m-manylinux1_x86_64.whl

Download URL python_bsonjs-0.1.0-cp27-cp27m-manylinux1_x86_64.whl
Size 255.2 kB
Tags CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
4c512277137002c6faf1ddae9cf9edfeb7b6a6e5638088f3e62caef6c55182c6
BLAKE2b-256 checksum
How to use checksums
91a4f6f1ca1418a6da0dbd18dd0f6bd3572dba2c984774a63d43604ffac7ac82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp27-cp27m-manylinux1_i686.whl

Download URL python_bsonjs-0.1.0-cp27-cp27m-manylinux1_i686.whl
Size 234.6 kB
Tags CPython 2.7 CPython 2.7 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
cdf913f20df3116d4d6f8e5b3032d00cb99135ddedcca54df737a0d6c3c33642
BLAKE2b-256 checksum
How to use checksums
93ca151884cee640b16c1fc68918c2cae37f32fbf19e05b7aa68c1b08b7270d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp27-cp27m-macosx_10_11_intel.whl

Download URL python_bsonjs-0.1.0-cp27-cp27m-macosx_10_11_intel.whl
Size 143.1 kB
Tags CPython 2.7 CPython 2.7 pymalloc macOS 10.11+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
cc208edecf07f5ac02c1011add1ff309240d28c549f3d679a51d4127f985f18d
BLAKE2b-256 checksum
How to use checksums
a9717fbd04eb96d27a96caf1a46ea9422308cd8fdce6033c83abedac615d156b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp26-cp26mu-manylinux1_x86_64.whl

Download URL python_bsonjs-0.1.0-cp26-cp26mu-manylinux1_x86_64.whl
Size 255.2 kB
Tags CPython 2.6 CPython 2.6 pymalloc wide-unicode Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
7cdc9ab80e0350c2b3ef0e88223842b13028cf2411f2f92a7a7877526b97a292
BLAKE2b-256 checksum
How to use checksums
e3122a1da73cb32a1f835ef35254fc91cc2fcca2362d3acf9c76d233f2aae2df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp26-cp26mu-manylinux1_i686.whl

Download URL python_bsonjs-0.1.0-cp26-cp26mu-manylinux1_i686.whl
Size 234.6 kB
Tags CPython 2.6 CPython 2.6 pymalloc wide-unicode Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
e7daec1d6deca3224ae94f7be067984cfdfc82f6b157a8dcd258889b19003c40
BLAKE2b-256 checksum
How to use checksums
a4a3d083aa07631558a9bdedf581e8e01177153782e10f46e93c3973df40d2a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp26-cp26m-manylinux1_x86_64.whl

Download URL python_bsonjs-0.1.0-cp26-cp26m-manylinux1_x86_64.whl
Size 255.2 kB
Tags CPython 2.6 CPython 2.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
693f62b8adda158599be1a9cd001b75e354250ac848ae928fef6dea6b82bb0b8
BLAKE2b-256 checksum
How to use checksums
e8f8df42b1ae77346deae8efdc8e1a362fbd3054f9d2d63da19907e8765c62ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp26-cp26m-manylinux1_i686.whl

Download URL python_bsonjs-0.1.0-cp26-cp26m-manylinux1_i686.whl
Size 234.6 kB
Tags CPython 2.6 CPython 2.6 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
a6f0f704b986dd762b59f5ad289bd584d796e4160d46ec99f6dff1fc228fb6db
BLAKE2b-256 checksum
How to use checksums
1d6e6059b62dd2739b54646d8c01992019760edef0843acf6e1dc98619891da4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / python_bsonjs-0.1.0-cp26-cp26m-macosx_10_11_intel.whl

Download URL python_bsonjs-0.1.0-cp26-cp26m-macosx_10_11_intel.whl
Size 143.1 kB
Tags CPython 2.6 CPython 2.6 pymalloc macOS 10.11+ Intel (x86-64, i386)
SHA-256 checksum
How to use checksums
ca4f6f2af5806c0834dcd6882c29dfb663b9f03bbcce6952566bec0482ca770d
BLAKE2b-256 checksum
How to use checksums
9b4e00c1acecd23414d23e172e92612ae94425ef182c39d83d44a0228f9d2b93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.7.0

8 release files

0.6.0

6 release files

0.5.0

6 release files

0.4.0

7 release files

0.3.0

7 release files

0.2.0

49 release files

0.1.1

29 release files

This release

0.1.0 This release

19 release files

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