Deploy Django or FastAPI in India with Plexivo Postgres

Deploy Django in India, or FastAPI: push from Git to Plexivo App Runner in Mumbai, connect Plexivo Postgres over TLS, run migrations and read your logs.

7 min read

Deploy Django or FastAPI in India with Plexivo Postgres

Python is how a great deal of India's software gets built: Django for products with an admin and a data model, FastAPI for APIs that need to be quick and typed. Both deserve a home close to their users, with a real PostgreSQL database and nothing to babysit.

This guide takes a Django or FastAPI app from a Git repository to a running HTTPS address on Plexivo App Runner in Mumbai, connected to Plexivo Postgres over verified TLS. Every console label and setting below comes from the Plexivo docs.

What do you need before you deploy Django in India?

  • Your code on GitHub, GitLab or Bitbucket, with a requirements.txt (or a Dockerfile).
  • A Plexivo account and a project. The Developer plan has a free trial, no credit card required.
  • A Python version pinned in your Dockerfile or project settings.

Plexivo App Runner builds Python, Django and FastAPI apps. If your repository has a Dockerfile at its root, Plexivo builds it as it is, which gives you full control. Without one, Plexivo detects your language and framework, installs your dependencies and sets the start command. The examples below use a Dockerfile, because the start command is the part Python apps most often need to state precisely.

Why must the app listen on PORT and 0.0.0.0?

Plexivo sets the PORT environment variable and sends traffic to it. Unless your image declares another port with EXPOSE, it is 8080. Your server must read PORT and bind to 0.0.0.0, not 127.0.0.1, or the platform cannot reach it.

For Django with Gunicorn:

dockerfile
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD gunicorn mysite.wsgi --bind 0.0.0.0:${PORT:-8080} --workers 2 --access-logfile -

For FastAPI with Uvicorn:

dockerfile
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD uvicorn main:app --host 0.0.0.0 --port ${PORT:-8080}

Add a .dockerignore that leaves out virtual environments, test data and build output. Smaller builds finish sooner and use fewer build minutes. See how builds work.

How do you deploy a Django or FastAPI app from Git, step by step?

  1. Start a new app. In the console, choose Create, then Plexivo App Runner.
  2. Connect Git. Under Source, pick GitHub, GitLab or Bitbucket and choose Connect GitHub (or GitLab, or Bitbucket). For GitHub you install the Plexivo GitHub App and choose which repositories it may read.
  3. Pick the code. Choose the Repository and the Branch.
  4. Name the app. The name becomes its address, <name>.plexivo.app, in lowercase letters, digits and dashes.
  5. Choose a size. Pick a size and the Minimum instances and Maximum instances.
  6. Deploy. Check the Estimated monthly cost, then choose Deploy (the button carries the app's name, as in Deploy web). Follow the build on the app's Deployments tab.

From then on, every push to that branch builds and deploys. The current release keeps serving until the new one is ready, and a release that never becomes healthy is rolled back automatically. In India, the PAN is checked once, when you first approve a deployment.

How do you connect Django to Plexivo Postgres over TLS?

Create a Plexivo Postgres database in the same project, choosing PostgreSQL 18 (recommended) or 17. Then open your app's Environment tab and, in Add a database or cache, choose the database as the Resource and Connect. Plexivo delivers two variables and restarts the app once they are ready:

  • DATABASE_URL: the connection string, with sslmode=verify-full.
  • DATABASE_CA_CERT: the database's own CA certificate.

Plexivo Postgres refuses any connection without TLS, and verify-full with the CA checks both the certificate and the host name. Python drivers want the CA as a file, so write it out once at start-up. In Django's settings.py:

python
import os
from pathlib import Path
import dj_database_url

if "DATABASE_URL" in os.environ:
    DATABASES = {"default": dj_database_url.parse(os.environ["DATABASE_URL"], conn_max_age=60)}
    if os.environ.get("DATABASE_CA_CERT"):
        ca = Path("/tmp/plexivo-postgres-ca.pem")
        ca.write_text(os.environ["DATABASE_CA_CERT"])
        DATABASES["default"].setdefault("OPTIONS", {}).update(
            {"sslmode": "verify-full", "sslrootcert": str(ca)}
        )

ALLOWED_HOSTS = ["web.plexivo.app", "app.example.com"]
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]

For FastAPI with SQLAlchemy:

python
import os
from pathlib import Path
from sqlalchemy import create_engine

ca = Path("/tmp/plexivo-postgres-ca.pem")
ca.write_text(os.environ["DATABASE_CA_CERT"])
url = os.environ["DATABASE_URL"].replace("postgresql://", "postgresql+psycopg://", 1)
engine = create_engine(url, pool_size=5, pool_pre_ping=True,
                       connect_args={"sslmode": "verify-full", "sslrootcert": str(ca)})

