Diving deep into my learning archive, I discovered a treasure trove of Python
development tools and resources that every serious Python developer should know
about. These discoveries span from code quality enforcement to CPython internals
understanding.
The Python Code Quality Authority is an organization
that maintains several essential Python code quality tools:
PyCQA Tools Ecosystem
- pylint - Comprehensive static analysis
- flake8 - Style guide enforcement
- mccabe - Cyclomatic complexity analysis
- prospector - Meta-tool combining multiple analyzers
- bandit - Security-focused static analysis
McCabe Complexity Analysis
Cyclomatic Complexity,
also known as McCabe Complexity, measures the number of linearly independent
paths through a program’s source code. The
mccabe module helps identify overly complex
functions:
1
2
3
4
5
6
7
8
9
10
11
12
13
| # Example of measuring complexity
from mccabe import get_code_complexity
def complex_function(x):
if x > 10:
if x > 20:
if x > 30:
return "very high"
return "high"
return "medium"
return "low"
# This function would have high cyclomatic complexity
|
Complexity Guidelines
- 1-10: Simple, low risk
- 11-20: Moderate complexity
- 21-50: High complexity, consider refactoring
- >50: Very high risk, definitely refactor
Advanced Code Quality with Prospector
Prospector is a meta-tool that runs multiple
Python code analysis tools and presents the results in a unified format:
1
2
3
| # Install and run prospector
pip install prospector
prospector myproject/
|
It combines:
- pylint for comprehensive analysis
- pep8/pycodestyle for style checking
- pep257/pydocstyle for docstring conventions
- pyflakes for logical errors
- mccabe for complexity analysis
CPython Internals Resources
Understanding Python’s internals makes you a better Python developer. Here are
the essential resources I discovered:
Core Learning Materials
- CPython Internals Book by Anthony Shaw -
Comprehensive guide to Python’s implementation
- CPython Source Code Guide -
RealPython’s detailed walkthrough
- Advanced Internals of CPython by Prashanth Raghu -
Deep technical PDF resource
Video Resources
Must-Watch CPython Content
Modern Python Development Practices
Import Sorting with isort
isort automatically sorts Python imports
according to PEP 8 guidelines:
1
2
3
4
5
6
7
8
9
10
11
12
13
| # Before isort
import sys
from myproject import settings
import os
from django.conf import settings as django_settings
# After isort
import os
import sys
from django.conf import settings as django_settings
from myproject import settings
|
Configuration in pyproject.toml:
1
2
3
4
| [tool.isort]
profile = "black"
multi_line_output = 3
line_length = 88
|
Profiling with Line Profiler
line_profiler provides
line-by-line timing information:
1
2
3
4
5
6
7
8
| @profile
def slow_function():
# Your code here
time.sleep(0.1)
result = sum(range(1000000))
return result
# Run with: kernprof -l -v script.py
|
Memory Profiling with Guppy/Heapy
Guppy3/Heapy helps identify memory
leaks and understand memory usage:
1
2
3
4
5
| from guppy import hpy
h = hpy()
print(h.heap())
# Shows detailed memory usage by object type
|
File Watching and Automation
The entr Command
entr runs commands when files change -
perfect for development workflows:
1
2
3
4
5
6
7
8
| # Run tests when Python files change
find . -name "*.py" | entr python -m pytest
# Restart server on code changes
find . -name "*.py" | entr -r python app.py
# Run linting on save
find . -name "*.py" | entr pylint
|
Development Workflow
entr is incredibly useful for
continuous testing, linting, or building during development. It’s more reliable
than many IDE file watchers and works across all platforms.
Advanced Python Features and PEPs
PEP 618: Optional Length-Checking to zip
PEP 618 introduced strict
parameter to zip():
1
2
3
4
5
6
7
| # Before PEP 618 - silent truncation
list1 = [1, 2, 3]
list2 = [4, 5]
result = list(zip(list1, list2)) # [(1, 4), (2, 5)]
# After PEP 618 - explicit error
result = list(zip(list1, list2, strict=True)) # ValueError!
|
PEP 622: Structural Pattern Matching
PEP 622 brought pattern matching to
Python 3.10+:
1
2
3
4
5
6
7
8
9
10
| def handle_data(data):
match data:
case {"type": "user", "name": str(name)}:
return f"User: {name}"
case {"type": "product", "id": int(product_id)}:
return f"Product ID: {product_id}"
case list() if len(data) > 10:
return "Large list"
case _:
return "Unknown data"
|
Try it in the
Pattern Matching Playground.
Flask Extensions for Code Quality
1
2
| # Flask-specific linting
pip install pylint-flask pylint-flask-sqlalchemy
|
These plugins understand Flask patterns and reduce false positives:
1
2
3
4
5
6
7
8
| # Without pylint-flask: "Instance of 'Flask' has no 'route' member"
# With pylint-flask: Correctly understands Flask patterns
from flask import Flask
app = Flask(__name__)
@app.route('/') # No longer flagged as error
def home():
return "Hello World"
|
Profiling Flask Applications
Use Werkzeug’s profiler middleware for detailed performance analysis:
1
2
3
4
5
6
| from werkzeug.contrib.profiler import ProfilerMiddleware
from flask import Flask
app = Flask(__name__)
app.wsgi_app = ProfilerMiddleware(app.wsgi_app,
restrictions=[30]) # Top 30 calls
|
Python Packaging Evolution
Modern Python Packaging
The landscape is evolving rapidly:
- Poetry - Modern dependency
management
- Flit - Simple publishing workflow
- pyproject.toml - New
standard for project metadata
PEP 508: Dependency Specification
PEP 508 defines the format for
dependency specifications:
1
2
3
4
5
6
7
8
9
| # Basic dependency
requests >= 2.25.0
# Environment markers
dataclasses; python_version < "3.7"
pywin32; sys_platform == "win32"
# Complex conditions
scipy >= 1.0.0; (python_version >= "3.7" and platform_machine != "aarch64")
|
Quality of Life Improvements
Key Takeaways
- Code Quality is Multi-Dimensional: Use multiple tools (pylint, flake8,
prospector) for comprehensive analysis
- Understanding Internals Matters: CPython knowledge helps write better,
more efficient code
- Automation is Essential: Tools like
entr and proper CI/CD make
development smoother - Modern Python is Evolving: Stay updated with new PEPs and packaging
standards
- Profiling Before Optimizing: Use proper tools to identify actual
bottlenecks
Development Philosophy
The best
developers don’t just write code that works - they write code that’s
maintainable, efficient, and follows established patterns. These tools help
achieve that goal systematically.
This exploration of Python development tools reinforces that professional Python
development requires a comprehensive toolkit beyond just knowing the language
syntax.
These discoveries came from my learning archive spanning 2020, showing how
Python tooling and best practices continue to evolve while maintaining backward
compatibility and developer productivity.