Thank you for your interest in contributing to pydgraph! We welcome contributions from the community.
- Getting Started
- Development Setup
- Making Changes
- Code Style and Standards
- Testing
- Submitting a Pull Request
- Code of Conduct
-
Fork the repository on GitHub
-
Clone your fork locally:
git clone https://github.com/YOUR-USERNAME/pydgraph.git cd pydgraph -
Add the upstream repository:
git remote add upstream https://github.com/dgraph-io/pydgraph.git
- Python 3.13+ (for development; Python 3.9+ for using the library)
- Docker and Docker Compose (for running tests)
- Git
This project uses a Makefile to simplify common development tasks. To see all available commands:
make helpOutput:
Environment Variables:
INSTALL_MISSING_TOOLS=true Enable automatic installation of missing tools (default: disabled)
Available targets:
help Show this help message
setup Setup project (install tools and sync dependencies)
sync Sets up and syncs project virtual environment.
check Run pre-commit hooks on all files
protogen Regenerate protobuf files (requires Python 3.13+)
clean Cleans build artifacts
build Builds release package
test Run tests
publish Publish a new release to PyPi (requires UV_PUBLISH_USERNAME and UV_PUBLISH_PASSWORD to be set)
deps Check/install tool dependencies (set INSTALL_MISSING_TOOLS=true to auto-install)
deps-docker Check and install Docker if needed (requires Docker 20.10.0+)
-
Set up the project:
make setup
This will:
- Check for required tools (uv, trunk, docker)
- Install pre-commit hooks
- Set up the correct Python version
- Create and configure a virtual environment
- Install all project dependencies
Note: To automatically install any missing tool dependencies (uv, trunk, docker), you can set
INSTALL_MISSING_TOOLStotrue:INSTALL_MISSING_TOOLS=true make setup
-
Verify your setup:
make check
After making changes to dependencies or pulling updates:
make syncThis syncs the project virtual environment with the latest dependencies.
If you make changes to pydgraph/proto/api.proto, regenerate the source files:
make protogenOr directly with uv:
uv run python scripts/protogen.pyImportant: This project uses Python 3.13+ with grpcio-tools 1.66.2+ as the canonical development environment. The generated proto files include mypy type stubs for better type checking. The script will verify you have the correct Python and grpcio-tools versions before generating files.
This project requires grpcio 1.65.0 or higher. Older versions have practical limitations:
- Compilation failures: grpcio versions older than ~1.60.0 fail to compile from source on modern systems (macOS with recent Xcode, newer Linux distributions) due to C++ compiler compatibility issues and outdated build configurations.
- No pre-built wheels: PyPI doesn't provide pre-built wheels for very old grpcio versions on modern Python versions (3.11+), forcing compilation from source.
- Build tool incompatibility: The build process for older grpcio versions uses deprecated compiler flags and build patterns that modern toolchains reject.
-
Create a new branch for your changes:
git checkout -b your-feature-name
-
Make your changes following our Code Style and Standards
-
Add tests for your changes (see Testing)
-
Ensure all checks pass:
make check testImportant: Before opening a pull request, make sure
make check testsucceeds locally. -
Commit your changes using Conventional Commits format:
git commit -m "feat: add new feature" git commit -m "fix: resolve issue with..." git commit -m "docs: update README"
- Follow PEP 8 style guidelines (enforced by ruff)
- Use type hints for all function signatures
- Add docstrings for public APIs
- Maximum line length: handled by the formatter
Every new Python file must start with SPDX headers followed by proper attribution:
# SPDX-FileCopyrightText: © 2017-2026 Istari Digital, Inc.
# SPDX-License-Identifier: Apache-2.0
"""
Module description here.
"""
__author__ = "Your Name"
__maintainer__ = "Istari Digital, Inc."Requirements:
- SPDX Headers: All new Python files must start with the two SPDX comment lines shown above
__author__: Set to your name (the contributor's name)__maintainer__: Always set to "Istari Digital, Inc."
This project uses several tools to maintain code quality:
- ruff: Linting and code formatting
- mypy: Static type checking
- trunk: Additional code quality checks
- pre-commit: Automated checks on commit
Run all checks:
make checkRun the full test suite:
make testRun specific tests:
make test PYTEST_ARGS="-v tests/test_connect.py::TestOpen"Run a single test:
make test PYTEST_ARGS="-v tests/test_connect.py::TestOpen::test_connection_with_auth"The project includes comprehensive stress tests that verify concurrent operations, transaction conflicts, deadlock prevention, and retry mechanisms for both sync and async clients.
Quick mode (default, ~12 seconds) - 20 workers, 50 ops, 10 iterations:
make test PYTEST_ARGS="tests/test_stress_sync.py tests/test_stress_async.py -v"Moderate mode (10x quick, includes movie dataset, ~60+ seconds) - 200 workers, 500 ops, 100 iterations:
make test STRESS_TEST_MODE=moderate PYTEST_ARGS="tests/test_stress_sync.py tests/test_stress_async.py -v"Full mode (10x moderate, maximum stress, ~10+ minutes) - 2000 workers, 5000 ops, 1000 iterations:
make test STRESS_TEST_MODE=full PYTEST_ARGS="tests/test_stress_sync.py tests/test_stress_async.py -v"The stress tests cover:
- Sync tests: Run with
ThreadPoolExecutorto test concurrent operations - Async tests: Use pure
asyncio.gather()concurrency (noconcurrent.futuresmixing) - Retry utilities: Tests for
retry_async(),with_retry_async(), andrun_transaction_async() - Deadlock regression: Validates the asyncio.Lock deadlock fix from PR #293
The test script requires Docker and Docker Compose to be installed on your machine.
The script will:
- Automatically bring up a Dgraph cluster
- Connect to randomly selected ports for HTTP and gRPC to prevent interference with clusters running on default ports
- Run the tests
- Bring down the cluster after tests complete
For Docker installation instructions, refer to the official Docker documentation.
- Add tests for all new features
- Add regression tests for bug fixes
- Tests should be clear, concise, and well-documented
- Use descriptive test names that explain what is being tested
Tests are automatically run in CI/CD against:
- Python versions: 3.9, 3.10, 3.11, 3.12, 3.13, 3.14
- Dgraph latest release
- Dgraph HEAD (main branch)
- Protobuf versions: default (6.x) for all Python versions, plus 4.x and 5.x on Python 3.9 and 3.14
The CI matrix tests all Python versions with the default protobuf, and additionally tests older protobuf versions (4.x, 5.x) on the edge Python versions (3.9 and 3.14) to ensure backwards compatibility without excessive CI runtime.
-
Push your changes to your fork:
git push origin your-feature-name
-
Open a pull request on GitHub
-
Fill out the pull request template (see PULL_REQUEST_TEMPLATE.md)
- Title: Must follow Conventional Commits format
- Examples:
feat: add connection pooling,fix: resolve memory leak,docs: update API reference
- Examples:
- Description: Clearly explain what the PR does and why
- Checklist: Complete all applicable items in the PR template
- Tests: All tests must pass (
make check testsucceeds) - Code Quality: All linting and type checking must pass
- Documentation: Update docs if adding/changing public APIs
Follow the Conventional Commits specification:
feat:- New featuresfix:- Bug fixesdocs:- Documentation changesstyle:- Code style changes (formatting, etc.)refactor:- Code refactoringtest:- Adding or updating testschore:- Maintenance tasksci:- CI/CD changes
Examples:
feat: add async client support
fix: resolve connection timeout issue
docs: update installation instructions
refactor: simplify error handling
test: add integration tests for ACL
- Maintainers will review your PR
- Address any feedback or requested changes
- Once approved, a maintainer will merge your PR
This project follows the Contributor Covenant Code of Conduct. Please read our Code of Conduct to understand the standards we expect from all contributors and community members.
- Open an issue for bugs or feature requests
- Join the Dgraph Community Slack for discussions
- Check the Dgraph documentation
- README.md - Project overview and usage
- PULL_REQUEST_TEMPLATE.md - PR template
- Conventional Commits - Commit message format
- Dgraph Documentation - Product documentation
Thank you for contributing to pydgraph! 🎉