Gormley Lab Python Project Template
A beginner-friendly Python project template that follows best practices and provides a solid foundation for new projects in the Gormley Lab.
- Use this template to create a new repository
- Rename the package: Change
src/package_name/tosrc/your_project_name/ - Update metadata: Edit
src/your_project_name/__about__.pywith your project details - Install dependencies:
pip install -r requirements.txt - Run the example:
python main.py
This template follows the src layout, a Python best practice that keeps your source code organized and separate from tests, documentation, and configuration files.
GL-template/
├── main.py # 🎯 Entry point - run this file to start your program
├── requirements.txt # 📦 List of Python packages your project needs
├── README.md # 📖 Project documentation (this file)
├── LICENSE # ⚖️ Legal terms for using your code
├── attachment/ # 📎 Store additional files and resources
├── data/ # 📊 Store datasets, CSV files, and raw data
├── docs/ # 📚 Documentation files and project notes
├── imgs/ # 🖼️ Images, plots, and visual outputs
├── jsons/ # 📋 JSON configuration and data files
├── models/ # 🤖 Machine learning models and saved weights
├── notebook/ # 📓 Jupyter notebooks for analysis and experimentation
└── src/ # 📂 Source code directory
└── package_name/ # 🐍 Your Python package (rename this!)
├── __init__.py # 🔧 Makes this directory a Python package
├── __about__.py # ℹ️ Package metadata (version, author, etc.)
├── class_example.py # 🏗️ Example class demonstrating OOP concepts
└── utils_example.py # 🛠️ Utility functions for common tasks
- Purpose: The file you run to start your program
- What it does: Imports your package and demonstrates its usage
- Key concept: Uses
if __name__ == "__main__"to ensure code only runs when executed directly
- Rename this to match your project (use lowercase with underscores:
my_awesome_project) - Contains all your project's source code
- The
__init__.pyfile makes it importable as a package
| File | Purpose | When to modify |
|---|---|---|
__init__.py |
Controls what gets imported from your package | When adding new classes/functions |
__about__.py |
Stores project metadata (version, author, description) | At project start and version updates |
class_example.py |
Template for object-oriented code | Replace with your own classes |
utils_example.py |
Template for utility functions | Add general-purpose functions here |
# Rename the package directory
mv src/package_name src/my_project_name
# Update imports in main.py to match your new package name
# Change: from package_name import ...
# To: from my_project_name import ...Edit src/my_project_name/__about__.py:
__title__ = "My Awesome Project"
__description__ = "What your project does"
__version__ = "1.0.0"
__author__ = "Your Name"
__author_email__ = "your.email@example.com"- Classes: Add new
.pyfiles for your classes in the package directory - Functions: Use
utils_example.pyor create new utility files - Imports: Update
__init__.pyto export your new classes and functions
Add any Python packages you need to requirements.txt:
numpy
pandas
matplotlib
- Use classes for complex data structures and behaviors
- Follow naming conventions:
ClassName(PascalCase) for classes,function_name(snake_case) for functions - Document your code with docstrings
- Keep related code together in the same file or subdirectory
- Use descriptive names for files, classes, and functions
- Separate concerns: classes for objects, utils for general functions
- Commit early and often with descriptive messages
- Use .gitignore to exclude temporary files
- Tag releases when you reach milestones
- Create a new
.pyfile in your package directory - Define your class with proper docstrings
- Import it in
__init__.py - Add it to the
__all__list
- Add the package name to
requirements.txt - Install with
pip install -r requirements.txt - Import and use in your code
# Run your program
python main.py
# Check for syntax errors
python -m py_compile src/your_package_name/*.py- Python Classes: Official Python Tutorial on Classes
- Package Structure: Python Packaging Guide
- Best Practices: The Hitchhiker's Guide to Python
This template is designed for the Gormley Lab. Feel free to suggest improvements or report issues to help other lab members get started with Python development.
Happy coding! 🐍✨