This repository is a define practices for AIT Brainlab to follow.
All python project should look like this and follow the standard.
- Project structure
- logging system
- command line (with
Typer) - basic web server and REST API (
with FastAPI and Jinja) - processor module with celery support (options for those who may not need
pub-sub/queue) - Define how Django should be implemented.
- Distribution standard (containerize for distribution)
- Chat/LLM standard (interface, prompt, mcp)
- tools/framework (some other github repo)
.
|-- .devcontainer/ # Where the development containers are defined
|-- .vscode/ # Where the vscode related configuration are kept
|-- data # ! Where data is kept. All the data are ignored by default.
| `-- example.csv
|-- docs/ # ! Where document (design, paper, any for reference) is kept.
|-- logs/ # Where logs are kept.
|-- models/ # ! Where models (weight) should be stored.
|-- notebooks/ # ! Where jupyter notebook should be stored.
| `-- 0-starter.ipynb
|-- src/ # ! Where development modules should be.
| |-- django_core # |
| | |-- __init__.py # |
| | |-- asgi.py # |
| | |-- settings.py # |
| | |-- urls.py # |
| | `-- wsgi.py # |
| |-- django_module # |
| | |-- __init__.py # |--- These are `Django` related structure
| | |-- admin.py # |
| | |-- apps.py # |
| | |-- migrations # |
| | | `-- __init__.py # |
| | |-- models.py # |
| | |-- tests.py # |
| | `-- views.py # |
|-- django_manage.py # |
| |-- project # Example modules with Brainlab practice.
| |-- __init__.py
| |-- cli.py
| |-- logger.py
| |-- processor
| | |-- __init__.py
| | |-- works.py
| | `-- works_test.py
| |-- processor_celery
| | |-- __init__.py
| | |-- cli.py
| | |-- works.py
| | `-- works_test.py
| `-- web
| |-- __init__.py
| |-- py.typed
| |-- router.py
| `-- templates
| |-- base.html
| |-- example.html
| `-- index.html
|-- .gitignore
|-- .python-version
|-- dev-setup.sh # ! run this one when you cloned
|-- LICENSE
|-- local.env.example # ! copy and create `local.env`
|-- pyproject.toml # python configuration. You have to change this.
|-- README.md
|-- supervisord.conf # ! if you want to run multiple processes at the same time, learn this one
`-- uv.lock
There are three main tools we use to manage the project.
uv: python project manager- devcontainer: where we spin development environment
mypy: a complier-ish that will check if your code meet certain standard
We intend that this repository will be used as a template for python development.
There are a lot of places where we have to add a python-project-start string to make this run properly.
You should change this name to follow your project/module name.
To change the name, you start from your project/repository name.
/some/path/to/your/repository/<project_name>Let's say we will create another project based on this template with name myproject
/some/path/path/to/your/repository/myprojectThe place where you need to change the name are
/.devcontainer/dev/.env: parameterPROJECT_NAMEpyproject.toml: parameterproject.namelocal.env.example: parameterPROJECT_NAME
This should be enough for you to start developing.
- (optional) spin up devcontainer in vscode (cmd/ctrl + shift + P and choose
Dev Containers: Rebuild and reopen in Container) - Set up the development environment in one go using
bash dev-setup.sh
The project has a command script.
By default it uses python-project-starter.
uv run python-project-starter --helpIf you want to change this command name, you have to configure the following
pyproject.toml: under sectionproject.scripts, change the command namesupervisord.conf: This use your command name to spawn processes
Command line solution uses Typer library which has completion capabitily.
After you write the command name, you can use tab to get suggestion/completion.
This functionality is automatically set for if you use .devcontainer.
For local user, you will need to run this manually (because I don't know if you want this install in your computer).
uv run <command_name> --install-completionTo remove this, get the intallation path from the command and delete the file manually.
Let's agree that we should develop a Django app module not an entire Django website.
In this AIT Brainlab best practice, the folders that are related to the Django are
...
|-- src/
| |-- django_core # |
| | |-- __init__.py # |
| | |-- asgi.py # |
| | |-- settings.py # |
| | |-- urls.py # |
| | `-- wsgi.py # |
| |-- django_module # |
| | |-- __init__.py # |--- These are `Django` related structure
| | |-- admin.py # |
| | |-- apps.py # |
| | |-- migrations # |
| | | `-- __init__.py # |
| | |-- models.py # |
| | |-- tests.py # |
| | `-- views.py # |
|-- django_manage.py # |
...The provided django_core is configuration for the development purposes.
The production may have different configuration.
Thus, your main development should be a modular module that is compatible with any django project.
To access typical django operation, you use
uv run django_manage.pyFor example, if you want to start the development server, you use
uv run django_manage.py runserver 0.0.0.0:8000Generate a django app boilerplate
# startapp <app_name> <app_folder>
uv run django_manage.py startapp myapp src/myappThen, add the module to the development project settings (/src/django_core/settings.py)
...
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp' # <---- Add here
]
...Finally, add the routing in /src/django_core/urls.py
...
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path("myapp/", include("myapp.urls")), #<---- Add here
]
...This project is licensed under the MIT License - see the LICENSE file for details.