Skip to content

About

A command line tool for Drivers Python development tasks.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

drivers-python-cli

A command line tool for Drivers Python development tasks. AI first. De-siloing happens here. Inspired by django-mongodb-cli.

CI codecov Python 3.11+ License Documentation Status

About

Drivers Python is the MongoDB Database Experience Team for the MongoDB Python driver.

Note: This is not Databricks for Python developers.

Feature Highlights

  • 🤖 AI-First Design - Built with AI-assisted development workflows in mind
  • 🔧 Modern Tooling - Uses the latest Python development tools and best practices
  • 📦 Fast Package Management - Powered by uv
  • ✨ Quality Focused - Pre-commit hooks with prek and ruff
  • 📚 Well Documented - Sphinx documentation with the beautiful Furo theme
  • ✅ Fully Tested - Comprehensive test suite with pytest and coverage reporting

See the full documentation for detailed feature documentation.

Installation

Via pipx (Recommended)

# Install directly from GitHub
pipx install git+https://github.com/mongodb-labs/drivers-python-cli.git

This will install drivers-python-cli globally and make the dpy command available in your terminal.

Quick Start

Step 1: Initialize Configuration

First, initialize the configuration file:

dpy config init

This creates a configuration file at ~/.config/drivers-python-cli/config.toml with default settings.

The default configuration includes:

  • Base directory: ~/Developer/mongodb
  • Pre-configured repository groups (django, pymongo, langchain, etc.)

You can edit this file to customize your setup.

Step 2: Clone Repositories

Clone a group of related repositories:

# Clone the django group
dpy clone -g django

This will clone all repositories in the django group to ~/Developer/mongodb/django/.

Step 3: Install Dependencies

Note: The dpy clone command automatically runs dpy install after cloning, but you can also install repositories and repository groups manually.

Install dependencies for a repository:

# Install dependencies for django-mongodb-backend
dpy install django-mongodb-backend

# Install with test extras
dpy install django-mongodb-backend -e test

# Install libmongocrypt (includes cmake build step for Queryable Encryption)
dpy install libmongocrypt

Tip: Extras and dependency groups can be configured in your config.toml file so you don't need to specify them on the command line each time.

Step 4: Run Tests

Run tests for a repository:

# Run all tests
dpy test django

# Run a specific test module (note: django-mongodb-backend modules have trailing underscores)
dpy test django encryption_

# Run tests matching a keyword
dpy test django encryption_ -k test_schema

Working with Django Projects

Create and manage Django projects with MongoDB backend:

# Create a new project
dpy project add myproject

# Install the project (defaults to newest project)
dpy project install

# Run migrations (defaults to newest project)
dpy project migrate

# Create a superuser (defaults to newest project)
dpy project su

# Run the project (defaults to newest project)
dpy project run

Convenience Feature: Most project commands default to the newest project when no name is specified. This makes it faster to work with your current project without typing the name repeatedly.

Common Workflows

List Everything:

# List all cloned repositories
dpy list

# List all virtual environments
dpy env list

Run Just Commands:

If a repository has a justfile, you can run just commands:

# Show available just commands
dpy just mongo-python-driver

# Run a specific just command
dpy just mongo-python-driver lint

# Run just command with arguments
dpy just mongo-python-driver test -v

Sync Repositories:

Keep your repositories up to date. dpy sync switches to the repo's default branch (preferred_branch, else main, else master), syncs it, and returns to your branch:

# Sync a single repository
dpy sync django-mongodb-backend

# Sync all repositories in a group
dpy sync -g django

# Sync all repositories across all groups
dpy sync -a

Spec Sync:

Keep driver spec tests in sync with the MongoDB specifications repository:

# Check which specs are out of date
dpy spec status

# Sync all specs (pure file copy from specifications → test/)
dpy spec sync

# Sync specific specs
dpy spec sync crud sessions change-streams

# Sync and immediately apply all patches
dpy spec sync --apply-patches

# List active patches (tests excluded pending JIRA tickets)
dpy spec patch list

# Verify all patches still apply cleanly
dpy spec patch verify

# Create a patch for unimplemented tests (after syncing)
dpy spec patch create PYTHON-1234

# Remove a patch once the feature is implemented
dpy spec patch remove PYTHON-1234

The dpy spec sync command wraps .evergreen/resync-specs.sh in the driver repo, auto-detecting the specifications repo from your config. Patches in .evergreen/spec-patch/PYTHON-XXXX.patch are reverse-applied (git apply -R) to exclude tests for features not yet implemented; each patch is named after a pre-existing JIRA ticket.

The weekly bot PR ([Spec Resync] MM-DD-YYYY) is produced by this same file-copy operation. To reproduce it locally: dpy spec sync on main.

See the full spec sync documentation for details.

View Git Branches:

View branches across repositories:

# View branches in a single repository
dpy branch django-mongodb-backend

# View all branches (including remote) with verbose output
dpy -v branch django-mongodb-backend

# View branches in all repositories in a group
dpy branch -g django

# View all branches in all repositories in a group
dpy -v branch -g django

Working with Multiple Groups:

You can work with multiple repository groups:

# Clone langchain group
dpy clone -g langchain

# Create venv for langchain
dpy env init -g langchain

# Install dependencies
dpy install langchain-mongodb -g langchain

Verbose Mode:

Use -v or --verbose for detailed output:

dpy -v install django-mongodb-backend
dpy --verbose test django encryption_

Pager Mode:

Use -p or --pager to view output through a pager (less):

dpy -p branch -g pymongo
dpy -p log mongo-python-driver
dpy -p config show

