Skip to main content

Repository Patterns for Python

Project description

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:

  • Faster prototyping and development
  • Easier to migrate the database
  • More readable code, Pythonic
  • Unit testing and testing in general is safer and easier

Features

Main features:

  • Support for Pydantic models for data validation
  • Identical way to create, read, update and delete (CRUD)
  • Pythonic and simple syntax
  • Support for more complex queries (greater than, not equal, less than etc.)

Supported repositories:

  • SQL
  • MongoDB
  • In-memory (Python list)
  • JSON files
  • CSV file

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

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

redbird-0.7.1.tar.gz (154.9 kB view details)

Uploaded Source

Built Distribution

redbird-0.7.1-py3-none-any.whl (60.1 kB view details)

Uploaded Python 3

File details

Details for the file redbird-0.7.1.tar.gz.

File metadata

  • Download URL: redbird-0.7.1.tar.gz
  • Upload date:
  • Size: 154.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for redbird-0.7.1.tar.gz
Algorithm Hash digest
SHA256 9ef1098f2a0e68afe40349475018f7694b05bdf92250772cd8d0126f26de58a9
MD5 74f9c23ec9eb6a4cb3e56776584688b5
BLAKE2b-256 4c126cbd6fc135a478ebc77e8ac2dd949a1c503d038a9181881a52c3e4ad6395

See more details on using hashes here.

File details

Details for the file redbird-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: redbird-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 60.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for redbird-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6a1fe83fa9dfc0c5b9cb256b54376c299c423f2daba7bcbc081a820ff5b3c6c1
MD5 f6a0f99a556915f6668cf463d327b95a
BLAKE2b-256 b647af2f7054e12d038115adc51073d2ce280ee4f4e368ad5a085eb149504ced

See more details on using hashes here.

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