bson
BSON codec for Python
What it is and what it does
bson is a standalone BSON codec for Python that does not require MongoDB to be installed. It provides functions to serialize Python dictionaries and other objects into BSON binary format and deserialize BSON back into Python objects. The package also includes utilities for sending and receiving BSON objects over network sockets by patching the socket module.
The package is useful when you need to work with BSON data outside of a MongoDB context—for example, when interoperating with other systems that use BSON as a data format, or when you want BSON serialization without the full MongoDB driver. It has no runtime dependencies, making it lightweight to add to a project.
Use it for:
- Serialize and deserialize BSON data in standalone Python applications that need to exchange data with BSON-based systems.
- Communicate BSON objects over network sockets between Python processes or services.
- Parse BSON-formatted data from files or external sources without installing MongoDB.
- Embed BSON encoding/decoding in tools that work with MongoDB exports or BSON-compatible APIs.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Encodes and decodes BSON (Binary JSON) data independently of MongoDB, and can serialize BSON objects over network sockets.
No—not recommended for new projects. The package has not been updated since 2020-05-26 and targets Python versions (2.6–3.6) that are no longer supported. Compatibility with modern Python (3.7+) is undocumented and likely broken. If you need BSON support, consider using the official pymongo library's BSON codec instead, which is actively maintained.
Install
bson on PyPI
pip
pip install bsonuv
uv add bsonpoetry
poetry add bsonInstalling bson
Before you install
High install friction: the package has not been updated since 2020-05-26 and is classified as aging. It targets Python 2.6 through 3.6, which are no longer actively supported. Compatibility with modern Python versions is unspecified.
License in practice
Licensed under BSD (permissive), which allows use in most projects without restriction, but you should verify the specific BSD variant matches your compliance requirements.
Quickstart
pip install bson
import bson
a = bson.dumps({"A": [1, 2, 3, 4, 5, "6", "7", {"C": "DS"}]})
b = bson.loads(a)
Package targets Python 2.6–3.6; compatibility with Python 3.7+ is not documented and may be broken.
Verify before relying
- Whether this package works reliably on Python 3.7 and later versions despite classifier claims ending at 3.6.
- Active maintenance status and whether the repository accepts pull requests or is effectively unmaintained.
- Whether the socket patching feature (bson.patch_socket) is still functional and tested.
Package facts
| License | BSD (permissive) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | aging — 2,271 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 967,185/month — #4,617 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: bson-0.5.10.tar.gz
Keywords: BSON, codec
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
pymongoPyMongo is the official MongoDB Python driver,…
permissive · top 1,000 on PyPI
pymongocryptPyMongoCrypt provides Python bindings for…
permissive · top 5,000 on PyPI
pymongoarrowPyMongoArrow converts MongoDB query results…
permissive · top 15,000 on PyPI
mongomockMongomock provides an in-memory mock of MongoDB…
permissive · top 5,000 on PyPI
pymongo-auth-awsEnables PyMongo to authenticate to MongoDB…
permissive · top 5,000 on PyPI
py-ubjsonEncodes and decodes data in Universal Binary…
permissive · top 5,000 on PyPI
Flask-PyMongoFlask-PyMongo integrates MongoDB database…
permissive · top 15,000 on PyPI
pymongo_inmemoryProvides an in-memory MongoDB instance for…
permissive · top 15,000 on PyPI
mongoengineMongoEngine provides an Object-Document Mapper…
permissive · top 5,000 on PyPI
ytsaurus-ysonProvides C++ bindings for serializing and…
permissive · top 15,000 on PyPI