python-hosts
A hosts file manager library written in python
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-hostsuv
uv add python-hostspoetry
poetry add python-hostsInstalling 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
Tags
More Networking packages
h11 is a pure-Python HTTP/1.1 protocol…
permissive · top 100 on PyPI
psutilpsutil retrieves real-time information about…
permissive · top 1,000 on PyPI
pyOpenSSLpyOpenSSL wraps OpenSSL's SSL/TLS functionality…
permissive · top 1,000 on PyPI
uvloopuvloop is a drop-in replacement for Python's…
permissive · top 1,000 on PyPI
execnetexecnet lets you spawn and communicate with…
permissive · top 1,000 on PyPI
pyzmqPyZMQ provides Python bindings for ZeroMQ…
permissive · top 1,000 on PyPI
aiodiscoverDiscovers hosts on a local network by…
permissive · top 15,000 on PyPI
netaddrRepresents and manipulates IPv4, IPv6, MAC…
permissive · top 5,000 on PyPI
ipaddressProvides IPv4 and IPv6 address manipulation for…
permissive · top 5,000 on PyPI
contentful_managementPython client for Contentful's Management API,…
permissive · top 15,000 on PyPI
IP2LocationLooks up geolocation data (country, region,…
permissive · top 15,000 on PyPI
ipaddrProvides utilities for parsing, validating, and…
permissive · top 15,000 on PyPI
multipingMultiPing sends ICMP echo requests (pings) to…
permissive · top 15,000 on PyPI
dnslibEncodes and decodes DNS wire-format packets,…
permissive · top 5,000 on PyPI
icmplibicmplib provides a pure Python implementation…
copyleft · top 5,000 on PyPI
IPyIPy provides Python classes for parsing,…
permissive · top 5,000 on PyPI