skillfed

python-hosts

A hosts file manager library written in python

python-hosts v1.1.2 184.1K downloads/30d#10,046 on PyPI133
Permissive license MIT AGING released

What it is and what it does

python-hosts is a library for programmatic manipulation of the system hosts file. It lets you create, add, remove, and query hostname-to-IP mappings without manually editing the file, and supports importing entries from files or URLs. The library has no runtime dependencies and works as a pure Python module.

It's designed for system administrators and automation scripts that need to manage network hostname resolution at the OS level. You instantiate a Hosts object pointing to a hosts file, manipulate entries using HostsEntry objects, and write changes back to disk. The package remains compatible with Python 2.7 and modern Python 3 releases, though it has not seen a release in over a year.

Use it for:

  • Automate adding or removing hostname entries in CI/CD pipelines or deployment scripts.
  • Bulk import hosts from a remote URL or file to synchronize local DNS resolution.
  • Query the hosts file programmatically to check if a hostname or IP already exists before making changes.
  • Merge new hostname aliases with existing entries without overwriting the entire hosts file.

Worth the install?

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

Manages hosts file entries programmatically—add, remove, import, and query IP-to-hostname mappings without manual file editing.

Yes, if you need programmatic hosts file management. The package is stable (Production/Stable status), has no dependencies, and carries a permissive MIT license. However, the aging maintenance status (416 days since last release) means you should verify compatibility with your Python version before relying on it for critical automation.

Install

python-hosts on PyPI

pip

pip install python-hosts

uv

uv add python-hosts

poetry

poetry add python-hosts

Installing python-hosts

Before you install

Low install friction with no runtime dependencies. Maintenance status is aging—last release was 416 days ago, though the repository remains active with a recent commit on 2025-08-11.

License in practice

MIT license (permissive) means you can use, modify, and distribute this package freely with minimal restrictions.

Quickstart

pip install python-hosts

from python_hosts import Hosts, HostsEntry
hosts = Hosts(path='hosts_test')
entry = HostsEntry(entry_type='ipv4', address='1.2.3.4', names=['www.example.com'])
hosts.add([entry])
hosts.write()

Verify before relying

  • Whether the package still works reliably on modern Python 3 versions given the aging maintenance status and lack of explicit requires_python specification.

Package facts

License MIT (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance aging — 416 days since the last release
Last repo commit
First released
Downloads 184,078/month — #10,046 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: python_hosts-1.1.2-py2-none-any.whl

Keywords: hosts, python, network

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: System AdministratorsLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonTopic :: System :: NetworkingTopic :: System :: Operating System

Tags

hosts file managementadd remove hosts entrieshosts file parsernetwork hostname mappinghosts file automation
system-administrationnetwork-configuration

More Networking packages