Metadata-Version: 2.1
Name: hosts-resolver
Version: 1.1.0
Summary: Zero-dependency Python module to resolve names using /etc/hosts alone
Author-email: Samuel FORESTIER <dev+hostsresolver@samuel.domains>
License: MIT
Project-URL: Repository, https://git.forestier.app/HorlogeSkynet/hosts_resolver
Keywords: DNS,gethostent,hosts
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: POSIX :: BSD
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Internet :: Name Service (DNS)
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE

# hosts_resolver

> Zero-dependency Python module to resolve names using /etc/hosts alone

## Rationale

Sometimes we only want to resolve names using /etc/hosts entries without performing DNS requests (thus `socket.getaddrinfo` is out of the equation).

So there are three options :

* manually parse /etc/hosts
* call `getent` program and parse its output
* use this module (which binds libc `gethostent` function) !

## Limitations

- `gethostent` is not reentrant (see GETHOSTBYNAME(3))
- `gethostent` is not thread-safe (see GETHOSTBYNAME(3))
- glibc implementations does not support IPv6 addresses (see GETHOSTBYNAME(3))
- behavior is **undefined** when using multiple context managers simultaneously

## Installation

```bash
pip3 install --index-url https://git.forestier.app/api/packages/HorlogeSkynet/pypi/simple/ hosts-resolver

# or manually download latest Wheel and then :
pip3 install ./hosts_resolver-*-py3-none-any.whl
```

## Usage

### From API

```python
from hosts_resolver.hosts_resolver import get_hosts_resolver

with get_hosts_resolver() as hosts_resolver:
    print(hosts_resolver.resolve("localhost"))

# -> IPv4Address('127.0.0.1')
```

### From CLI

> Why bother ?? You should be looking at `getent` !

```bash
hosts_resolver -j localhost
# -> {"localhost": "127.0.0.1"}
```

## Development

```bash
pip3 install -r requirements-dev.txt

pylint src/
mypy src/
isort --check src/
black --check src/

python3 -m build
```
