Skip to main content

Tools for using NumPy, Pandas, Polars, and PyArrow with MongoDB

Project description

PyMongoArrow

PyPI Version Python Versions Monthly Downloads Documentation Status

PyMongoArrow is a companion library to PyMongo that contains tools for loading MongoDB query result sets as Apache Arrow tables, Pandas DataFrames or NumPy arrays.

>>> from pymongoarrow.monkey import patch_all
... patch_all()
... from pymongoarrow.api import Schema
... schema = Schema({"_id": int, "qty": float})
... from pymongo import MongoClient
... client = MongoClient()
... client.db.data.insert_many(
...     [{"_id": 1, "qty": 25.4}, {"_id": 2, "qty": 16.9}, {"_id": 3, "qty": 2.3}]
... )
... data_frame = client.db.test.find_pandas_all({}, schema=schema)
... data_frame
   _id   qty
0    1  25.4
1    2  16.9
2    3   2.3
... arrow_table = client.db.test.find_arrow_all({}, schema=schema)
# The schema may also be omitted
... arrow_table = client.db.test.find_arrow_all({})
... arrow_table
pyarrow.Table
_id: int64
qty: double
... ndarrays = client.db.test.find_numpy_all({}, schema=schema)
... ndarrays
{'_id': array([1, 2, 3]), 'qty': array([25.4, 16.9,  2.3])}

PyMongoArrow is the recommended way to materialize MongoDB query result sets as contiguous-in-memory, typed arrays suited for in-memory analytical processing applications.

Installing PyMongoArrow

PyMongoArrow is available on PyPI:

python -m pip install pymongoarrow

To use PyMongoArrow with MongoDB Atlas' mongodb+srv:// URIs, you will need to also install PyMongo with the srv extra:

python -m pip install 'pymongo[srv]' pymongoarrow

To use PyMongoArrow APIs that return query result sets as pandas DataFrame instances, you will also need to have the pandas package installed:

python -m pip install pandas

Note: pymongoarrow is not supported or tested on big-endian systems (e.g. Linux s390x).

Development Install

See the instructions in the [Contributing Guide][./CONTRIBUTING.md]

Documentation

Full documentation is available on Read the Docs.

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

pymongoarrow-1.5.1.tar.gz (59.6 kB view hashes)

Uploaded Source

Built Distributions

pymongoarrow-1.5.1-cp312-cp312-win_amd64.whl (232.1 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

pymongoarrow-1.5.1-cp312-cp312-manylinux_2_28_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.28+ x86-64

pymongoarrow-1.5.1-cp312-cp312-manylinux_2_28_aarch64.whl (1.5 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.28+ ARM64

pymongoarrow-1.5.1-cp312-cp312-macosx_11_0_arm64.whl (259.3 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

pymongoarrow-1.5.1-cp312-cp312-macosx_10_15_x86_64.whl (276.7 kB view hashes)

Uploaded CPython 3.12 macOS 10.15+ x86-64

pymongoarrow-1.5.1-cp311-cp311-win_amd64.whl (236.8 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

pymongoarrow-1.5.1-cp311-cp311-manylinux_2_28_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

pymongoarrow-1.5.1-cp311-cp311-manylinux_2_28_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.28+ ARM64

pymongoarrow-1.5.1-cp311-cp311-macosx_11_0_arm64.whl (259.9 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pymongoarrow-1.5.1-cp311-cp311-macosx_10_15_x86_64.whl (280.0 kB view hashes)

Uploaded CPython 3.11 macOS 10.15+ x86-64

pymongoarrow-1.5.1-cp310-cp310-win_amd64.whl (236.3 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pymongoarrow-1.5.1-cp310-cp310-manylinux_2_28_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

pymongoarrow-1.5.1-cp310-cp310-manylinux_2_28_aarch64.whl (1.5 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.28+ ARM64

pymongoarrow-1.5.1-cp310-cp310-macosx_11_0_arm64.whl (258.5 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pymongoarrow-1.5.1-cp310-cp310-macosx_10_15_x86_64.whl (277.6 kB view hashes)

Uploaded CPython 3.10 macOS 10.15+ x86-64

pymongoarrow-1.5.1-cp39-cp39-win_amd64.whl (236.4 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pymongoarrow-1.5.1-cp39-cp39-manylinux_2_28_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.28+ x86-64

pymongoarrow-1.5.1-cp39-cp39-manylinux_2_28_aarch64.whl (1.5 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.28+ ARM64

pymongoarrow-1.5.1-cp39-cp39-macosx_11_0_arm64.whl (280.1 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pymongoarrow-1.5.1-cp39-cp39-macosx_10_15_x86_64.whl (296.5 kB view hashes)

Uploaded CPython 3.9 macOS 10.15+ x86-64

pymongoarrow-1.5.1-cp38-cp38-win_amd64.whl (237.7 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

pymongoarrow-1.5.1-cp38-cp38-manylinux_2_28_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.28+ x86-64

pymongoarrow-1.5.1-cp38-cp38-manylinux_2_28_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.28+ ARM64

pymongoarrow-1.5.1-cp38-cp38-macosx_11_0_arm64.whl (281.2 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

pymongoarrow-1.5.1-cp38-cp38-macosx_10_15_x86_64.whl (297.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.15+ x86-64

Supported by

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