This is a sample project to demonstrate an implementation and benefits of the Repository
pattern in python.
The beautfy of this pattern is enhanced when used together with DIP (dependency inversion principle), where it states that we should not depend on implementations but rather abstractions.
We also get the benefit of being able to easily mock our "service layer" (database accesses), since we can create a Fake that follows the same interface and use it to test components that depend on external sources (With some changes you can also create a repository for an external API).
This is shown in the integration tests, where we use the fake to test components that need the a repository.
This is an example repository and I don't advice you to import it to your project and use it as package, rather you should take it as reference and adapt it to your needs
I recommend developing with VScode and docker container (DockerFile provided). You can install this project as a packag make install or create a wheel via make dist.
- Free software: MIT license
- Abstract classes for SQL and NoSQL repositories.
- Working example for SQL based repositories.
- Two SqlRepositories,
PandasSqlRepository
andSqlLite3Repository
. FakeSqlRepository
used to show the benefits of its approach. alongside tests.MongoSqlRepository
andFakeMongoRepository
(no tests or example yet, and probably never will, but are kept there).
This package was created with Cookiecutter and the `ZordoC/cookiecutter-simple-pypackage`_ project template.