Miksus / red-bird

Repository Patterns for Python
https://red-bird.readthedocs.io
MIT License
163 stars 22 forks source link
database mongodb orm repository-pattern sql

Red Bird

Repository Patterns for Python

Generic database implemetation for SQL, MongoDB and in-memory lists


Pypi version build codecov Documentation Status PyPI pyversions

Repository pattern is a technique to abstract the data access from the domain/business logic. In other words, it decouples the database access from the application code. The aim is that the code runs the same regardless if the data is stored to an SQL database, NoSQL database, file or even as an in-memory list.

Read more about the repository patterns in the official documentation.

Why?

Repository pattern has several benefits over embedding the database access to the application:

Features

Main features:

Supported repositories:

Examples

First, we create a simple repo:

from redbird.repos import MemoryRepo
repo = MemoryRepo()

Note: the following examples work on any repository, not just in-memory repository.

Adding/creating items:

repo.add({"name": "Anna", "nationality": "British"})

Reading items:

repo.filter_by(name="Anna").all()

Updating items:

repo.filter_by(name="Anna").update(nationality="Finnish")

Deleting items:

repo.filter_by(name="Anna").delete()

See more from the official documentation.

Author