Skip to main content

Command Palette

Search for a command to run...

#2 - Setting Up a Python API Testing Project with uv

Published
2 min read
S

• Possess over 14 years of experience in Quality Engineering, specializing in building test frameworks for complex systems including web applications, REST APIs, and core cloud infrastructure on platforms like Akamai's Linode and Azure.

• Skilled in the development and improvement of automation frameworks for various Web applications, service APIs displaying proficiency in TestNG, PyTest, Selenium, Rest Assured, Jenkins pipeline.

Understanding uv and its key advantages

What is uv?

  • uv is an extremely fast, modern Python package and project manager written in Rust, designed as an all-in-one replacement for existing tools like pip, virtualenv, pipx, and pyenv. uv promises dramatic performance gains and a simplified workflow for Python developers.

  • It consolidates multiple tools into a single, cohesive command-line interface. pip + venv + pip-tools + pipx — replaced by one fast tool

  • It fully supports pyproject.toml for defining project metadata and dependencies, aligning with modern Python packaging standards.

Advantage

  1. pyproject.toml as the source of truth

  2. A lockfile (uv.lock) for deterministic installs

  3. No need to “activate” venv

  4. Better dev vs prod dependency separation


Essential uv commands for project setup

Uv command and workflow

Setup uv and python

  • Install uv and update path

curl -Ls https://astral.sh/uv/install.sh | bash

  • Verify uv is installed

uv --version
uv 0.9.21

  • Install multiple python version

uv python install 3.14

  • List Python version → uv python list

    • Lists all Python interpreters uv can see (includes system-installed and uv-installed Python)

    • uv separates system Python from project Python, so OS updates can’t silently break your code or CI pipelines.

    • uv python list always shows system-installed Python if no Python is installed via uv, because uv discovers and reuses what the OS already provides.

    • Once you install Python via uv python install, uv prefers that version, but system Python remains visible as a fallback—not replaced.

  • Create a file with required python version

echo "3.13" > .python-version
cat .python-version >>  3.13

  • Initialize python project → uv init

  • Optional - Change project description in pyproject.toml


Creating an API testing project using uv

  • Setup python virtual environment → uv venv --python 3.13

  • Install packages

uv add requests faker
uv add --group test pytest
uv add --dev black ruff mypy

  • After running above command, it updated pyproject.toml with dependencies and created uv.lock

  • List dependency → uv pip list


Reference

API Testing | Pytest & requests

Part 2 of 5

A practical series on building a scalable, production-ready API testing framework using Python, requests and Pytest. Covers modern project setup, clean architecture, real-world API scenarios, and CI integration.

Up next

#3 - API Testing with requests

What Really Happens When You Call requests.get() API Testing using requests and pytest