Tests on Python Code Examples.
A collection of small, self-contained Python scripts and proofs of concept: formatting and language
features, file and image utilities, SQLite/PostgreSQL persistence with Tkinter UIs, calls to public
Brazilian government APIs, JWT handling and more. Each example is a standalone module under
pythonruns/src/mytests/, runnable on its own with python -m.
- What's Inside
- Tech Stack
- Prerequisites
- Installation
- How to Run
- Running Tests
- Project Structure
- Latest Articles, Publications and Tech-Talks
- Author
- License
All examples live in pythonruns/src/mytests/.
- calculate_power.py: calculate a power x^y of a number.
- float_format.py: tests and prints multiple float formats.
- boolean_number.py: converting numbers to booleans.
- sort_list.py: sorting a list of numbers ascending and descending.
- switch_case.py:
match/casestatement driven by console input. - input_console.py: reading values from the console and combining
and/orconditions. - future/with_future.py and
future/without_future.py: effect of
from __future__ import annotationson__annotations__. - app_logging.py: the basics of logging in Python.
- happy_teacher_day.py: prints a heart in the console with the word Teachers, for happy teachers day.
- I_love_you.py: prints a heart in the console with a given 8-character word.
- camel_2_snake_case.py: converts a file text content from camel case to snake case.
- split_files.py: splits a text input file (like a log) into a given number of chunks.
- convert_pdf_to_docx.py: converts a pdf file to a docx file.
- fake_data.py: creates fake test data using Faker.
- short_uuid.py: generates short UUIDs and converts standard UUIDs with
shortuuid. - pickle/pickle_serialize_load.py: serializing and loading
objects with
pickle. - progress_bar.py: console progress bars with
progressandtqdm. - plot_graph.py: sin/cos/tan subplots with Matplotlib and NumPy.
- remove_background.py: removes background from images, letting only the main subject.
- resize_images.py and compress_images.py: resize/compress image files down to a target size in KB.
- qrcode/generate_qrcode.py: creates a QR-Code from your data.
- qrcode/generate_qrcode_with_midle_empty.py: QR code with a transparent hole in the center for a logo.
- database/save_to_mem_db.py, persist_json_in_memory.py, persist_json_to_db.py, persist_json_to_db_visualize.py, persist_json_disk_to_db_visualize.py: storing and viewing JSON data in memory or an in-memory SQLite database through a Tkinter window.
- database/persist_with_postgres.py: the same idea backed
by PostgreSQL via
psycopg2(requires a running PostgreSQL instance).
- jusbr/call_api_fines_ibama_brazil.py: Environmental fines research in Brazil's government site.
- jusbr/call_api_tjmg.py, call_api_trf_proc.py, call_api_trf_classe_orgao.py: queries against the CNJ DataJud public API (by process number, or by class/court body).
- jwt_test.py:
JWTManagerclass to create and decode JWT tokens withpython-jose. - backup_restore_wordpress.py: backup/restore of a WordPress
site (database and files) between a local machine and a remote server over SSH/SFTP with
paramiko.
- tests/mytests/test_jwt_manager.py: pytest suite for
JWTManager(token creation, decoding, expiry, invalid signatures, multiple HMAC algorithms). - tests/test_examples.py:
unittestcheck of OS path separators.
The scripts/ folder holds standalone shell/Python utilities (server install, disk cleanup, git helpers,
app monitoring) that are not part of the package.
- Python 3.11 / 3.12 (
requires-python = ">=3.11,<3.13"), managed with uv - pytest, pytest-cov, pytest-html
- Main libraries used by the examples: Faker, python-jose, pdf2docx, Pillow, rembg, OpenCV, qrcode, Matplotlib, NumPy, pandas, requests, paramiko, psycopg2, shortuuid, tqdm, progress
- Code quality: ruff, black, isort, mypy, pre-commit
- CI: GitHub Actions (ci.yml) running tests on Python 3.11 and 3.12
- Python 3.11 or 3.12
- uv
- Tkinter (bundled with most Python installs) for the
database/examples - A PostgreSQL instance only for
persist_with_postgres.py
This project uses uv for fast and reliable Python package management.
If you don't have uv installed yet:
# On macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# Or with pip
pip install uvCreate and activate a virtual environment, then install dependencies:
# Create a virtual environment and install dependencies (one step)
uv sync
# Or manually:
# 1. Create a virtual environment
uv venv
# 2. Activate it
# On Linux/macOS:
source .venv/bin/activate
# On Windows:
# .venv\Scripts\activate
# 3. Sync all dependencies
uv syncAlternatively, you can use the provided makefile:
make installCommon uv commands:
# Sync dependencies from uv.lock (recommended for consistent environments)
uv sync
# Sync with all dependency groups (including dev)
uv sync --all-groups
# Update dependencies and regenerate lockfile
uv lock --upgrade
uv sync
# Add a new dependency
# (Edit pyproject.toml, then run:)
uv lock
uv sync
# Run a command in the virtual environment
uv run python -m pythonruns
uv run pytest
# Use pip if needed for one-off packages (not recommended for project deps)
uv pip install package-nameRun any example as a module from the repository root:
uv run python -m pythonruns.src.mytests.fake_data
uv run python -m pythonruns.src.mytests.jwt_test
uv run python -m pythonruns.src.mytests.split_files /path/to/app.log 5The general form is:
python3 -m pythonruns.src.mytests.file_to_runSome examples read from resources/ and write to output/ using relative paths
(../resources, ../output), so check the paths at the top of a script before running it.
# Run all tests (same command as CI)
uv run pytest tests/ -v
# With coverage (HTML report in ./htmlcov)
uv run pytest tests/ --cov=pythonruns --cov-report=html
# Or via the makefile (requires the virtual environment to be activated)
make testOther makefile targets: make help lists them all (install, sync, update, pre-commit, build, clean, ...).
PythonRuns/
├── pythonruns/
│ ├── hello_world.py
│ └── src/mytests/ # example modules (database/, future/, jusbr/, pickle/, qrcode/, ...)
├── tests/ # pytest / unittest tests
├── resources/ # sample inputs (images, sample.pdf)
├── output/ # generated outputs (images, CSV, docx)
├── scripts/ # standalone shell/Python utilities
├── docs/ # uv migration notes and quick reference
├── pyproject.toml # project metadata and dependencies
├── uv.lock
└── makefile
- [Code & Coffee - Substack] Java turns 30: An Innovation Journey Through Time and Technology - What 30 years of Java can teach us about building tech that lasts. A timeline on what happened to Java from May 23rd 1995, when Sun Microsystems introduced Java 1.0 to the world, until modern days that made Java essentially great.
- [Dev Community] FastAPI Unleashed: Building Modern and High-Performance APIs - Demostranting FastAPI, a web framework designed for building APIs quickly and efficiently. Python based natively async, it takes advantage of non-blocking I/O to handle high loads, with extra features such as embedded data validation with Pydantic and auto-documentation with Swagger/Redoc.
- [Dev Community] NoSQL Fighters Arena: The Battle of Data Titans - Explore NoSQL databases reimagined as superheroes, each with unique powers and weaknesses, in a fun and visual battle-style format.
- [LinkedIn Pulse] Java is turning 30 soon! Here's Why You Should Care, Even if You're Not a Tech Person - Java is a super famous programming language, and it is almost turning 30. But wait, what exactly is Java, and why should it matter to you?
- [DZone] Top NoSQL Databases and When to Use Each - A practical guide comparing NoSQL technologies like MongoDB, Cassandra, Redis, and more, highlighting their strengths, limitations, and best use cases.
- [Dev Community] Test Python Code Like a Pro with Poetry, Tox, Nox and CI/CD - Improving your test coverage with multiple python versions through the use of of tools like Poetry, Pytest, Tox, Nox and CI/CD.
- [Dev Community] Python Multithreading: Unlocking Concurrency for Better Performance - The essentials of Python multithreading with practical examples and best practices to enhance application performance through concurrency. A must-read, to understand threading application performance in deep.
- [DZone] Secure Password Hashing in Java: Best Practices and Code Examples - Secure password hashing using modern algorithms like BCrypt, Argon2, and PBKDF2 with salting and computational intensity for better security, as alternative to SHA-512.
- More available on my LinkedIn page.
- Wallace Espindola, Sr. Software Engineer / Solution Architect / Java & Python Dev
- LinkedIn: linkedin.com/in/wallaceespindola/
- GitHub: github.com/wallaceespindola
- E-mail: wallace.espindola@gmail.com
- Twitter: @wsespindola
- Gravatar: gravatar.com/wallacese
- Dev Community: dev.to/wallaceespindola
- DZone Articles: DZone Profile
- Pulse Linkedin: LinkedIn Articles
- Website: W-Tech IT Solutions
- Substack: wallaceespindola.substack.com
- Medium: medium.com/@wallaceespindola
- Slides: speakerdeck.com/wallacese
- This project is released under the Apache 2.0 License.
- See the LICENSE file for details.
- Copyright © 2025 Wallace Espindola.