This repository contains additional services required by the DataClouder template. For reference implementations, check out our other templates:
git clone https://github.com/dataclouder-dev/dataclouder-template-python [your-project-name]
or use the button on github right top corner CREATE TEMPLATE
- Python >= 3.11
- Make >= 3.0.0 (Optional but highly recommended)
- UV (latest version recommended, install via
pip install uv
orpipx install uv
) - Docker (Optional)
- Google Cloud credentials and environment variables
- MongoDB credentials
-
.env file is required, you need to create it but can copy and paste from .env.example, then set the variables
-
Google service account file is required and placed it in the
./.cred
folder at the project root
check documentation how to create service account here
You should be ready to go
Requires UV and Docker to be installed.
make install # Only the first time
# Single command setup (Work in Progress)
make start
# Create virtual environment
uv venv .venv # Or python3 -m venv .venv
# Activate virtual environment
# For Unix/MacOS:
source .venv/bin/activate
# For Windows:
.venv\Scripts\activate
# Install dependencies using UV (ensure uv.lock is up to date)
uv sync
- Google Cloud credential file (place in
/.cred
folder) - Environment variables template (
.env
file)
# Option 1: Using uvicorn (after activating venv)
uvicorn app.main:app --reload
# Option 2: Using FastAPI development server (after activating venv)
# fastapi dev app/main.py # If fastapi-cli is installed
# Option 3) Recommended (uses uv run)
make start
Once running, access the API documentation at: http://127.0.0.1:8000/docs
Environment | URL |
---|---|
QA | https://..... |
Production | https://..... |
-
Set environment variables:
- Ensure the
.env
file is present in the project root
- Ensure the
-
Build Docker image:
make docker-build
(Note:
make gcp-build
submits to Google Cloud Build,make docker-build
builds locally) -
Deploy to Google Cloud Run:
make gcp-deploy-service
(Note:
make gcp-deploy
includes the gcp-build step)
Change project name in Makefile
.
then just run
make deploy
Note: if you want to automate multiple environment remember that makefile just replace if the variables in the .env dont exist so adding this variables in .env will have priority. you can add per every environment
Note: Before setting up automated deployment, we recommend performing one manual deployment to verify everything works correctly. Initial deployments require setting up Cloud Run service variables, while subsequent deployments do not. Also note that manual deployments use the default GCR repository for artifacts, while automated deployments use a custom repository.
Steps:
- Fork the repository
- Go to Cloud Build and create a new trigger
- Grant GitHub access, select the repository, and accept conditions
- Configure trigger settings according to your needs
- Optional: Add permissions to the service account (Logs Writer, Cloud Run Admin, or default logs only)
- Add the repository in Artifact Registry (recommended: add policies to remove old versions)
UV is used for managing dependencies and virtual environments in this project. Key commands:
-
Create/Activate Virtual Environment & Install Dependencies:
# Create a virtual environment (if it doesn't exist) and install/sync dependencies make install # or manually: uv venv source .venv/bin/activate # On Unix/macOS # .venv\Scripts\activate # On Windows uv sync # Installs based on pyproject.toml and uv.lock
-
Adding a new package:
- Add the package to
[project.dependencies]
or[project.optional-dependencies]
in yourpyproject.toml
. - Then run:
uv sync uv lock # To update the lock file
Alternatively, for quick additions (which will also update
pyproject.toml
if it's a project):uv pip install <package-name> uv lock
- Add the package to
-
Removing a package:
- Remove the package from your
pyproject.toml
. - Then run:
uv sync uv lock
- Remove the package from your
-
Updating a package:
- Update the version constraint in your
pyproject.toml
. - Then run:
uv sync uv lock
Or, to update to the latest version and update
pyproject.toml
:uv pip install <package-name>@latest uv lock
- Update the version constraint in your
-
Listing installed packages:
uv pip list # or for a requirements.txt-like format: uv pip freeze
-
Generating/Updating the lock file:
uv lock
Building and publishing are handled by hatchling
as defined in pyproject.toml
and typically involve using tools like twine
for publishing to PyPI.
You can create new project but, if you want to get updates from the template, you can run
make merge-upstream
# Build the image
make docker-build
# or manually:
# docker build -t dc_python_server_image .
# (Ensure IMAGE_NAME in Makefile matches if using manual command)
# Run the container
make docker-run
# or manually:
# docker run -it -p 8000:8080 dc_python_server_image
We highly recommend using Ruff, a fast Python linter and formatter that replaces multiple tools like flake8. Settings are configured in the pyproject.toml
file.
Install the Ruff VSCode Extension
# These can be run directly if .venv is activated, or via 'uv run':
uv run ruff check . # Check for issues
uv run ruff check --fix . # Fix issues automatically
uv run ruff format . # Format code
uv run ruff check --fix --format . # Fix issues and format code
For more information about Ruff rules and configuration, visit the official documentation.