Skip to content

Commit d1b4f6c

Browse files
committed
Improve documentation
1 parent 49c0e2e commit d1b4f6c

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@ python-hosts
33
[![codecov](https://codecov.io/gh/jonhadfield/python-hosts/branch/devel/graph/badge.svg)](https://codecov.io/gh/jonhadfield/python-hosts) [![Docs](https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat)](http://python-hosts.readthedocs.org/en/latest/)
44

55

6-
This 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.
9-
It remains compatible with Python 2.7 as well as modern Python 3 releases.
6+
`python-hosts` is a small Python library for reading and writing hosts files.
7+
It provides a simple API for adding or removing entries as well as importing
8+
records from another file or a remote URL. The package has no heavy
9+
dependencies and works on Linux, macOS and Windows.
10+
11+
It remains compatible with Python 2.7 in addition to modern Python 3 releases.
12+
13+
Features
14+
--------
15+
* Add, remove or merge host entries programmatically.
16+
* Import entries from a plain text file or from a URL.
17+
* Works across platforms by automatically selecting the correct hosts file
18+
location.
19+
* Python 2.7 and Python 3.5+ support.
1020

1121
Documentation
1222
-------------
@@ -20,7 +30,7 @@ Installation
2030
pip install python-hosts
2131

2232
Example usage
23-
------------
33+
-------------
2434
Adding an entry to a hosts file
2535

2636
from python_hosts import Hosts, HostsEntry
@@ -36,6 +46,13 @@ Importing a list of host entries by URL
3646
hosts.import_url(url='https://gist.githubusercontent.com/jonhadfield/5b6cdf853ef629f9b187345d89157280/raw/ddfa4a069fb12bf3c1f285249d44922aeb75db3f/hosts')
3747
hosts.write()
3848

49+
Importing entries from another file
50+
51+
from python_hosts import Hosts
52+
hosts = Hosts(path='hosts_test')
53+
hosts.import_file(import_file_path='other_hosts')
54+
hosts.write()
55+
3956
CLI
4057
---
4158
A command line client using python-hosts can be found here: https://github.com/jonhadfield/hostman
@@ -46,6 +63,14 @@ Requirements
4663

4764
Tested on Python 2.7 and Python 3.5+, including PyPy variants
4865

66+
Running tests
67+
-------------
68+
Install the development requirements and run::
69+
70+
pip install -r test-requirements.txt
71+
pytest
72+
73+
4974

5075
License
5176
-------

docs/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
python hosts
33
============
44

5-
A python library for managing a hosts file.
5+
A Python library for managing hosts files. It can add or remove entries and
6+
import records from other files or remote URLs.
67

78

89
Getting started
@@ -13,6 +14,7 @@ Getting started
1314

1415
installation
1516
usage
17+
../CHANGELOG
1618

1719

1820
API

docs/usage.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,17 @@ Usage
2121
**Write entries**::
2222

2323
my_hosts.write()
24+
25+
**Import entries from a URL**::
26+
27+
from python_hosts import Hosts
28+
my_hosts = Hosts(path='hosts_test')
29+
my_hosts.import_url(url='https://example.com/hosts')
30+
my_hosts.write()
31+
32+
**Import entries from another file**::
33+
34+
from python_hosts import Hosts
35+
my_hosts = Hosts(path='hosts_test')
36+
my_hosts.import_file(import_file_path='other_hosts')
37+
my_hosts.write()

0 commit comments

Comments
 (0)