When the database password rotates, the variables follow, so you never copy a password by hand. Never turn off TLS verification. The connection docs show every variable, including DATABASE_POOLER_URL and DATABASE_READ_URL.

Where should Django settings and secrets live?

On the app's Environment tab, choose + Add variable, enter the Key and Value, then apply. Plexivo restarts instances onto the new values one at a time, and each old instance keeps serving until its replacement is ready. Values are encrypted at rest, and keys that look like secrets stay masked until you choose Show.

For values you share across apps, such as DJANGO_SECRET_KEY or a payment key, use Plexivo Secrets. Open Secrets in the sidebar, choose New secret, then Store secret. On the app's Environment tab, choose Attach a secret…. Rotate it once and every attached app restarts onto the new version. See Plexivo Secrets.

Plexivo also sets TZ to your organisation's time zone, India Standard Time for India. Keep Django's USE_TZ = True so the database stores timestamps consistently.

How do you run Django migrations on Plexivo?

There are two good patterns.

From your laptop, through the Plexivo CLI tunnel. This keeps schema changes deliberate:

bash
plexivo auth login
plexivo db connect orders-db

Keep it running, and in a second terminal use the port it printed:

bash
DATABASE_URL="postgresql://app:PASSWORD@127.0.0.1:5432/app?sslmode=require" python manage.py migrate

The tunnel is encrypted and works even when the database is private. For FastAPI with Alembic, run alembic upgrade head the same way. See the Plexivo CLI.

At start-up. Prefix the start command with python manage.py migrate --noinput &&. This suits a single instance. A new instance has up to 5 minutes to pass its first health check, so keep long migrations for the tunnel.

How do you add a health check?

Add a fast endpoint that answers 200 without a sign-in, such as /healthz. On the app's Settings tab, in Health check, enter the path and choose Apply changes. The path must answer with a 2xx or 3xx status within 2 seconds; an instance that fails for 6 seconds stops receiving traffic until it answers again. If Django answers the check with 400, look at ALLOWED_HOSTS first. The health checks docs have the full timing.

Which size should you choose, and how does autoscaling work?

Start small and resize with real numbers. A Plexivo App Runner nano instance is 0.125 vCPU and 256 MB for US$6.04 a month; a micro is 0.25 vCPU and 512 MB for US$11.08, a comfortable start for Gunicorn with two workers. The smallest Plexivo Postgres is 0.25 vCPU, 512 MB and 10 GB for US$11.98 a month, with 50 connections for your app, so keep workers multiplied by instances below that. Every size is on the pricing page.

On the Scaling tab, Instances is how many always run and Autoscale up to is the most Plexivo may run. Plexivo adds an instance when average CPU passes 70% of each instance's vCPU. By default an app may autoscale to 4 instances on Startup and 10 on Business. On Developer, an idle app sleeps after 15 minutes without requests and wakes on the next one. On Business and Enterprise, clients connect through a built-in PgBouncer pooler in transaction mode; for Django, set DISABLE_SERVER_SIDE_CURSORS = True in the database settings.

Where do you see your app's logs?

Write logs to standard output, which is why the Gunicorn command above includes --access-logfile -. The app's Logs tab shows up to 100 lines from the last 15 minutes across current instances, and the Deployments tab shows each build's reason and output. The Metrics tab charts requests per second, latency p99, CPU and memory. For stored events, deploy steps and builds on one page, read the Logs Explorer guide.

FAQ

Do I need a Dockerfile to deploy Django on Plexivo?

No. Without a Dockerfile, Plexivo detects Python and your framework, installs dependencies and sets the start command. A Dockerfile is useful when you want to state the Gunicorn or Uvicorn command exactly.

Why does my app deploy but never become ready?

Usually it is listening on the wrong address. Read PORT, bind to 0.0.0.0, and check that your health check path answers with 2xx or 3xx. The Logs tab shows what the app printed as it started.

Is the connection to Plexivo Postgres encrypted?

Yes. Plexivo Postgres refuses connections without TLS, and each database has its own certificate authority. Use sslmode=verify-full with the CA from DATABASE_CA_CERT.

Can FastAPI use async drivers?

Yes. Any PostgreSQL driver works, including asyncpg, as long as it verifies TLS with the database's CA certificate. Size its pool below your database's connection limit.

Can I pay for hosting in rupees?

Yes. Prices are in US dollars, and customers in India pay in rupees by UPI, card or net banking at the month's rate, plus GST, with a GST tax invoice in rupees.

Ship your Python app

Push your Django or FastAPI repository and watch it build in Mumbai, with the price shown before you approve. Open the Plexivo console to start a free trial on the Developer plan, no credit card required.