Skip to main content

Asynchronous Python ODM for MongoDB

Project description

Beanie

Beanie - is an Asynchronous Python object-document mapper (ODM) for MongoDB, based on Motor and Pydantic.

When using Beanie each database collection has a corresponding Document that is used to interact with that collection. In addition to retrieving data, Beanie allows you to add, update, or delete documents from the collection as well.

Beanie saves you time by removing boiler-plate code and it helps you focus on the parts of your app that actually matter.

Data and schema migrations are supported by Beanie out of the box.

Installation

PIP

pip install beanie

Poetry

poetry add beanie

Quick Start

from typing import Optional, List

import motor
from beanie import Document, init_beanie
from pydantic import BaseModel


class Tag(BaseModel):
    name: str
    color: str


class Note(Document):
    title: str
    text: Optional[str]
    tag_list: List[Tag] = []


async def main():
    # Crete Motor client
    client = motor.motor_asyncio.AsyncIOMotorClient(
        "mongodb://user:pass@host:27017"
    )
    
    # Init beanie with the Note document class
    await init_beanie(database=client.db_name, document_models=[Note])

    # Get all the notes
    all_notes = await Note.find_all().to_list()

Documentation

ODM

  • Tutorial - ODM usage examples
  • API - Full list of the ODM classes and methods with descriptions

Migrations

Example Projects

  • FastAPI Demo - Beanie and FastAPI collaboration demonstration. CRUD and Aggregation.
  • Indexes Demo - Regular and Geo Indexes usage example wrapped to a microservice.

Articles

Resources

  • GitHub - GitHub page of the project
  • Changelog - list of all the valuable changes
  • Discord - ask your questions, share ideas or just say Hello!!

Supported by JetBrains

JetBrains

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

beanie-1.0.0b1.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

beanie-1.0.0b1-py3-none-any.whl (42.2 kB view details)

Uploaded Python 3

File details

Details for the file beanie-1.0.0b1.tar.gz.

File metadata

  • Download URL: beanie-1.0.0b1.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/5.8.0-48-generic

File hashes

Hashes for beanie-1.0.0b1.tar.gz
Algorithm Hash digest
SHA256 5c3b53bbbb2cc9785237799a640d3a5a89659ca8d1a4f5722027b12234f64bae
MD5 fdc0a999c02c1919e73e735d72b1aa3e
BLAKE2b-256 6a28432b6b0cbf03f1f967e3b124687f8a42a07be85d0acb689e56b1e7f57d2f

See more details on using hashes here.

File details

Details for the file beanie-1.0.0b1-py3-none-any.whl.

File metadata

  • Download URL: beanie-1.0.0b1-py3-none-any.whl
  • Upload date:
  • Size: 42.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/5.8.0-48-generic

File hashes

Hashes for beanie-1.0.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 68aa2ebe597d5166c74cd29ab45fc3883fd51caeacbb7b786decd56b3e71674f
MD5 89151e751b4ffc2229f7b422239348e4
BLAKE2b-256 13394a205d21760798d0cb9fd9fe112f49e46692bff6775e029e17b7943b6ff6

See more details on using hashes here.

Supported by

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