Thank you for your interest in contributing to the NetBird Python Client! This guide will help you get started with contributing to the project.
- Code of Conduct
- Getting Started
- Development Setup
- Making Changes
- Testing
- Code Style
- Submitting Changes
- Reporting Issues
This project follows the NetBird community standards. Please be respectful and inclusive in all interactions.
- Python 3.10 or higher
- Git
- A NetBird account with API access (for integration testing)
-
Fork and clone the repository
git clone https://github.com/your-username/netbird-python-client.git cd netbird-python-client -
Create a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\\Scripts\\activate
-
Install development dependencies
pip install -e ".[dev]" -
Install pre-commit hooks
pre-commit install
-
Verify setup
pytest --version mypy --version black --version
Use descriptive branch names:
feature/add-async-support- New featuresfix/authentication-error- Bug fixesdocs/api-reference-update- Documentation updatesrefactor/client-structure- Code refactoring
-
Create a new branch
git checkout -b feature/your-feature-name
-
Make your changes
- Follow the existing code structure
- Add type hints to all functions
- Include docstrings for public methods
- Update relevant documentation
-
Add tests
- Write unit tests for new functionality
- Ensure existing tests still pass
- Aim for high test coverage
-
Run quality checks
# Run tests pytest # Type checking mypy src/ # Code formatting black src/ tests/ isort src/ tests/ # Linting flake8 src/ tests/
# Run all tests
pytest
# Run with coverage
pytest --cov=src/netbird --cov-report=html
# Run specific test categories
pytest -m unit
pytest -m integration
# Run tests for specific module
pytest tests/test_client.pytests/unit/- Unit tests that don't require external dependenciestests/integration/- Integration tests that interact with the NetBird APItests/fixtures/- Test data and fixtures
-
Unit Tests
import pytest from netbird import APIClient from netbird.exceptions import NetBirdAuthenticationError def test_client_initialization(): client = APIClient(host="example.com", api_token="test-token") assert client.host == "example.com" def test_invalid_token_raises_error(): with pytest.raises(NetBirdAuthenticationError): # Test authentication error handling pass
-
Integration Tests
import os import pytest from netbird import APIClient @pytest.fixture def client(): api_token = os.getenv("NETBIRD_TEST_TOKEN") if not api_token: pytest.skip("NETBIRD_TEST_TOKEN not set") return APIClient(host="api.netbird.io", api_token=api_token) @pytest.mark.integration def test_list_users(client): users = client.users.list() assert isinstance(users, list)
For integration tests, set these environment variables:
export NETBIRD_TEST_TOKEN="your-test-api-token"
export NETBIRD_TEST_HOST="api.netbird.io" # OptionalWe use the following tools to maintain code quality:
- Black: Code formatting
- isort: Import sorting
- flake8: Linting
- mypy: Type checking
-
Type Hints
from typing import List, Optional def get_users(self, active_only: bool = False) -> List[User]: \"\"\"Get list of users. Args: active_only: Filter for active users only Returns: List of User objects \"\"\"
-
Docstrings
def create_user(self, user_data: UserCreate) -> User: \"\"\"Create a new user. Args: user_data: User creation data Returns: Created User object Raises: NetBirdValidationError: If user data is invalid NetBirdAPIError: If creation fails Example: >>> user_data = UserCreate(email="test@example.com", name="Test User") >>> user = client.users.create(user_data) \"\"\"
-
Error Handling
try: response = self.client.get(f"users/{user_id}") return self._parse_response(response, User) except HTTPError as e: if e.response.status_code == 404: raise NetBirdNotFoundError(f"User {user_id} not found") raise NetBirdAPIError(f"Failed to get user: {e}")
The project uses pre-commit hooks to ensure code quality:
# .pre-commit-config.yaml
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8-
Ensure your code passes all checks
pytest mypy src/ black --check src/ tests/ isort --check-only src/ tests/ flake8 src/ tests/
-
Update documentation
- Update docstrings for new/changed methods
- Update README if needed
- Add examples for new features
-
Create a pull request
- Write a clear title and description
- Reference any related issues
- Include examples of new functionality
## Description
Brief description of the changes.
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Documentation update
- [ ] Refactoring
## Testing
- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] All tests pass
## Checklist
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] No breaking changes (or clearly documented)- Automated checks must pass
- At least one maintainer review required
- All conversations must be resolved
- No merge conflicts
When reporting bugs, please include:
-
Environment Information
- Python version
- Package version
- Operating system
-
Steps to Reproduce
# Minimal code example from netbird import APIClient client = APIClient(host="api.netbird.io", api_token="token") # Steps that cause the issue
-
Expected vs Actual Behavior
- What you expected to happen
- What actually happened
- Error messages or stack traces
-
Additional Context
- Any other relevant information
For feature requests, please provide:
- Use Case: Describe the problem you're trying to solve
- Proposed Solution: How you think it should work
- Alternatives: Other solutions you've considered
- Additional Context: Any other relevant information
- GitHub Discussions: For general questions and discussions
- GitHub Issues: For bug reports and feature requests
- NetBird Community: Join the broader NetBird community
Contributors will be recognized in:
- CHANGELOG.md for significant contributions
- README.md contributors section
- Release notes for major features
Thank you for contributing to the NetBird Python Client! 🚀