Skip to main content

Asynchronous Python ODM for MongoDB

Project description

Beanie

Beanie - is an Asynchronous Python ODM for MongoDB, based on Motor and Pydantic.

It uses an abstraction over Pydantic models and Motor collections to work with the database. Class Document allows to: create, replace, update, get, find and aggregate.

Beanie supports migrations 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()

Materials

ODM

  • Tutorial - ODM usage examples
  • Documentation - 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!!

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-0.4.1.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

beanie-0.4.1-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file beanie-0.4.1.tar.gz.

File metadata

  • Download URL: beanie-0.4.1.tar.gz
  • Upload date:
  • Size: 17.8 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-0.4.1.tar.gz
Algorithm Hash digest
SHA256 881cf43f29caf9a93f0a2a49a3a0fe4cbf60a3dc3c9704ba4c2a0842ed219dca
MD5 72a9d7bed65611c84c2f009b1ae18e46
BLAKE2b-256 88bac46a90af39d905647a8e67d5e4b3ed5d2ed3c5dc39a7a275e83bed4453ba

See more details on using hashes here.

File details

Details for the file beanie-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: beanie-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 25.8 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-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da8a444bff732c913a0d5c61da7f508550182f144c354ed78c9e7b5605421fe2
MD5 7c6f2c7bfeba8b96cb5d0b0c08f39b85
BLAKE2b-256 46d4be86aa351b5087ff957d59b92d92b045ac5788d5bf070160721bb130aaf6

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