---
title: "Python Development Patterns"
description: "Python coding patterns and conventions for project structure, code organization, error handling, and performance. Covers venv, async/await, factory pattern, and context managers."
type: context
domain: development
tags: [python, patterns, async, error-handling, performance]
---

# Python Patterns

## Project Structure
- Use virtual environments (venv)
- Implement proper package structure with `__init__.py`
- Separate configuration from code
- Use requirements.txt for dependencies

## Code Organization
- **MVC/MVT patterns** for web applications
- **Factory pattern** for object creation
- **Context managers** for resource handling
- **Async/await** for I/O-bound operations

## Error Handling
- Use specific exception types
- Implement proper logging with levels
- Graceful degradation for external dependencies
- Validation at API boundaries

## Performance Considerations
- Use generators for large datasets
- Profile before optimizing
- Leverage caching appropriately
- Consider async for concurrent operations

## Related Documentation
- Examples: `/examples/python/web-frameworks.md`
- Examples: `/examples/python/api-clients.md`
- Examples: `/examples/python/async-patterns.md`
- Reference: `/reference/python/debugging.md`
- Reference: `/reference/python/performance.md`