For more details, see the full documentation.

Development

Getting Started

# Clone the repository
git clone https://github.com/mongodb-labs/drivers-python-cli.git
cd drivers-python-cli

# Install the package (uses uv pip install -e .)
just install

# Install pre-commit hooks
just install-hooks

The just install command uses uv under the hood to install the package in editable mode. If you need development dependencies, you can install them with just:

just install-docs  # Documentation dependencies
just install-test  # Testing dependencies

Or use uv directly:

uv pip install -e ".[docs]"  # Documentation dependencies
uv pip install -e ".[test]"  # Testing dependencies
uv pip install -e ".[dev]"   # All development dependencies (docs + test)

Command Runner

This project uses just as a command runner. All commands have single-character aliases for convenience.

Common Commands

# Install the package
just install      # or: just i

# Run tests
just test         # or: just t

# Build documentation
just docs         # or: just d

# Format code
just format       # or: just f

# Run linter
just lint         # or: just l

# Run pre-commit hooks
just hooks-run    # or: just h

# Build the package
just build        # or: just b

# Clean build artifacts
just clean        # or: just c

Running Tests

# Run all tests with coverage
just test

# Run tests with verbose output
just test-verbose

# Generate coverage report
just test-cov

Building Documentation

# Build HTML documentation
just docs

# Serve documentation locally
just docs-serve

# Clean documentation build
just docs-clean

Technology Stack

  • CLI Framework: Typer - Modern, intuitive CLI framework
  • Package Manager: uv - Ultra-fast Python package installer
  • Task Runner: just - Command runner with simple syntax
  • Pre-commit: prek - Pre-commit hook manager
  • Linter/Formatter: ruff - Extremely fast Python linter
  • Documentation: Sphinx with Furo theme
  • Testing: pytest with pytest-cov

Project Structure

Repository Structure

drivers-python-cli/
├── src/drivers_python_cli/       # Source code
│   ├── __init__.py           # Package initialization
│   ├── cli.py                # Main CLI entry point
│   ├── config.toml           # Default configuration template
│   ├── commands/             # Command implementations
│   │   ├── branch.py         # Git branch commands
│   │   ├── clone.py          # Repository cloning
│   │   ├── config.py         # Configuration management
│   │   ├── docs.py           # Documentation commands
│   │   ├── edit.py           # Editor integration
│   │   ├── env.py            # Virtual environment management
│   │   ├── install.py        # Dependency installation
│   │   ├── just.py           # Just command runner
│   │   ├── list.py           # Repository listing
│   │   ├── log.py            # Git log commands
│   │   ├── mongodb.py        # MongoDB runner integration
│   │   ├── open.py           # Browser integration
│   │   ├── project.py        # Django project management
│   │   ├── remove.py         # Repository removal
│   │   ├── status.py         # Git status commands
│   │   ├── switch.py         # Git branch switching
│   │   ├── sync.py           # Fork synchronization
│   │   └── test.py           # Test runner
│   ├── utils/                # Utility modules
│   │   ├── project.py        # Project utilities
│   │   ├── repo.py           # Repository utilities
│   │   └── venv.py           # Virtual environment utilities
│   └── templates/            # Django project templates
│       ├── app_template/     # Django app template
│       ├── frontend_template/ # Frontend template
│       └── project_template/ # Django project template
├── tests/                    # Test suite
│   ├── conftest.py           # Pytest configuration
│   ├── test_*.py             # Command tests
│   └── integration/          # Integration tests
├── docs/                     # Sphinx documentation
│   ├── conf.py               # Sphinx configuration
│   ├── index.rst             # Documentation index
│   ├── introduction/         # Introduction docs
│   ├── features/             # Feature documentation
│   ├── design/               # Design documentation
│   ├── api/                  # API documentation
│   └── development/          # Development docs
├── pyproject.toml            # Project configuration
├── justfile                  # Task runner commands
├── uv.lock                   # Dependency lock file
└── README.md                 # This file

User Directory Structure

After running dpy config init and dpy clone -g django, your directory structure will look like:

~/Developer/mongodb/              # base_dir (configurable)
├── django/                       # Group directory
│   ├── .venv/                    # Group-level virtual environment
│   ├── mongo-python-driver/     # Cloned from global group
│   ├── django/                   # Django fork
│   ├── django-mongodb-backend/  # MongoDB backend for Django
│   ├── django-mongodb-extensions/ # MongoDB extensions
│   ├── libmongocrypt/           # Queryable Encryption library
│   └── medical-records/         # Example project
├── pymongo/                      # Another group
│   ├── .venv/                    # Separate venv for this group
│   ├── mongo-python-driver/     # Cloned from global group
│   ├── specifications/          # MongoDB specifications
│   └── drivers-evergreen-tools/ # Testing tools
└── langchain/                    # Another group
    ├── .venv/                    # Separate venv for this group
    ├── mongo-python-driver/     # Cloned from global group
    └── langchain-mongodb/       # LangChain MongoDB integration

Key Points:

  • Group-Level Virtual Environments: Each group has its own .venv directory for isolated dependencies
  • Global Repositories: Repositories in global_groups (like mongo-python-driver) are automatically cloned into every group
  • Configurable Base Directory: The base directory can be customized in ~/.config/drivers-python-cli/config.toml
  • Organized by Purpose: Groups organize related repositories (e.g., django, pymongo, langchain)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Install pre-commit hooks (just install-hooks)
  4. Make your changes
  5. Run tests (just test)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

Links


Made with ❤️ by MongoDB Drivers Python

About

A command line tool for Drivers Python development tasks.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages