|
2 | 2 |
|
3 | 3 | # Python Component for Diploi |
4 | 4 |
|
5 | | -Uses [uv](https://docs.astral.sh/uv/) to manage Python versions & packages. |
| 5 | +[](https://diploi.com/component/python) |
| 6 | +[](https://diploi.com/component/python) |
| 7 | +[](https://diploi.com/component/python) |
6 | 8 |
|
7 | 9 | ## Operation |
8 | 10 |
|
| 11 | +### Getting started |
| 12 | + |
| 13 | +1. In the Dashboard, click **Create Project +** |
| 14 | +2. Under **Pick Components**, choose **Python**. Here you can also add a frontend framework to create a monorepo app, eg, Python for backend and React+Vite for frontend |
| 15 | +3. In **Pick Add-ons**, you can add one or multiple databases to your app |
| 16 | +4. Choose **Create Repository** to generate a new GitHub repo |
| 17 | +5. Finally, click **Launch Stack** |
| 18 | + |
9 | 19 | ### Development |
10 | 20 |
|
11 | | -Will activate a virtual environment in `.venv` and run `uv sync` when component is first initialized, and `python src/main.py` when deployment is started. |
| 21 | +During development, the container installs Node.js and `nodemon` to enable automatic reloads when files change. The development server is started with: |
| 22 | + |
| 23 | +```sh |
| 24 | +nodemon --delay 1 --watch "pyproject.toml" --watch "requirements.txt" --watch ".venv/lib/*" --watch ".venv/lib64/*" --watch "src" --ext "py" --exec "sh -c 'if [ -f pyproject.toml ]; then uv run --isolated --with . src/main.py; elif [ -f requirements.txt ]; then uv run --isolated --with-requirements requirements.txt src/main.py; else uv run --isolated src/main.py; fi'" |
| 25 | +``` |
| 26 | + |
| 27 | +This will: |
| 28 | +- Use `nodemon` to watch for file changes and restart the server automatically. |
| 29 | +- Run `src/main.py` in an isolated Python environment managed by `uv`. |
| 30 | +- Automatically detect whether to use `pyproject.toml` or `requirements.txt` for dependency resolution. |
12 | 31 |
|
13 | 32 | ### Production |
14 | 33 |
|
15 | | -Will build a production ready image. Image runs `uv sync` when being created. Once the image runs, `python src/main.py` is called. |
| 34 | +Builds a production-ready image. During the build, dependencies are installed with `uv sync`. When the container starts, it runs: |
| 35 | + |
| 36 | +```sh |
| 37 | +uv run --frozen src/main.py |
| 38 | +``` |
| 39 | + |
| 40 | +This starts your Python application using the exact dependency versions locked in the project. |
| 41 | + |
| 42 | +## Links |
| 43 | + |
| 44 | +- [Python documentation](https://docs.python.org/) |
| 45 | +- [uv documentation](https://docs.astral.sh/uv/) |
0 commit comments