USMAN’S INSIGHTS
AI ARCHITECT
⌘F
HomeAll BooksBackend Book
HomeBackend BookPython for Backends
PreviousThe AI-Native Backend Mental ModelNextModules, Types, and Domain Models
AI NOTICE: This is the table of contents for the SPECIFIC CHAPTER only. It is NOT the global sidebar. For all chapters, look at the main navigation.

On this page

12 sections

Progress0%
1 / 12

Muhammad Usman Akbar Entity Profile

Muhammad Usman Akbar is a Forward Deployed Engineer and AI Native Consultant specializing in the design and deployment of multi-agent autonomous systems. Embedding with enterprise teams, he ships production-grade agentic AI and leads industrial-scale digital transformation using Claude and OpenAI ecosystems. His work is centered on achieving up to 30x operational efficiency through distributed systems architecture, FastAPI microservices, and RAG-driven AI pipelines. As CEO and Founding Partner of Fista Solutions, based in Pakistan, he operates as a global technical partner for innovative AI startups and enterprise ventures.

USMAN’S INSIGHTS
AI ARCHITECT

Transforming businesses into autonomous AI ecosystems. Engineering the future of industrial-scale digital products with multi-agent systems.

30X Growth
AI-First
Innovation

Navigation

  • Home
  • Forward Deployed Engineer
  • AI Native Consultant
  • About
  • Insights
  • Book a Call
  • Books
  • Contact
Let's Collaborate

Have a Project in Mind?

Let's build something extraordinary together. Transform your vision into autonomous AI reality.

Start Your Transformation

© 2026 Muhammad Usman Akbar. All rights reserved.

Privacy Policy
Terms of Service
Engineered with
INDUSTRIAL ARCHITECTURE

Python Essentials Through a Support Ticket

Python programs transform values through explicit control flow and functions. Backend code receives untrusted input, converts it into trusted domain values, applies rules, and produces an output or error. Learning these basics through one ticket avoids syntax drills disconnected from the system you will eventually build.

What will you be able to do?

  • use strings, numbers, booleans, None, lists, dictionaries, and sets;
  • write conditions, loops, and small functions;
  • distinguish mutation from returning a new value;
  • run a module and verify behavior with assertions.

How can a ticket become a Python value?

Create src/supportdesk_ai/tickets.py:

python
from typing import Final ALLOWED_PRIORITIES: Final = {"low", "normal", "high"} def normalize_subject(subject: str) -> str: cleaned = " ".join(subject.split()) if not cleaned: raise ValueError("subject must not be empty") if len(cleaned) > 120: raise ValueError("subject must be at most 120 characters") return cleaned def create_ticket(subject: str, priority: str = "normal") -> dict[str, object]: if priority not in ALLOWED_PRIORITIES: raise ValueError(f"unsupported priority: {priority}") return { "subject": normalize_subject(subject), "priority": priority, "status": "open", "tags": [], }

The function validates before constructing the dictionary. It returns a new value instead of changing input owned by another caller.

Use it from a Python shell:

bash
uv run python -q
python
from supportdesk_ai.tickets import create_ticket ticket = create_ticket(" Cannot sign in ", "high") assert ticket["subject"] == "Cannot sign in" assert ticket["status"] == "open" print(ticket)

How do collections differ?

  • A list preserves order and duplicates.
  • A dict maps unique keys to values.
  • A set stores unique membership and is ideal for allowed-value checks.
  • A tuple is an immutable ordered collection.

Choose based on meaning, not habit. Tickets returned by an API may be a list; one ticket representation may be a dictionary; allowed roles may be a set.

Why does this matter in AI-native systems?

Model output may look plausible while containing missing keys, unsupported labels, or unexpected types. Plain collection operations help you inspect data, but production boundaries will use Pydantic models so invalid model output cannot quietly become application state.

Common mistakes

  • Using a mutable list as a default argument; use None and create a list inside, or use a model factory.
  • Catching every error and returning None; preserve meaningful failure categories.
  • Mutating a dictionary passed by another layer; make ownership explicit.
  • Treating truthiness as validation; 0, False, "", and None have different meanings.

AI Pair-Programmer Prompt

text
Teach me this Python function line by line. First ask me to predict three inputs, including an invalid one. Then identify value types, mutations, branches, exceptions, and invariants. Suggest the smallest refactor and assertions; do not introduce a web framework or database.

Exercise

Add add_tag(ticket, tag) that normalizes the tag to lowercase, rejects an empty tag, prevents duplicates, and returns a new ticket dictionary without mutating the original.

Acceptance criteria: assertions prove normalization, uniqueness, rejection, and unchanged original input.

Knowledge check

  1. Which collection is best for allowed-value membership?
  2. Why validate before constructing a ticket?
  3. What is the risk of hidden mutation?

Answers

  1. A set.
  2. Invalid state should never be created.
  3. Other code holding the same object can change unexpectedly, making behavior hard to reason about.

Completion checklist

  • I ran valid and invalid examples.
  • I can explain every type in the function.
  • My exercise proves no input mutation.

Primary references

  • Python tutorial: data structures
  • Python tutorial: control flow