JV
PY

Java to Python

10 lessons

Progress0%
1Variables & Types2Classes & OOP3Collections4Exception Handling5File I/O6Functional Programming7Duck Typing and Protocols8Python Ecosystem9Type Hints and Static Analysis10Context Managers and Resources
All Mirror Courses
JV
PY
Python Ecosystem
MirrorLesson 8 of 10
Lesson 8

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.

Mirror Card
JV
From Java:

In Java, you're familiar with pip, virtualenv, pyproject.toml, pytest, popular libraries vs java ecosystem.

PY
In Python:

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:

PY
Python 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+fixer

Comparing to Java

Here's how you might have written similar code in Java:

JV
Java (What you know)
# 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 CI
Mirror Card
JV
From Java:

You may be used to different syntax or behavior.

PY
In Python:

Virtual environments (venv) isolate project dependencies — no Maven local repo

Mirror Card
JV
From Java:

You may be used to different syntax or behavior.

PY
In Python:

pip install + pyproject.toml = mvn install + pom.xml

Mirror Card
JV
From Java:

You may be used to different syntax or behavior.

PY
In Python:

pytest is simpler than JUnit — plain functions, no annotation boilerplate

Mirror Card
JV
From Java:

You may be used to different syntax or behavior.

PY
In Python:

mypy/pyright for static type checking (Java has it built-in)

Mirror Card
JV
From Java:

You may be used to different syntax or behavior.

PY
In Python:

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.

JV
Java
# Java: no isolation needed — Maven ~/.m2/repository
PY
Python
python -m venv venv      # create
source venv/bin/activate # activate (macOS/Linux)
pip install flask        # install into THIS venv only
deactivate               # leave venv

2. pyproject.toml

Modern Python projects use pyproject.toml — the standardized project metadata file. Replaces setup.py and requirements.txt.

JV
Java
<!-- pom.xml for Maven -->
<dependency><groupId>...</groupId></dependency>
PY
Python
# 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.

JV
Java
@Test
void testAdd() {
    assertEquals(3, add(1, 2));
}
PY
Python
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.

JV
Java
# Java: maven/gradle does everything
mvn compile test package
PY
Python
pip install -r requirements.txt  # install
pytest                          # test
mypy src/                       # type check
black . && ruff check --fix .   # format + lint
# Or: ruff format . (covers black)
Rule of Thumb
Use ruff (fast Rust-based linter/formatter) over black+flake8 for new projects — one tool instead of two.

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
Common Pitfall
Don't assume Python works exactly like Java. While the concepts may be similar, the syntax and behavior can differ significantly.

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)
Rule of Thumb
The best way to learn is by doing. Try rewriting some of your Java code in Python to practice these concepts.
PreviousNext