Skip to main content
Documentation Status https://github.com/MacHu-GWU/soft_deps-project/actions/workflows/main.yml/badge.svg https://codecov.io/gh/MacHu-GWU/soft_deps-project/branch/main/graph/badge.svg https://img.shields.io/pypi/v/soft-deps.svg https://img.shields.io/pypi/l/soft-deps.svg https://img.shields.io/pypi/pyversions/soft-deps.svg https://img.shields.io/badge/✍️_Release_History!--None.svg?style=social&logo=github https://img.shields.io/badge/⭐_Star_me_on_GitHub!--None.svg?style=social&logo=github
https://img.shields.io/badge/Link-API-blue.svg https://img.shields.io/badge/Link-Install-blue.svg https://img.shields.io/badge/Link-GitHub-blue.svg https://img.shields.io/badge/Link-Submit_Issue-blue.svg https://img.shields.io/badge/Link-Request_Feature-blue.svg https://img.shields.io/badge/Link-Download-blue.svg

Welcome to soft_deps Documentation

https://soft-deps.readthedocs.io/en/latest/_static/soft_deps-logo.png

soft-deps is a Python pattern for elegant optional dependency management that prioritizes developer experience over lazy loading. Unlike true lazy imports, soft-deps immediately attempts to import dependencies at module load time - if the dependency is installed, you get the real module with full functionality. If it’s missing, you get a helpful proxy object that provides complete IDE type hints and auto-completion, but raises informative error messages only when you actually try to use the missing functionality.

This approach gives you the best of both worlds: seamless development experience with full IDE support when dependencies are available, and graceful degradation with clear installation guidance when they’re not, all while maintaining zero code invasiveness in your implementation.

Quick Start

Why use soft-deps?

  • For library authors: Provide optional features without forcing users to install heavy dependencies

  • For users: Get full IDE support and autocomplete even for optional dependencies

  • For teams: Graceful degradation with clear error messages instead of cryptic import failures

When to use soft-deps?

Use soft-deps when your library has optional features that depend on external packages:

  • Data science libraries with optional visualization (matplotlib, plotly)

  • Web frameworks with optional database drivers (psycopg2, pymongo)

  • CLI tools with optional cloud integrations (boto3, google-cloud)

  • Any library where you want some features to work without heavy dependencies

How it works:

Library authors use the soft-deps pattern in their code:

# your_library.py
from soft_deps.api import MissingDependency

# Try to import optional dependency
try:
    import pandas as pd
except ImportError:
    # Create helpful proxy if missing
    pd = MissingDependency("pandas", "pip install pandas")

def export_to_excel(data):
    """Export data to Excel file (requires pandas)."""
    # IDE gets full autocomplete here even if pandas not installed
    # Error only occurs when this line actually executes
    return pd.DataFrame(data).to_excel("output.xlsx")

Users get seamless experience regardless of what’s installed:

# user_script.py
from your_library import export_to_excel

# This imports successfully even without pandas installed
# IDE provides full autocomplete and type hints

try:
    export_to_excel({"col1": [1, 2, 3]})
except ImportError as e:
    print(e)  # "You didn't install pandas. To use DataFrame, pip install pandas"

The difference:

# ❌ Traditional approach - breaks immediately
import pandas as pd  # ImportError if not installed

# ❌ Lazy imports - no IDE support
def export_data():
    import pandas as pd  # IDE can't help with autocomplete

# ✅ soft-deps - best of both worlds
try:
    import pandas as pd
except ImportError:
    pd = MissingDependency("pandas", "pip install pandas")
# IDE gets full support, graceful errors when actually used

Install

soft_deps is released on PyPI, so all you need is to:

$ pip install soft-deps

To upgrade to latest version:

$ pip install --upgrade soft-deps

Metadata

Release files for soft-deps 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for soft-deps 0.1.1
File Size Uploaded
soft_deps-0.1.1.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for soft-deps 0.1.1
File Interpreter ABI Platform
soft_deps-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.5 kB

Release files / soft_deps-0.1.1.tar.gz

Download URL soft_deps-0.1.1.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
06821b012cdc3d2c0585bc13b3eb7816b779ab27e2b8dfdfef6d5c761ec982b8
BLAKE2b-256 checksum
How to use checksums
592f3d5532c4563ff723de944de32c5068328bff01d65e99dd852ee98468d30b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.8

Release files / soft_deps-0.1.1-py3-none-any.whl

Download URL soft_deps-0.1.1-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40299ae5b0795d54e088ef72c8dc78ea927f87e430f8d685632bcdb46bed8098
BLAKE2b-256 checksum
How to use checksums
fad46c267222eed51422cfd9d37a55d3d59bf1a82eda4b393cd0a583c08a55b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.8

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page