Create a new python projects contribute
When creating a new Python repository, some guidelines help keep our code standardized.
Recommended libraries
Development & testing
pytest
: Primary testing framework for writing and running tests.pytest-cov
: Test coverage reporting plugin forpytest
.black
: Opinionated code formatter that ensures consistent code style.flake8
: Linter for style enforcement.pylint
: Comprehensive linter for error detection and quality enforcement.mypy
: Static type checker.isort
: Utility to sort imports.
Package manager & build system
poetry
: Modern packaging and dependency management.
Common utilities
typer
: Library for building CLI applications.python-dotenv
: Environment variable management.pydantic
: Data validation and settings management using Python type annotations.fastapi
: Modern, high-performance web framework for building APIs.structlog
: Structured logging library.httpx
: Asynchronous and performant HTTP client.rich
: Terminal formatting library for rich text.sqlmodel
: Intuitive and robust ORM.tqdm
: Fast, extensible progress bar for CLI.
Recommended folder structure
Depending on the type of project, for example, API service, CLI application or library, the folder structure can be varied. The following structure is for a standard CLI application.
project_name/
├── .gitlab/ # GitLab-specific configuration
│ ├── issue_templates/ # Issue templates
│ └── merge_request_templates/ # MR templates
├── .gitlab-ci.yml # CI/CD configuration
├── project_name/ # Main package directory
│ ├── __init__.py # Package initialization
│ ├── cli.py # Command-line interface entry points
│ ├── config.py # Configuration handling
│ └── core/ # Core functionality
│ └── __init__.py
├── tests/ # Test directory
│ ├── __init__.py
│ ├── conftest.py # pytest fixtures and configuration
│ └── test_*.py # Test modules
├── docs/ # Documentation
├── scripts/ # Utility scripts
├── README.md # Project overview
├── CONTRIBUTING.md # Contribution guidelines
├── LICENSE # License information
├── pyproject.toml # Project metadata and dependencies (Poetry)
Linter configuration
We should consolidate configurations into pyproject.toml
as much as possible.
pyproject.toml
[tool.black]
line-length = 120
[tool.isort]
profile = "black"
[tool.mypy]
python_version = 3.12
ignore_missing_imports = true
[tool.pylint.main]
jobs = 0
load-plugins = [
# custom plugins
]
[tool.pylint.messages_control]
enable = [
# custom plugins
]
[tool.pylint.reports]
score = "no"
setup.cfg
[flake8]
extend-ignore = E203,E501
extend-exclude = **/__init__.py,.venv,tests
indent-size = 4
max-line-length = 120
Adding reviewer roulette
We recommend reviewer roulette to distribute review workload across reviewers and maintainers.
Follow the GitLab Dangerfiles instructions to add the configuration to your project.
Implement the Danger Reviewer component in your GitLab CI pipeline to automatically trigger the roulette.
Docs
Edit this page to fix an error or add an improvement in a merge request.
Create an issue to suggest an improvement to this page.
Product
Create an issue if there's something you don't like about this feature.
Propose functionality by submitting a feature request.
Feature availability and product trials
View pricing to see all GitLab tiers and features, or to upgrade.
Try GitLab for free with access to all features for 30 days.
Get help
If you didn't find what you were looking for, search the docs.
If you want help with something specific and could use community support, post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLab subscription).
Request support