Registry / devops / python-iptables

python-iptables

JSON →
library1.2.0pypypi✓ verified 87d ago

Python bindings for iptables, providing a Pythonic interface to manipulate Linux netfilter rules. Currently at v1.2.0, with infrequent releases and limited maintenance.

pip install python-iptables
INSTALL
IMPORT
SIG · PYTHON-IPTABLES
P
python-iptables
devopspythonv1.2.0
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Table
from iptc import Table
from iptables import Table
The library uses the alias 'iptc' (short for iptables C bindings).

List all rules in the FILTER table. Run as root.

import os from iptc import Table, Chain, Rule, Match, Target table = Table(Table.FILTER) for chain in table.chains: print(f"Chain {chain.name}") for rule in chain.rules: print(f" Rule: {rule.src} -> {rule.dst}")
Debug
Known issues
breakingMust be run as root (or with CAP_NET_ADMIN). Non-root users will get permissions error.
fix
Run script with sudo or set capabilities on Python interpreter.
affects: all
deprecatedNo longer maintained; last release 1.2.0 (2020). Consider alternatives like nftables for new projects.
fix
Use python-nftables or subprocess calls to iptables-legacy.
affects: >=1.0
gotchaTable.commit() must be called to apply rule changes. Forgetting it leaves rules unapplied.
fix
After modifying rules/flushing chain, call table.commit().
affects: all
Errors
Common errors & fixes
PermissionError: [Errno 1] Operation not permitted
Script not run as root; iptables requires root privileges.
fix
Run with sudo: sudo python script.py
AttributeError: module 'iptc' has no attribute 'Table'
Wrong import; the correct module is iptc, not iptables.
fix
Use 'from iptc import Table' instead of 'import iptables'.
AttributeError: 'NoneType' object has no attribute 'append'
Chain object is None because chain name does not exist or table was not flushed properly.
fix
Ensure chain exists (e.g., from table.chains) or create chain first.
Upgrade
Version history
1.2.0latest on PyPI · released Apr 6, 2025
Audit
Dependencies
iptablesrequiredRequires iptables binaries installed on the system.
Agent activity
7 hits · last 30 days
node
6
Resources
python-iptables — pip install python-iptables · libregistry