skillfed

selinux

shim selinux module

selinux v0.3.0 1.8M downloads/30d#3,583 on PyPI19
Permissive license MIT license Active released

What it is and what it does

This package is a workaround for a specific virtualenv limitation: selinux normally cannot be imported from inside isolated Python environments even when the system library is installed. The selinux shim bridges that gap by providing a pure-Python wrapper that allows code running in a virtualenv to import selinux.

The shim requires that libselinux Python bindings be present on the host system—it does not replace them, only makes them accessible from within a virtualenv. It has been tested to work both inside, outside virtualenvs without interfering with the original library. The package depends only on distro for runtime operation, supports Python 3.9 or later.

Use it for:

  • Importing selinux in isolated Python environments for system administration tasks
  • Testing or developing tools that depend on selinux in a containerized or virtualenv-based CI/CD pipeline
  • Running code that requires selinux from within a virtualenv without system-level workarounds

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides a pure-Python shim for the selinux module that works inside virtualenvs, allowing tools to import selinux without requiring system-level virtualenv configuration.

Yes, if you need to use selinux from inside a virtualenv. The package solves a specific problem with minimal dependencies, no security issues, active maintenance status. The gap since the latest release is a minor concern, but the package remains actively maintained, marked Production/Stable. Install only if you encounter the virtualenv selinux import problem.

Install

selinux on PyPI

pip

pip install selinux

uv

uv add selinux

poetry

poetry add selinux

Installing selinux

Before you install

Low install friction with a single runtime dependency (distro). The package is actively maintained with recent commits, though the latest release was over three years ago; it remains marked as Production/Stable with support for current Python versions.

License in practice

MIT license permits unrestricted use, modification, in both open-source, proprietary projects with minimal obligations.

Quickstart

pip install selinux
import selinux

libselinux Python bindings must be installed on the system; the shim bridges access to them from within a virtualenv.

Verify before relying

  • Whether the shim works with all selinux functions or only a subset of the API
  • Whether it works with selinux versions other than those tested at release time
  • Compatibility with Ansible modules specifically

Package facts

License MIT license (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies 1 — distro
Maintenance actively maintained — 1,329 days since the last release
Last repo commit
First released
Downloads 1,761,246/month — #3,583 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: selinux-0.3.0-py2.py3-none-any.whl

Keywords: selinux, virtualenv

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: System AdministratorsLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.9Topic :: System :: Systems AdministrationTopic :: Utilities

Tags

selinux virtualenv importselinux python shimvirtualenv selinux compatibilityisolated environment selinuxselinux module wrapper
selinuxvirtualenv-compat

More Utilities packages