Skip to content

This repository contains a collection of Python learning exercises grouped by topic. Each folder is a small, self-contained set of exercises that focus on a single concept (type annotations, async programming, async comprehensions, testing, etc.). These exercises are intended for practice and learning, and most files can be executed directly

Notifications You must be signed in to change notification settings

ggbaguidi/alx-backend-python

Repository files navigation

ALX BACKEND (Python exercises)

This repository contains a collection of Python learning exercises grouped by topic. Each folder is a small, self-contained set of exercises that focus on a single concept (type annotations, async programming, async comprehensions, testing, etc.). These exercises are intended for practice and learning, and most files can be executed directly with the Python interpreter.

This README provides a quick overview of the project structure, setup steps for a Linux (zsh) environment, and commands to run the examples and tests.

Table of contents

  • Project layout
  • Prerequisites
  • Setup (venv & dependencies)
  • How to run examples
  • Running tests
  • Notes and tips

Project layout

  • 0x00-python_variable_annotations/ — Small functions and scripts that exercise Python type annotations, typed function signatures, and static typing patterns (e.g., add, concat, type_checking).
  • 0x01-python_async_function/ — Examples that show basic async function syntax, running concurrent coroutines, measuring runtime and creating tasks.
  • 0x02-python_async_comprehension/ — Exercises covering async generators and async comprehensions with simple measurement utilities.
  • 0x03-Unittests_and_integration_tests/ — Example unittest-based client code, fixtures and tests demonstrating unit and integration testing patterns. Contains test_client.py, test_utils.py and supporting modules.

Prerequisites

  • Python 3.8+ (3.10/3.11 recommended)
  • pip
  • Optional: virtualenv or use python3 -m venv

Setup (Linux / zsh)

Open a terminal and run:

# create and activate a virtual environment in the project root
python3 -m venv .venv
source .venv/bin/activate

# upgrade pip
pip install --upgrade pip

Dependencies

Most exercises are self-contained and don't require third-party packages. For testing and convenience you may want to install pytest or other test tools, but the provided tests use Python's standard unittest module and will run without extra dependencies.

Optional (recommended for richer test output):

pip install pytest pytest-cov

How to run examples

Each exercise file is a small script or module. You can run them directly with the interpreter. From the repository root:

# run a simple example from the variable annotations exercises
python3 0x00-python_variable_annotations/0-add.py

# run an async example (these are simple scripts demonstrating usage patterns)
python3 0x01-python_async_function/0-basic_async_syntax.py

# run an async comprehension example
python3 0x02-python_async_comprehension/1-async_comprehension.py

Running tests (unittest)

The 0x03-Unittests_and_integration_tests/ folder contains unittest-based tests. Run them with Python's test discovery or with pytest if installed.

Using Python's unittest discovery:

# from repository root
python3 -m unittest discover -v 0x03-Unittests_and_integration_tests

Using pytest (if installed):

pytest -q 0x03-Unittests_and_integration_tests

Folder notes and highlights

  • 0x00-python_variable_annotations/ — Good place to practice adding static types and learning how to write function signatures that help static type checkers (e.g., mypy). Files such as 100-safe_first_element.py and 101-safely_get_value.py illustrate safe handling of values and typing for optional results.
  • 0x01-python_async_function/ — Shows coroutine creation, awaiting, running multiple coroutines concurrently and measuring runtime. Useful for learning asyncio basics.
  • 0x02-python_async_comprehension/ — Demonstrates how to use async generators and comprehensions to process asynchronous streams of data.
  • 0x03-Unittests_and_integration_tests/ — Example fixtures and tests that demonstrate how to structure unit and integration tests. The client.py and utils.py modules are the code under test; test_client.py and test_utils.py are test modules.

Tips and recommended next steps

  • If you want static type checking, install mypy and run it against the 0x00-... folder:
pip install mypy
mypy 0x00-python_variable_annotations
  • To experiment with asynchronous code, open the examples and add print() statements or small modifications — run them interactively in the venv.
  • Consider adding a requirements.txt if you adopt third-party packages for testing or linting.

Contributing

If you want to add exercises or improve documentation, fork the repository and open a pull request with your changes.

👥 Authors

alx-backend-python

Using Python3 to develop a app backend ALX Software Engineering

About

This repository contains a collection of Python learning exercises grouped by topic. Each folder is a small, self-contained set of exercises that focus on a single concept (type annotations, async programming, async comprehensions, testing, etc.). These exercises are intended for practice and learning, and most files can be executed directly

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages