Installation¶
Requirements¶
- Python 3.11 or higher
Install from PyPI¶
The recommended way to install injectipy is from PyPI using pip:
With Poetry¶
If you're using Poetry for dependency management:
With pipenv¶
If you're using pipenv:
Development Installation¶
If you want to contribute to injectipy or install from source:
1. Clone the Repository¶
2. Install with Poetry (Recommended)¶
# Install Poetry if you haven't already
curl -sSL https://install.python-poetry.org | python3 -
# Install dependencies
poetry install
# Activate the virtual environment
poetry shell
3. Install with pip (Alternative)¶
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
pip install -e .
# Install development dependencies
pip install pytest pytest-cov black mypy ruff pre-commit
Verify Installation¶
Test that injectipy is installed correctly:
import injectipy
print(injectipy.__version__)
# Test basic functionality
from injectipy import inject, Inject, DependencyScope
scope = DependencyScope()
scope.register_value("test", "Hello, World!")
@inject
def test_function(message: str = Inject["test"]):
return message
with scope:
result = test_function()
print(result) # Should print: Hello, World!
Optional Dependencies¶
For development and testing:
# Code formatting and linting
pip install black ruff mypy
# Testing
pip install pytest pytest-cov
# Pre-commit hooks
pip install pre-commit
IDE Setup¶
VS Code¶
For the best development experience with VS Code:
- Install the Python extension
- Configure Python interpreter to use your virtual environment
- Add these settings to
.vscode/settings.json
:
{
"python.formatting.provider": "black",
"python.linting.enabled": true,
"python.linting.mypyEnabled": true,
"python.linting.ruffEnabled": true
}
PyCharm¶
- Configure Python interpreter to use your virtual environment
- Enable type checking: Settings → Editor → Inspections → Python → Type checker
- Configure code style to use Black formatting
Troubleshooting¶
Import Errors¶
If you encounter import errors:
# Make sure injectipy is properly installed
pip show injectipy
# Check Python path
import sys
print(sys.path)
Version Conflicts¶
If you have dependency conflicts:
# Check for conflicts
pip check
# Create a fresh virtual environment
python -m venv fresh_env
source fresh_env/bin/activate
pip install injectipy
Performance Issues¶
For optimal performance:
- Use Python 3.11+ for best performance
- Enable caching for expensive resolvers
- Consider using
register_value
for static dependencies
Next Steps¶
See the main README.md for usage examples and API documentation.