Assimilator - the best Python patterns for the best projects
Install now
pip install py-assimilator
Code comparison
- Boilerplate - you repeat yourself!
- Dependencies - lots of external dependencies!
- Coding mistakes - bugs and errors!
- Readability - no easy way to read your code!
- Boring - repeat this boring process over and over again!
def create_user():
name = request.json['name']
email = request.json['email']
new_user = User(name=name, email=email) # DEPENDENCY!
db.session.add(new_user)
db.session.commit() # DEPENDENCY!
return new_user
def get_all_users():
users = User.query.all() # DEPENDENCY!
output = []
for user in users: # BOILERPLATE!
user_data = {}
user_data['name'] = user.name
user_data['email'] = user.email
output.append(user_data)
return users
def get_user(user_id):
user = User.query.get_or_404(user_id) # DEPENDENCY!
user_data = {}
user_data['name'] = user.name # BOILERPLATE!
user_data['email'] = user.email # BOILERPLATE!
return user_data
def update_user(user_id):
user = User.query.get_or_404(user_id) # DEPENDENCY!
user.name = request.json['name'] # BOILERPLATE!
user.email = request.json['email'] # BOILERPLATE!
db.session.commit() # NO ACID! DEPENDENCY!
return user
def delete_user(user_id):
user = User.query.get_or_404(user_id) # DEPENDENCY!
db.session.delete(user) # NO ACID!
db.session.commit() # DEPENDENCY!
return True
- One pattern - get all the functions from CRUDService class
- Independent code - no dependencies at all!
- Coding mistakes - common bugs and errors are fixes!
- Multiple databases - change your storage without changing your code!
- Fast - spend 10 minutes instead of 10 hours!
- Extensible - make CRUDService pattern suit your needs!
service = create_crud_service()
def create_user(user_data: dict):
return service.create(user_data)
def list_users():
return service.list()
def get_user(id: int):
return service.get(id=id)
def update_user(id: int, new_data: dict):
return service.update(id=id, is_admin=True, update_data=new_data)
def delete_user():
return service.delete(username="Tom")
# Full FastAPI CRUD example on Github
# https://github.com/knucklesuganda/py_assimilator/tree/master/examples/fastapi_crud_example
- We depend on other people and their bugs!
- It's hard to update our code!
- We cannot use new technologies!
- Complicated refactoring!
from sqlalchemy import Table, Column,...
from models import User, Friend, Like,...
from database_init import init, session_create...
from database_filters import my_filter...
def bad_code():
init()
session = session_create()
my_user = session(User).filter(
Friend.id == 1,
Like.post.id == 5,
).first()
return my_user.username
- We use patterns to hide dependencies from other modules!
- It's easy to update our code since we have no dependencies!
- We can easily use new technologies!
- Refactoring is easy!
- Patterns are extensible to your specific needs!
from assimilator.core.database import Repository, filter_
def independent_code(repository: Repository):
return repository.get(
filter_(friend__id=1, like__post=5)
)
What is that all about?
- We want to write the best code.
- We need the best patterns and techniques for this.
- We use PyAssimilator and save lots of time.
- We use PyAssimilator and write the best code.
- We use PyAssimilator and use the best patterns.
- We use PyAssimilator and have no dependencies in our code.
- We use PyAssimilator and can switch one database to another in a matter of seconds.
- We learn PyAssimilator once and use it forever!
- And most importantly, we make Python projects better!
So, do I really need it?
If you want to spend less time writing your code, but write better code - then you must use PyAssimilator. It can be hard to start if you have no experience with good code, so you can watch creator's video tutorials.
Our vision
Make Python the best programming language for enterprise development and use all of its dynamic capabilities to write things that other languages can't even comprehend!
- Pattern substitution(switch databases easily) ✔️
- Event-based apps(in development) 🛠️
- 45% of all Python projects use PyAssimilator 🛠️
- Independent code(in development) 🛠️
- Adaptive patterns(in development) 🛠️
- Automatic code improvements(in development) 🛠️
- Decentralized code management(in development) 🛠️
If you want to help with any of those things - be free to contribute to the project. Remember, you never do anything for free - and that will not be the case either.
Sources
Donate and create your own framework!
Donate using this link and help PyAssimilator prosper! You can also request a feature that you want to see in our framework and we will have it in our priority list!
Contributors
Stars history
⭐Stargazers⭐
Types of patterns
These are different use cases for the patterns implemented:
- Database - patterns for database/data layer interactions.
- Events(in development) - projects with events or event-driven architecture.
- Unidentified - patterns that are useful for different purposes.
Available providers
Providers are different patterns for external modules like SQLAlchemy or FastAPI.
- Alchemy(Database, Events) - patterns for SQLAlchemy for both database and events.
- Kafka(Events) - patterns in Kafka related to events.
- Internal(Database, Events) - internal is the type of provider that saves everything in memory(dict, list and all the tools within your app).
- Redis(Database, Events) - redis_ allows us to work with Redis memory database.
- MongoDB(Database) - mongo allows us to work with MongoDB database.