PHP to Python: Switching Backend Languages Mid-Career
Background
My first real backend was PHP. I learned it because it ran on cheap shared hosting, every tutorial used it, and CodeIgniter made MVC make sense to a self-taught developer.
By the time I needed a backend for an AI project, Python was the obvious choice — the AI ecosystem lives there. So I learned Flask. Here's what I found.
What's the Same
MVC is MVC. The pattern is the same: a router maps URLs to controllers, controllers call models, models talk to the database, and you return a response. Whether it's CodeIgniter or Flask, this mental model transfers completely.
REST is REST. GET, POST, PUT, DELETE. JSON request bodies, JSON responses, HTTP status codes. None of this is language-specific.
The debugging process is identical. Read the error, find the line, fix it. The error messages look different but the debugging loop is the same.
What's Different
Syntax
PHP requires $ prefixes, semicolons, and has verbose array syntax. Python is minimal by comparison:
// PHP / CodeIgniter
public function getRecipes() {
$recipes = $this->recipeModel->findAll();
return $this->response->setJSON(['data' => $recipes]);
}
# Python / Flask
@app.route('/api/recipes')
def get_recipes():
recipes = Recipe.find_all()
return jsonify({'data': recipes})
Python wins on readability every time.
The Ecosystem
CodeIgniter is batteries-included. ORM, validation, sessions, email — all built in. Flask is minimal by design. You bring your own ORM (SQLAlchemy), your own validation (marshmallow), your own JWT library.
This is a genuine trade-off. CodeIgniter gets you moving faster. Flask is more flexible but requires more setup.
AI Integration
This is where Python dominates. The official SDKs for OpenAI, Google Gemini, Anthropic, and Groq are all Python-first. You can do AI in PHP, but it's fighting the current.
import google.generativeai as genai
model = genai.GenerativeModel('gemini-1.5-flash')
response = model.generate_content(f"Generate a recipe for {dish_name}")
Three lines. That's why I use Python for AI work.
My Current Stack
- Portfolio API: CodeIgniter 4 on Hostinger (PHP is what the hosting supports)
- AI Projects: Flask on cloud hosting (Python for AI ecosystem access)
I don't think of them as competing. They're tools for different jobs. PHP is excellent for hosting-constrained environments with structured data. Python is essential for anything touching AI.
What I'd Tell Myself
Don't wait until you "know PHP well enough" to learn Python. The concepts transfer. The syntax difference is smaller than you think. And the Python ecosystem — especially for AI work — is worth the investment.
Start with Flask and build something real. You'll be productive within a week.
Tags
Jose Paulo Timbang
Full Stack Developer & AI Engineer
Self-taught developer from the Philippines. Building web applications and AI-powered tools. Learn more →