Qo'llanma6 min read·22-aprel, 2026

How to Deploy a FastAPI App on if.uz — Python API Hosting in Uzbekistan

Deploy your FastAPI application to if.uz with automatic HTTPS and Postgres. Complete guide for Python developers in Uzbekistan.

FastAPI is the fastest-growing Python web framework, loved for its automatic OpenAPI docs, async support, and performance. Deploying it on if.uz takes about 3 minutes.

Project Structure

bash
my-fastapi-app/
├── main.py           ← entry point
├── requirements.txt
├── Procfile
└── ...

Step 1 — main.py

Make sure your FastAPI app is importable as main:app and reads the port from the environment:

python
from fastapi import FastAPI
import os

app = FastAPI(title="My API")

@app.get("/")
def root():
    return {"message": "Hello from if.uz!"}

@app.get("/health")
def health():
    return {"status": "ok"}

if __name__ == "__main__":
    import uvicorn
    port = int(os.environ.get("PORT", 8000))
    uvicorn.run("main:app", host="0.0.0.0", port=port)

Step 2 — requirements.txt

bash
fastapi>=0.110
uvicorn[standard]>=0.27
pydantic>=2.0
# Add your other dependencies below:
# sqlalchemy>=2.0
# asyncpg>=0.29
# python-jose[cryptography]>=3.3

Step 3 — Procfile

bash
web: uvicorn main:app --host 0.0.0.0 --port $PORT --workers 2

💡 Tip

For async FastAPI with SQLAlchemy/asyncpg, use 1 worker with multiple async handlers instead of multiple workers. Change "--workers 2" to "--workers 1" for async-heavy apps.

Step 4 — Deploy on if.uz

  1. 1Push to GitHub
  2. 2Connect repo in if.uz dashboard
  3. 3Click Deploy — Nixpacks finds requirements.txt, installs deps, runs the Procfile web command
  4. 4Your API is live at yourapi-username.if.uz with automatic HTTPS
  5. 5FastAPI docs available at yourapi-username.if.uz/docs

Step 5 — Async Database with SQLAlchemy + Postgres

Deploy a PostgreSQL instance from the Marketplace, then connect your FastAPI app:

python
import os
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker

# Convert postgresql:// → postgresql+asyncpg:// for async support
DATABASE_URL = os.environ.get("DATABASE_URL", "").replace(
    "postgresql://", "postgresql+asyncpg://"
)

engine = create_async_engine(DATABASE_URL, echo=False)
AsyncSessionLocal = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)

Environment Variables to Set

bash
DATABASE_URL=postgresql://postgres:[email protected]:5432/mydb
SECRET_KEY=your-jwt-secret-here
ENVIRONMENT=production

Testing Your Deployed API

Once deployed, visit https://yourapi-username.if.uz/docs — FastAPI's built-in Swagger UI works perfectly. Test all your endpoints directly from the browser.

bash
# Test from anywhere in the world:
curl https://yourapi-username.if.uz/health
# {"status":"ok"}

FastAPI + if.uz is an ideal stack for building REST APIs and microservices for the Uzbekistan market. The local hosting means your API responds in milliseconds to Uzbek frontend clients.

Deploy qilishga tayyormisiz?

Bepul plan, kredit karta kerak emas, 2 daqiqada jonli.

Bepul boshlash →