-
Notifications
You must be signed in to change notification settings - Fork 964
Closed
Description
First of all - it's an amazing set of best practices, I also want to share some things that I use:
Project Structure
src
could be added to PYTHONPATH
to avoid
prefixing every app import with src
, IDEs like PyCharm also support that.
Models also could be stored in same package, it's easier to import your models and make sure all modules were executed when you generate your migrations:
src/
db/
models/
__init__.py
comments.py
posts.py
tags.py
base.py
dependencies.py
# __init__.py
from . commends import Comment
from . posts import Post
from . tags import Tag
__all__ = ["Comment", "Post", "Tag"]
# Anywhere in the code
from db.models import Post
Continuous Integration
Absolutely use CI in gitlab/github to automate your tests and linters!
Dependency Management
Use poetry instead of requirements.txt, it's awesome!
Custom base model from day 0
This could also be used to enable orm_mode
and set up custom alias_generator
if client (for example a JS app) requires it.
Use Starlette's Config object Pydantic BaseSettings!
Pydantic has its own class to manage environment variables:
class AppSettings(BaseSettings):
class Config:
env_prefix = "app_"
domain: str
ccrvlh, xboolean, MappyLiam, h3ct0rjs, ShaikAli65 and 1 more
Metadata
Metadata
Assignees
Labels
No labels