
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
conditional
Advanced tools
conditional(condition, contextmanager) Enter contextmanager only if condition is true.
The conditional context manager comes handy when you always want to
execute a with-block but only conditionally want to apply its context
manager.
If you find yourself writing code like this:
.. code-block:: python
if CONDITION:
with CONTEXTMANAGER():
BODY()
else:
BODY()
Consider replacing it with:
.. code-block:: python
with conditional(CONDITION, CONTEXTMANAGER()):
BODY()
conditional supports asynchronous context managers:
.. code-block:: python
async with conditional(CONDITION, ASYNCCONTEXTMANAGER()):
BODY()
The package ships with type annotations. Type checkers and IDEs can use this information to implement type safety and auto completion.
Say we want to ignore signals when a pager application is in the foreground, but not otherwise:
.. code-block:: python
from conditional import conditional
with conditional(has_pager(cmd), ignoresignals()):
os.system(cmd)
For further details please refer to the API Documentation_.
.. _API Documentation: https://conditional.readthedocs.io/en/stable/
Support asynchronous context managers. Thanks to Dawid Wolski. [stefan]
Require Python >= 3.5. [stefan]
Add type annotations to the context manager. [stefan]
Update tox.ini for latest tox. [stefan]
Add GitHub CI workflow. [stefan]
Add .readthedocs.yaml file. [stefan]
Pin sphinx and sphinx-rtd-theme versions in docs extra. [stefan]
Add mypy extra which installs mypy. [stefan]
Add Python 3.8-3.10 to tox.ini. Remove old Python versions. [stefan]
Replace deprecated python setup.py test in tox.ini.
[stefan]
Remove deprecated test_suite and tests_require from setup.py.
[stefan]
Move metadata to setup.cfg and add a pyproject.toml file. [stefan]
Include tests in sdist but not in wheel. [stefan]
Add MANIFEST.in. [stefan]
Release as wheel. [stefan]
Support Python 2.6-3.6 without 2to3. [stefan]
Add a LICENSE file. [stefan]
FAQs
Conditionally enter a context manager
We found that conditional 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.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.