
Research
PyPI Package Disguised as Instagram Growth Tool Harvests User Credentials
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
A lightweight, intuitive dependency injection library for Python that makes testing and dependency management a breeze.
A lightweight, type-safe dependency injection library for Python that supports synchronous, asynchronous, and contextual dependencies.
@dependency
)@async_dependency
)@contextual_dependency
)@cache
pip install diwrappers
from diwrappers import dependency
@dependency
def api_token() -> str:
return "your-api-token"
@api_token.inject
def make_request(api_token: str, endpoint: str):
return f"Calling {endpoint} with token {api_token}"
# The api_token will be automatically injected
result = make_request("/users")
For dependencies that require asynchronous initialization:
from diwrappers import async_dependency
@async_dependency
async def database():
connection = await establish_db_connection()
return connection
@database.inject
async def get_user(db, user_id: int):
return await db.query(f"SELECT * FROM users WHERE id = {user_id}")
# Use with async/await
user = await get_user(123)
For dependencies that need proper resource management:
from diwrappers import contextual_dependency
import contextlib
@contextual_dependency
@contextlib.contextmanager
def db_transaction():
transaction = start_transaction()
try:
yield transaction
transaction.commit()
except:
transaction.rollback()
raise
@db_transaction.inject
def update_user(transaction, user_id: int, data: dict):
transaction.execute("UPDATE users SET ...", data)
# Must be wrapped in ensure() to properly manage the context
@db_transaction.ensure
def main():
update_user(123, {"name": "New Name"})
The library provides utilities for mocking dependencies in tests:
@dependency
def current_time() -> float:
return time.time()
# In tests
with current_time.fake_value(1234567890.0):
assert get_timestamp() == 1234567890.0
@dependency
def random_id() -> str:
return str(uuid.uuid4())
@random_id.faker
def fixed_id():
return "test-id-123"
# In tests
with fixed_id():
assert create_resource().id == "test-id-123"
To create singleton dependencies that are cached for the lifetime of the program:
from functools import cache
@dependency
@cache
def config():
return load_config_from_file()
The library leverages Python's type hints to ensure type safety:
@dependency
def logger() -> Logger:
return Logger()
@logger.inject
def process_data(logger: Logger, data: dict) -> None:
logger.info(f"Processing {data}") # Type-checked by your IDE/mypy
@cache
for expensive-to-create dependencies that can be reusedensure()
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
A lightweight, intuitive dependency injection library for Python that makes testing and dependency management a breeze.
We found that diwrappers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.