Skip to content

Latest commit

 

History

History
207 lines (158 loc) · 4.18 KB

File metadata and controls

207 lines (158 loc) · 4.18 KB

Contributing to Langbase Python SDK

Thank you for your interest in contributing to the Langbase Python SDK! We welcome contributions from the community.

Getting Started

Prerequisites

  • Python 3.7 or higher
  • pip package manager
  • git

Development Setup

  1. Fork and clone the repository

    git clone https://github.com/langbase/langbase-python-sdk
    cd langbase-python-sdk
  2. Create a virtual environment

    python3 -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate

    Note:

    Check version of pip

    pip --version

    If it's pip 21.3 or lower, you need to upgrade it.

    pip install --upgrade pip
  3. Install the package in development mode

    pip install -e .
  4. Install development dependencies

    pip install -r requirements-dev.txt
  5. Install pre-commit hooks

    pre-commit install

Before You Commit

IMPORTANT: All code must pass quality checks before committing. Run these commands:

Format Your Code

# Auto-format with Black (required)
black langbase/ tests/ examples/

# Sort imports with isort (required)
isort langbase/ tests/ examples/

4. Run Tests

# 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

5. Run All Checks at Once

# This runs all pre-commit hooks (black, isort)
pre-commit run --all-files

6. Release a new version

python release.py

3. Optional: Publish to PyPI

python -m build
twine upload dist/*

Quick Checklist

Before pushing your changes, ensure:

  • ✅ 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

Making Changes

1. Create a Feature Branch

git checkout -b feature/your-feature-name

2. Make Your Changes

  • Write clean, readable code
  • Add type hints to all functions
  • Follow existing code patterns
  • Add docstrings to public functions

3. Add Tests

  • Write tests for new features
  • Ensure existing tests still pass
  • Aim for good test coverage

4. Update Documentation

  • Update README.md if adding new features
  • Update docstrings
  • Add examples if applicable

5. Commit Your Changes

# Stage your changes
git add .

# Commit with a descriptive message
git commit -m "📖 DOC: Improved contribution docs"

Follow conventional commit format:

  • 📦 NEW: New feature
  • 🐛 BUG: Bug fix
  • 📖 Docs: Documentation changes
  • 👌🏻 IMP: Improvements

6. Push and Create PR

git push origin feature/your-feature-name

Then create a Pull Request on GitHub.

Code Style Guide

Type Hints

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."""
    ...

Docstrings

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
    ...

Testing Guidelines

Writing Tests

  • 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)

Need Help?

License

By contributing, you agree that your contributions will be licensed under the MIT License.