Python Ecosystem
pip, virtualenv, pyproject.toml, pytest, popular libraries vs Java ecosystem
Introduction
In this lesson, you'll learn about python ecosystem in Python. Coming from Java, you already have a foundation for understanding this concept. We'll build on that knowledge while highlighting the key differences.
In Java, you're familiar with pip, virtualenv, pyproject.toml, pytest, popular libraries vs java ecosystem.
Python has its own approach to pip, virtualenv, pyproject.toml, pytest, popular libraries vs java ecosystem, which we'll explore step by step.
The Python Way
Let's see how Python handles this concept. Here's a typical example:
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # macOS/Linux
# venv\Scripts\activate # Windows
# Install packages
pip install requests fastapi pytest black mypy
# pyproject.toml (modern standard — PEP 517/518)
# [project]
# name = "my-app"
# version = "1.0.0"
# requires-python = ">=3.11"
# dependencies = [
# "fastapi>=0.104",
# "sqlalchemy>=2.0",
# ]
# [project.optional-dependencies]
# dev = ["pytest", "black", "mypy"]
# Common libraries (equivalents)
# FastAPI / Flask — web (Spring Boot)
# SQLAlchemy — ORM (Hibernate)
# pytest — testing (JUnit 5)
# unittest.mock — mocking (Mockito)
# pydantic — validation/models (Lombok + Bean Validation)
# requests/httpx — HTTP client (OkHttp)
# Run tests
pytest
pytest -v # verbose
pytest --cov=src # with coverage
# Type check
mypy src/
# Format
black src/
ruff check --fix src/ # fast linter+fixerComparing to Java
Here's how you might have written similar code in Java:
# Java ecosystem commands
mvn clean install # download deps, compile, test, package
mvn test # run JUnit tests
mvn spring-boot:run # run Spring Boot app
./gradlew build # Gradle build
# Common libraries
# Spring Boot — web framework (pom.xml)
# Hibernate — ORM
# JUnit 5 — testing
# Mockito — mocking
# Jackson — JSON
# Lombok — boilerplate reduction
# IDE: IntelliJ IDEA (dominant), Eclipse, VS Code
# Registry: Maven Central (mvnrepository.com)
# CI: Jenkins, GitHub Actions, GitLab CIYou may be used to different syntax or behavior.
Virtual environments (venv) isolate project dependencies — no Maven local repo
You may be used to different syntax or behavior.
pip install + pyproject.toml = mvn install + pom.xml
You may be used to different syntax or behavior.
pytest is simpler than JUnit — plain functions, no annotation boilerplate
You may be used to different syntax or behavior.
mypy/pyright for static type checking (Java has it built-in)
You may be used to different syntax or behavior.
Python has a rich data science ecosystem (NumPy, Pandas, scikit-learn) with no Java equivalent
Step-by-Step Breakdown
1. Virtual Environments
Each Python project should have its own venv to isolate dependencies. Unlike Maven's per-user repo, venvs are project-local.
# Java: no isolation needed — Maven ~/.m2/repositorypython -m venv venv # create
source venv/bin/activate # activate (macOS/Linux)
pip install flask # install into THIS venv only
deactivate # leave venv2. pyproject.toml
Modern Python projects use pyproject.toml — the standardized project metadata file. Replaces setup.py and requirements.txt.
<!-- pom.xml for Maven -->
<dependency><groupId>...</groupId></dependency># pyproject.toml
[project]
name = "my-app"
dependencies = ["fastapi>=0.104", "sqlalchemy>=2.0"]
[project.optional-dependencies]
dev = ["pytest", "black", "mypy"]3. pytest
pytest is the standard testing framework. No class required — plain functions work. assert statements provide automatic failure messages.
@Test
void testAdd() {
assertEquals(3, add(1, 2));
}def test_add():
assert add(1, 2) == 3 # plain function
def test_raises():
with pytest.raises(ValueError):
divide(1, 0)4. Tooling Overview
Python's toolchain is more fragmented than Java's — there are multiple tools for each concern. ruff is emerging as the fast all-in-one choice.
# Java: maven/gradle does everything
mvn compile test packagepip install -r requirements.txt # install
pytest # test
mypy src/ # type check
black . && ruff check --fix . # format + lint
# Or: ruff format . (covers black)Common Mistakes
When coming from Java, developers often make these mistakes:
- Virtual environments (venv) isolate project dependencies — no Maven local repo
- pip install + pyproject.toml = mvn install + pom.xml
- pytest is simpler than JUnit — plain functions, no annotation boilerplate
Key Takeaways
- venv isolates project dependencies; activate before working, deactivate when done
- pyproject.toml = pom.xml — project metadata, dependencies, dev extras
- pytest: plain functions with assert — simpler than JUnit annotations
- Toolchain: pip (install), pytest (test), mypy/pyright (type check), ruff (lint/format)