Thank you for your interest in contributing to the Langbase Python SDK! We welcome contributions from the community.
- Python 3.7 or higher
- pip package manager
- git
-
Fork and clone the repository
git clone https://github.com/langbase/langbase-python-sdk cd langbase-python-sdk -
Create a virtual environment
python3 -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
Check version of pip
pip --version
If it's pip 21.3 or lower, you need to upgrade it.
pip install --upgrade pip
-
Install the package in development mode
pip install -e . -
Install development dependencies
pip install -r requirements-dev.txt
-
Install pre-commit hooks
pre-commit install
# Auto-format with Black (required)
black langbase/ tests/ examples/
# Sort imports with isort (required)
isort langbase/ tests/ examples/# Run all tests
pytest
# Run with coverage
pytest --cov=langbase
# Run specific test file
pytest tests/test_pipes.py
# Run in verbose mode
pytest -v# This runs all pre-commit hooks (black, isort)
pre-commit run --all-filesThe release process is automated with an interactive script. Only maintainers should create releases.
python release.pyThe script will guide you through:
- Choosing version bump type (patch/minor/major)
- Writing release notes
- Updating version files
- Committing and pushing changes
- Building and uploading to PyPI
See the Release Process section below for detailed instructions.
Ensure your contribution meets these requirements:
- ✅ Code is formatted with
black - ✅ Imports are sorted with
isort - ✅ All tests pass with
pytest - ✅ New features have tests
- ✅ New features have type hints
- ✅ Documentation is updated if needed
Before running python release.py, ensure:
- ✅ All tests pass:
pytest - ✅ Code is properly formatted:
pre-commit run --all-files - ✅ Working directory is clean:
git status - ✅ On main branch and up to date:
git pull origin main - ✅ Have PyPI credentials configured in
~/.pypirc(see PyPI Configuration section) - ✅ Have dev dependencies installed:
pip install -r requirements-dev.txt - ✅ Reviewed changes since last release
- ✅ Prepared release notes describing changes
git checkout -b feature/your-feature-name- Write clean, readable code
- Add type hints to all functions
- Follow existing code patterns
- Add docstrings to public functions
- Write tests for new features
- Ensure existing tests still pass
- Aim for good test coverage
- Update README.md if adding new features
- Update docstrings
- Add examples if applicable
# Stage your changes
git add .
# Commit with a descriptive message
git commit -m "📖 DOC: Improved contribution docs"Follow conventional commit format:
📦 NEW:New feature.👌IMPROVE:Improvements.🐛 BUG:Bug fix.📖 Docs:Documentation changes.🚀 RELEASE: Release new version.
git push origin feature/your-feature-nameThen create a Pull Request on GitHub.
All functions should have type hints:
def process_data(input_text: str, max_length: int = 100) -> Dict[str, Any]:
"""Process input text and return results."""
...Use Google-style docstrings:
def my_function(param1: str, param2: int) -> bool:
"""
Brief description of function.
Args:
param1: Description of param1
param2: Description of param2
Returns:
Description of return value
...- Use pytest for all tests
- Use descriptive test names
- Test both success and error cases
- Use fixtures for common setup
Example:
def test_pipe_run_with_invalid_name_raises_error(langbase_client):
"""Test that running a pipe with invalid name raises appropriate error."""
with pytest.raises(NotFoundError) as exc_info:
langbase_client.pipes.run(name="non-existent-pipe")
assert "404" in str(exc_info.value)Before creating a release, ensure you have:
-
PyPI Account & Access
-
Required Tools
These are already installed with dev dependencies:
pip install -r requirements-dev.txt # Includes build and twine -
Clean Working Directory
git status # Should show no uncommitted changes git pull origin main # Ensure you're up to date
Create or update your ~/.pypirc file with your PyPI credentials:
[distutils]
index-servers =
pypi
testpypi
[pypi]
username = __token__
password = pypi-your-api-token-here
[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__
password = pypi-your-test-api-token-hereTo get API tokens:
- PyPI: Go to PyPI Account Settings → API tokens → "Add API token"
- Test PyPI: Go to Test PyPI Account Settings → API tokens → "Add API token"
Security Notes:
- Use API tokens instead of passwords (more secure)
- Set appropriate permissions (project-scoped tokens recommended)
- Keep your
~/.pypircfile private (chmod 600)
Choose the appropriate version bump:
- patch (0.1.0 → 0.1.1): Bug fixes, documentation updates, small improvements
- minor (0.1.0 → 0.2.0): New features, backwards compatible changes
- major (0.1.0 → 1.0.0): Breaking changes, major API updates
-
Run the Release Script
python release.py
-
Follow Interactive Prompts
The script will ask you to:
- Choose release type (patch/minor/major)
- Enter release message describing changes
- Confirm version bump
- Choose between Test PyPI or Production PyPI
-
What the Script Does Automatically
- Updates version in
pyproject.tomlandlangbase/__init__.py - Updates
CHANGELOG.mdwith release notes - Commits changes with conventional commit message
- Pushes to GitHub (optional)
- Builds the package (
python -m build) - Uploads to PyPI/Test PyPI (
twine upload)
- Updates version in
For testing releases before production:
- Run
python release.py - Answer "y" when asked about Test PyPI
- This uploads to https://test.pypi.org/project/langbase/
- Test install:
pip install --index-url https://test.pypi.org/simple/ langbase
Note: Test releases don't commit to git, so you can reset changes after testing.
- Run
python release.py - Answer "n" when asked about Test PyPI
- The package will be uploaded to https://pypi.org/project/langbase/
- Changes are committed and pushed to GitHub
After a successful release:
- ✅ Verify the new version appears on PyPI
- ✅ Test install the new version:
pip install langbase=={version} - ✅ Check that GitHub has the release commit
- ✅ Update any dependent projects or documentation
- ✅ Announce the release (Discord, social media, etc.)
Common Issues:
-
PyPI Upload Fails
- Check your
~/.pypircconfiguration - Ensure you have maintainer access
- Version might already exist (can't overwrite)
- Check your
-
Pre-commit Hooks Fail
- The script retries automatically
- Hooks may modify files (formatting, etc.)
- Script will re-stage and retry up to 3 times
Recovery:
If a release fails partway through:
# Reset version changes (if not yet committed)
git checkout -- pyproject.toml langbase/__init__.py CHANGELOG.md
# Or if committed but not pushed, reset the last commit
git reset --soft HEAD~1- Check existing issues and PRs
- Read the documentation
- Ask in our Discord community
- Open an issue for bugs or feature requests
By contributing, you agree that your contributions will be licensed under the Apache 2.0 License.