Elegant optional dependency management for Python - full IDE support when available, graceful degradation when missing.
Project description
Welcome to soft_deps Documentation
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file soft_deps-0.1.1.tar.gz.
File metadata
- Download URL: soft_deps-0.1.1.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06821b012cdc3d2c0585bc13b3eb7816b779ab27e2b8dfdfef6d5c761ec982b8
|
|
| MD5 |
7d7395ae0eb7fdc294310a1d8f91ffb5
|
|
| BLAKE2b-256 |
592f3d5532c4563ff723de944de32c5068328bff01d65e99dd852ee98468d30b
|
File details
Details for the file soft_deps-0.1.1-py3-none-any.whl.
File metadata
- Download URL: soft_deps-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40299ae5b0795d54e088ef72c8dc78ea927f87e430f8d685632bcdb46bed8098
|
|
| MD5 |
320f70089c070171a2b4a49a6b9aa4b9
|
|
| BLAKE2b-256 |
fad46c267222eed51422cfd9d37a55d3d59bf1a82eda4b393cd0a583c08a55b2
|