Skip to main content

Capistrano-inspired deployment automation for Django apps.

Project description

Pystrano

Capistrano-inspired deployment automation for Django apps.

Pystrano helps you define repeatable SSH-based Django deployment workflows with simple YAML playbooks.

Project Status

Pystrano is currently focused on Django deployment workflows. Django is the tested and documented path today.

FastAPI support is planned, but it should be treated as roadmap work until the implementation, tests, and documentation are released.

Other Python applications may be possible through custom commands, but they are not the primary supported workflow yet.

Why Pystrano?

Use Pystrano if:

  • you deploy Django apps to one or more servers over SSH
  • you want repeatable deployment workflows
  • you prefer simple YAML playbooks
  • you want release-oriented deploys and rollback-friendly structure
  • you are deploying to VPS-style servers with tools like Gunicorn and systemd

Pystrano may be adaptable to other Python applications through custom commands, but Django is the supported and documented workflow today.

Consider other tools if:

  • you need full infrastructure provisioning
  • you need container orchestration
  • you need complex multi-cloud workflows
  • you already have a mature CI/CD platform handling deployments
  • you need a fully managed deployment platform

Installation

Pystrano requires Python 3.12 or newer.

pip install pystrano

Quickstart

Pystrano reads a deployment config from this default path:

deploy/<app_name>/<environment_name>/deployment.yml

For an app named api and an environment named production, create:

deploy/api/production/deployment.yml

Then inspect the remote commands without executing them:

pystrano setup production api --dry-run
pystrano deploy production api --dry-run

Run the setup flow when the server is ready to be provisioned:

pystrano setup production api

Run the deployment flow:

pystrano deploy production api

Use a different config root or file name when needed:

pystrano deploy production api --deploy-config-dir ./ops/deploy --config-file-name pystrano.yml

Add --verbose to show more Fabric, Invoke, and Paramiko output.

Configuration

A deployment config contains a common section and a servers list. Values in common apply to every server. Values on an individual server override the common values for that server.

common:
  source_code_url: "git@github.com:example/example-django-app.git"
  project_root: "apps/example-django-app"
  project_user: "deploy"
  venv_dir: ".venv"
  keep_releases: 5
  system_packages: |
    libpq-dev
    python3-dev
  env_file: "./deploy/api/production/.env"
  ssh_known_hosts: "github.com"
  service_file: "./deploy/api/production/gunicorn.service"
  secrets: "./deploy/api/production/secret.json"
  branch: "main"
  clone_depth: 1

servers:
  - host: "app1.example.com"
    port: 22
    run_migrations: true
    collect_static_files: true

  - host: "app2.example.com"
    run_migrations: false
    collect_static_files: true

Common fields used by the current implementation:

  • source_code_url: Git repository URL cloned on each deploy.
  • project_root: Project directory under /home/<project_user>/.
  • project_user: Remote user that owns and deploys the app.
  • venv_dir: Virtualenv directory under /home/<project_user>/.
  • keep_releases: Number of release directories to keep. Use 0 or less to keep all.
  • system_packages: Extra packages installed during setup.
  • env_file: Local dotenv file copied to the remote shared directory during deploy.
  • ssh_known_hosts: Semicolon-separated hosts added with ssh-keyscan during setup.
  • service_file: Optional local systemd service file copied during setup.
  • secrets: Optional semicolon-separated local files copied during setup and linked into releases.
  • branch: Git branch cloned during deploy.
  • clone_depth: Shallow clone depth. Use 0 or less for a full clone.
  • revision: Optional tag, SHA, or ref checked out after cloning. When set, Pystrano performs a full clone.

Server fields:

  • host: SSH host.
  • port: SSH port. Defaults to 22.
  • run_migrations: Whether to run manage.py migrate during deploy.
  • collect_static_files: Whether to run manage.py collectstatic --noinput during deploy.

Deployment Workflow

pystrano setup <environment> <app> connects as root and prepares the remote host. The setup flow creates the project user, copies authorized SSH keys, creates the shared/releases/current directory structure, installs base packages, creates the virtualenv, updates known hosts, optionally installs a systemd service file, and optionally uploads secret files to the shared directory.

pystrano deploy <environment> <app> connects as project_user and creates a timestamped release under:

/home/<project_user>/<project_root>/releases/<timestamp>

The deploy flow clones the configured repository, copies the dotenv file into the shared directory, links shared assets, installs requirements.txt, links configured secrets, optionally runs Django static collection and migrations, updates the current symlink, optionally restarts the configured systemd service, and removes old releases according to keep_releases.

Pystrano does not currently expose a rollback CLI command. Deployments are release-oriented, so a maintainer can inspect previous release directories on the server and manually repoint the current symlink if needed. Keep keep_releases high enough for the rollback window you want.

Example: Django on a VPS

See examples/django-gunicorn-systemd for a starting point that combines Django, Gunicorn, systemd, SSH deployment, shared files, and release cleanup.

Maintainer Checklist

Recommended GitHub repository metadata:

  • Repository description: Capistrano-inspired deployment automation for Django apps.
  • Website: https://pystrano.com
  • Topics: python, django, deployment, deploy, cli, yaml, capistrano, devops, ssh, systemd, gunicorn, vps

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pystrano-1.2.2.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pystrano-1.2.2-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file pystrano-1.2.2.tar.gz.

File metadata

  • Download URL: pystrano-1.2.2.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pystrano-1.2.2.tar.gz
Algorithm Hash digest
SHA256 4239110719a392ba39215a65d0fec25a51d421a0720b933df612efbadddb0e6e
MD5 a08785a40c04b99d9d64f7538be504cc
BLAKE2b-256 8fe6edb323cf78e4b7c30f3309a0c0881dc8476730d1ac2b00171b6d4631a9d2

See more details on using hashes here.

File details

Details for the file pystrano-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: pystrano-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pystrano-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9b2872796de7e609f6ca0639f8765d106723aad29ac20f369aaaa173e233c6c7
MD5 04151bda5c6874bf9f8b966c8f672e75
BLAKE2b-256 86bd163716b1f622e2dfec8f6aa02519253f6c8fc7aff28ba497860c6a222a4d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page