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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redbird-0.5.1-py3-none-any.whl (40.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: redbird-0.5.1.tar.gz
  • Upload date:
  • Size: 47.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for redbird-0.5.1.tar.gz
Algorithm Hash digest
SHA256 7ed1268f8e87088642b83665ef6ea64eb7c7bcb5b2fa4887b2e976c282b38aea
MD5 6605addc7eeb8d7da9cc89c76c2fed44
BLAKE2b-256 73ce968270ec1c581988dd0d4d9e4eaf513c65fe507ae1375a6704aff0b3330a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: redbird-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 40.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for redbird-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0cb1c4736ea1487c51dfc63ea1a320fd1fa4a4c5a594618df887df4e775dfbab
MD5 12a2327ca641711813752a00b81b931e
BLAKE2b-256 20f136594488aada5edc2580221d05b1dc2e4a9c53d4ae88487404991983581f

See more details on using hashes here.

Supported by

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