Skip to content
Aabha AI Academy

Module 1 of 9 · Lesson 2 of 26

Configure and run a reproducible API

Work through configure and run a reproducible API using a runnable reference, a focused regression check and a local extension.

Read in any order. All lessons stay open, including after an unanswered or incorrect check.

In this lesson you will configure and run a reproducible API. Work with the Equipment Rental API in the downloadable lab. The reference is a complete solution with separate lesson checks, so you can inspect the answer, make a deliberate local change and verify its behavior.
Reproducibility has three parts: the Python runtime, the resolved dependencies and explicit configuration. The lab uses Python 3.13 and requirements.lock, which pins the runtime and test packages together. Install them into a virtual environment so unrelated projects cannot change your results. Record your interpreter version along with the lock file; a list of package names alone cannot reproduce the environment.

Settings reads LAB_ environment variables. The database URL and token key are required for the integrated application, and a short key is rejected. They have no checked-in secret defaults. The hello application remains usable without a database or identity system. This separation lets you start with a tiny request while keeping the final application configuration deliberate. The local database test runner generates temporary credentials in memory, publishes the container only on loopback and removes it afterward. It never selects an existing database. A passing setup check proves the local contract, not readiness for an Internet deployment.
Worked source: equipment/settings.py, Settings.

Create .venv with python3.13 -m venv .venv; activate it and run python -m pip install -r requirements.lock. Run python --version and python run_checks.py -k lesson02. The check constructs settings with a valid synthetic key and rejects a short one. Full API startup also requires your own disposable LAB_DATABASE_URL and LAB_JWT_SECRET.
pythonCopyable
class Settings(BaseSettings):
    model_config = SettingsConfigDict(env_prefix="LAB_", extra="ignore")
    database_url: str
    jwt_secret: str = Field(min_length=32)
    api_title: str = "Equipment Rental learning API"
    provider_url: str = "http://127.0.0.1:8787"

    @property
    def sync_url(self):
        return sync_url(self.database_url)
TerminalPython 3.13 virtual environment; Docker running; extracted lab directory
python run_checks.py -k lesson02

Expected result The selected lesson test passes against a new temporary PostgreSQL database; the container is removed afterward.

Keep for reference

Equipment Rental lab and lesson checks

ZIP containing Python source, real Alembic migrations, 26 lesson checks, a dependency lock and text instructions. Extract it before following the local exercise.

Download Equipment Rental lab and lesson checks

Practise locally

Add a bounded integer LAB_PAGE_LIMIT setting with a default of 10 and a range of 1–100. Test its default, a valid override and rejection of 0. Do not add a token key or database password to source. Save the dependency lock and test output, and document the configuration names separately from their values.

The lesson check verifies the reference behavior. Add your own assertions for your change. Local practice is not uploaded or scored by this learning release.

Pause and reflect

What failure does this lesson prevent, and which assertion in lesson02 would expose it?

Use a concrete input, expected result and limitation from your local work. Saving a reflection does not certify the project.

Optional knowledge check

What belongs in the committed configuration guide?

A working database password so everyone can reuse it.

Try another answer. A shared password is persistent access; each local environment must supply its own configuration.

Only record package names; resolved versions do not matter.

Try another answer. Different resolved versions can change behavior; use the supplied lock and runtime.

Variable names and constraints, without secret values.

Correct. Names and validation rules make setup reproducible without disclosing credentials.

This practice does not assess your project or award a certificate.

Your reading progress

Progress is saved in this browser when storage is available.

Sign in to save across devices · Create an optional account