{"id":21824,"library":"python-iptables","title":"python-iptables","description":"Python bindings for iptables, providing a Pythonic interface to manipulate Linux netfilter rules. Currently at v1.2.0, with infrequent releases and limited maintenance.","status":"maintenance","version":"1.2.0","language":"python","source_language":"en","source_url":"https://github.com/ldx/python-iptables","tags":["iptables","netfilter","firewall","linux"],"install":[{"cmd":"pip install python-iptables","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Requires iptables binaries installed on the system.","package":"iptables","optional":false}],"imports":[{"note":"The library uses the alias 'iptc' (short for iptables C bindings).","wrong":"from iptables import Table","symbol":"Table","correct":"from iptc import Table"}],"quickstart":{"code":"import os\nfrom iptc import Table, Chain, Rule, Match, Target\n\ntable = Table(Table.FILTER)\nfor chain in table.chains:\n    print(f\"Chain {chain.name}\")\n    for rule in chain.rules:\n        print(f\"  Rule: {rule.src} -> {rule.dst}\")","lang":"python","description":"List all rules in the FILTER table. Run as root."},"warnings":[{"fix":"Run script with sudo or set capabilities on Python interpreter.","message":"Must be run as root (or with CAP_NET_ADMIN). Non-root users will get permissions error.","severity":"breaking","affected_versions":"all"},{"fix":"Use python-nftables or subprocess calls to iptables-legacy.","message":"No longer maintained; last release 1.2.0 (2020). Consider alternatives like nftables for new projects.","severity":"deprecated","affected_versions":">=1.0"},{"fix":"After modifying rules/flushing chain, call table.commit().","message":"Table.commit() must be called to apply rule changes. Forgetting it leaves rules unapplied.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run with sudo: sudo python script.py","cause":"Script not run as root; iptables requires root privileges.","error":"PermissionError: [Errno 1] Operation not permitted"},{"fix":"Use 'from iptc import Table' instead of 'import iptables'.","cause":"Wrong import; the correct module is iptc, not iptables.","error":"AttributeError: module 'iptc' has no attribute 'Table'"},{"fix":"Ensure chain exists (e.g., from table.chains) or create chain first.","cause":"Chain object is None because chain name does not exist or table was not flushed properly.","error":"AttributeError: 'NoneType' object has no attribute 'append'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}