$npx skillfedfor your agent

conditional

Conditionally enter a context manager

Worth itPyPI Software DevelopmentReleased Jul 2026233.6K downloads / moBSD-2-ClausePure Python

Decision gist · record as of 2026-08-14

pure-Python wheel — conditional-2.2-py3-none-any.whl
v2.2 · released 2026-07-04 · Python >=3.5

Yes. This is a stable, actively maintained, zero-dependency utility that solves a genuine code-organization problem. If you write context managers and find yourself duplicating code blocks to conditionally apply them, conditional eliminates that duplication cleanly. The permissive license and type annotations add no friction.AI-flagged interpretation of the facts on this page — verify before relying

Before you install

  • Requires Python >= 3.5.
  • Low friction: pure Python wheel with no runtime dependencies.
  • Active maintenance with a recent release (41 days ago) and an up-to-date repository.

License · maintenance · safety

BSD-2-Clause (permissive) — BSD-2-Clause is permissive; you can use this package freely in commercial or private projects with minimal restrictions.

last release 2026-07-04 (41 days) · last repo commit 2026-08-07 · 10 stars

0 known vulnerabilities (OSV.dev, 2026-08-14) · 233,637 downloads/mo, #9,036 on PyPI

Verify before relying

from conditional import conditional

with conditional(some_condition, my_context_manager()):
    # body executes regardless; context manager applied only if some_condition is True
    do_work()
Same gist for agents: .md · .json

What it is and what it does

conditional is a lightweight context manager that wraps another context manager and enters it only when a condition is true, while always executing the body of the with-block. Instead of writing separate if/else branches with duplicated code—one branch with the context manager and one without—you pass a boolean condition and the context manager to conditional, and it handles the logic.

The package supports both synchronous and asynchronous context managers, includes full type annotations for IDE and type-checker support, and has no external dependencies. It is stable (Development Status 5), actively maintained, and suitable for any code path where you want to conditionally apply resource management, signal handling, or other context-dependent setup without code duplication.

Use it for

  • Conditionally suppress signals or exceptions in a code block depending on runtime state.
  • Apply a database transaction context manager only when needed, executing the same code path either way.
  • Optionally enable timing or profiling instrumentation around a block based on a debug flag.
  • Conditionally acquire a lock or semaphore depending on whether concurrent access is expected.
  • Skip file-locking or temporary-directory setup in certain execution modes while keeping the main logic unified.

Worth the install?

AI-flagged interpretation of the facts on this page. Verify before relying on it.

Worth it

Yes.

This is a stable, actively maintained, zero-dependency utility that solves a genuine code-organization problem. If you write context managers and find yourself duplicating code blocks to conditionally apply them, conditional eliminates that duplication cleanly. The permissive license and type annotations add no friction.

Install

conditional on PyPI

Before you install

Low friction: pure Python wheel with no runtime dependencies. Active maintenance with a recent release (41 days ago) and an up-to-date repository.

Requires Python >= 3.5.

License in practice

BSD-2-Clause is permissive; you can use this package freely in commercial or private projects with minimal restrictions.

Quickstart

from conditional import conditional

with conditional(some_condition, my_context_manager()):
    # body executes regardless; context manager applied only if some_condition is True
    do_work()

Package facts

LicenseBSD-2-Clause permissive
Python supportSupports the current Python release >=3.5
Install frictionLow. Pure-Python wheel
Runtime dependenciesNone
MaintenanceActively maintained 41 days since the last release
Last repo commit
First released
Downloads233,637 / month, #9,036 on PyPI 30-day window, as of 2026-08-14
Known vulnerabilitiesNone known OSV.dev, checked 2026-08-14
Classifiers
Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Typing :: Typed

Evidence: conditional-2.2-py3-none-any.whl

Tags

Capabilities
conditional context manageroptional context managercontext manager if conditionconditional with statementasync context manager conditionalskip context manager based on conditioncontext manager wrapper
Topics
context-managerasync-supporttyped
PyPI keywords
conditionalcontext managercontextmanagerwithasyncasync withenterexit

Let your AI agent find packages like this

Example. Real query, live index.

You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.

wish › “conditional context manager”

  • conditionalConditionally apply a context manager to a code block based on a…
  • async-timeoutProvides an asyncio-compatible timeout context manager for applying…
  • stubsProvides a context-manager syntax for temporarily replacing function…

Give your agent the search over MCP, or paste the wish link into any chat.

More Software Development packages

typing-extensions Worth it
PyPI · Software Development · released Jul 2026

Provides backported and experimental type hints for Python 3.9+, allowing use of newer typing features on older Python versions and enabling early experimentation with type system PEPs before they enter the standard library.

PSF-2.0pure Python · 3.9+
1.9Bdownloads / mo
numpy Worth it
PyPI · Software Development · released Aug 2026

NumPy provides an N-dimensional array object and a comprehensive suite of mathematical, linear algebra, Fourier transform, and random number functions for scientific computing in Python.

BSD-3-Clause AND 0BSD AND MIT AND Zlib AND CC0-1.0compiled wheel · 3.12+
1.1Bdownloads / mo
fastapi Worth it
PyPI · Software Development · released Jul 2026

FastAPI is a Python web framework for building REST APIs using type hints, with automatic request validation, serialization, and interactive API documentation.

MITpure Python · 3.10+
568.6Mdownloads / mo
annotated-doc With conditions
PyPI · Software Development · released Jul 2026

Provides a way to document function parameters, class attributes, return types, and variables inline using Python's `Annotated` type hint syntax instead of traditional docstrings.

MITpure Python · 3.9+
456.2Mdownloads / mo
typer Worth it
PyPI · Software Development · released Aug 2026

Typer builds command-line applications from Python functions using type hints, automatically generating help text, argument parsing, and shell completion.

Install it if you are building CLIs in Python.

MITpure Python · 3.10+
369.3Mdownloads / mo
distlib With conditions
PyPI · Software Development · released Jun 2026

Distlib provides low-level packaging utilities for building, distributing, and managing Python software—including metadata handling, version specifiers, wheel support, script installation, and dependency resolution.

permissive licensepure Python
323.3Mdownloads / mo

See also coverage-conditional-plugin · enum-compat · pytest-skip-markers · pytest-enabler · codemod-tox · rest_condition · stubs · contextvars · stopit · mypy-strict-kwargs