@@ -4,8 +4,9 @@ python-hosts
44
55
66This is a python library for managing a hosts file.
7- It enables you to add and remove entries, or import them from a file or URL.
8- Utility functions have been streamlined for easier maintenance.
7+ It enables you to add and remove entries, import them from a file or URL and
8+ query existing entries. Utility functions have been streamlined for easier
9+ maintenance.
910It remains compatible with Python 2.7 as well as modern Python 3 releases.
1011
1112Documentation
@@ -21,21 +22,30 @@ pip install python-hosts
2122
2223Example usage
2324------------
24- Adding an entry to a hosts file
25+ Create a `` Hosts `` instance and add an entry::
2526
2627 from python_hosts import Hosts, HostsEntry
2728 hosts = Hosts(path='hosts_test')
2829 new_entry = HostsEntry(entry_type='ipv4', address='1.2.3.4', names=['www.example.com', 'example'])
2930 hosts.add([new_entry])
3031 hosts.write()
3132
32- Importing a list of host entries by URL
33+ Import entries from a URL or file::
3334
34- from python_hosts import Hosts
35- hosts = Hosts(path='hosts_test')
36- hosts.import_url(url='https://gist.githubusercontent.com/jonhadfield/5b6cdf853ef629f9b187345d89157280/raw/ddfa4a069fb12bf3c1f285249d44922aeb75db3f/hosts')
35+ hosts.import_url('https://example.com/hosts')
36+ hosts.import_file('extra_hosts')
3737 hosts.write()
3838
39+ Remove or query entries::
40+
41+ hosts.remove_all_matching(name='example')
42+ hosts.exists(address='1.2.3.4')
43+
44+ Entries can also be merged with existing ones::
45+
46+ new_entry = HostsEntry(entry_type='ipv4', address='1.2.3.4', names=['alias'])
47+ hosts.add([new_entry], merge_names=True)
48+
3949CLI
4050---
4151A command line client using python-hosts can be found here: https://github.com/jonhadfield/hostman
0 commit comments