iplib3


Nameiplib3 JSON
Version 0.2.4 PyPI version JSON
download
home_pagehttps://pypi.org/project/iplib3/
SummaryA modern, object-oriented approach to IP addresses.
upload_time2023-09-18 16:15:21
maintainerLari Liuhamo
docs_urlNone
authorLari Liuhamo
requires_python>=3.9.0,<4.0.0
licenseMIT
keywords network networking ip ipaddress address python3 pathlib
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # IPLib3

A `pathlib.Path`-equivalent for IP addresses.

|              |   |
|--------------|---|
| PyPI         | ![Python versions](https://img.shields.io/pypi/pyversions/iplib3?logo=python) ![PyPI - Implementation](https://img.shields.io/pypi/implementation/iplib3) ![Wheel](https://img.shields.io/pypi/wheel/iplib3?logo=pypi) ![Downloads](https://img.shields.io/pypi/dm/iplib3?logo=pypi) [![Version](https://img.shields.io/pypi/v/iplib3)](https://pypi.org/project/iplib3/) |
| Tests (main) | [![codecov](https://codecov.io/gh/Diapolo10/iplib3/branch/main/graph/badge.svg?token=JUWGSVLIF3)](https://codecov.io/gh/Diapolo10/iplib3) ![Unit tests](https://github.com/diapolo10/iplib3/workflows/Unit%20tests/badge.svg) ![Pylint](https://github.com/diapolo10/iplib3/workflows/Pylint/badge.svg) ![Flake8](https://github.com/diapolo10/iplib3/workflows/Flake8/badge.svg) ![Deploy to PyPI](https://github.com/diapolo10/iplib3/workflows/Deploy%20to%20PyPI/badge.svg) |
| Tests (nightly) | [![codecov](https://codecov.io/gh/Diapolo10/iplib3/branch/nightly/graph/badge.svg?token=JUWGSVLIF3)](https://codecov.io/gh/Diapolo10/iplib3/branch/nightly) ![Unit tests](https://github.com/diapolo10/iplib3/workflows/Unit%20tests/badge.svg?branch=nightly) ![Pylint](https://github.com/diapolo10/iplib3/workflows/Pylint/badge.svg?branch=nightly) ![Flake8](https://github.com/diapolo10/iplib3/workflows/Flake8/badge.svg?branch=nightly) ![Deploy to PyPI](https://github.com/diapolo10/iplib3/workflows/Deploy%20to%20PyPI/badge.svg?branch=nightly) |
| Docs         | [![Documentation Status](https://readthedocs.org/projects/iplib3/badge/?version=latest)](https://iplib3.readthedocs.io/en/latest/?badge=latest) |
| Activity     | ![GitHub contributors](https://img.shields.io/github/contributors/diapolo10/iplib3) ![Last commit](https://img.shields.io/github/last-commit/diapolo10/iplib3?logo=github) ![GitHub all releases](https://img.shields.io/github/downloads/diapolo10/iplib3/total?logo=github) ![GitHub issues](https://img.shields.io/github/issues/diapolo10/iplib3) ![GitHub closed issues](https://img.shields.io/github/issues-closed/diapolo10/iplib3) ![GitHub pull requests](https://img.shields.io/github/issues-pr/diapolo10/iplib3) ![GitHub closed pull requests](https://img.shields.io/github/issues-pr-closed/diapolo10/iplib3) |
| QA           | [![CodeFactor](https://www.codefactor.io/repository/github/diapolo10/iplib3/badge?logo=codefactor)](https://www.codefactor.io/repository/github/diapolo10/iplib3) [![Rating](https://img.shields.io/librariesio/sourcerank/pypi/iplib3)](https://libraries.io/github/Diapolo10/iplib3/sourcerank) |
| Other        | [![License](https://img.shields.io/github/license/diapolo10/iplib3)](https://opensource.org/licenses/MIT) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FDiapolo10%2Fiplib3.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FDiapolo10%2Fiplib3?ref=badge_shield) [![Requirements Status](https://requires.io/github/Diapolo10/iplib3/requirements.svg?branch=nightly)](https://requires.io/github/Diapolo10/iplib3/requirements/?branch=nightly) ![Repository size](https://img.shields.io/github/repo-size/diapolo10/iplib3?logo=github) ![Code size](https://img.shields.io/github/languages/code-size/diapolo10/iplib3?logo=github) ![Lines of code](https://img.shields.io/tokei/lines/github/diapolo10/iplib3?logo=github) |

This module was heavily inspired by the built-in `pathlib` module to provide a similar, flexible interface for IP addresses. `iplib3` can effortlessly convert between IPv4, IPv6, raw numbers and hex values and it can also verify IP address syntax. It can recognise optional port numbers and store them separately from the main address. The `iplib.IPAddress` class works like `pathlib.Path` in that it accepts both IPv4 and IPv6 addresses, returning an object representing whichever format was used. The module also uses some unit tests, and these will be added more over time as functionality grows and becomes more set in stone.

The module is currently lacking in long-term vision as I used it as a practice project, but there are some plans to further flesh it out. It could incorporate URL support in the future and may be extended with `requests` integration.

This project is not affiliated with `iplib`, the naming similarity is merely a coincidence.

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FDiapolo10%2Fiplib3.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FDiapolo10%2Fiplib3?ref=badge_large)

## Installation

`iplib3` will work with Python versions 3.6 and above. It could be back-ported to 3.5 or for even earlier versions with relatively little change, but the maintainer doesn't see a good reason to focus on earlier versions.

This module will not support Python 2.

Use the package manager [`pip`](https://pip.pypa.io/en/stable/) to install `iplib3`.

On Windows:

```sh
py -m pip install iplib3
```

On most Unix-like platforms:

```sh
pip3 install iplib3
```

On other platforms, you may try:

```sh
pip install iplib3
```

The library is distributed as wheels and source distributions, and the source distributions use Poetry as the build back-end instead of `setuptools`.

## Usage

The module mainly provides a single class, `iplib3.IPAddress`, which can be used to initialise IP address objects of any supported type. However, it is possible to use the provided `iplib3.IPv4` and `iplib3.IPv6` classes directly if needed.

The primary class has the advantage that it also supports raw numbers; you can initialise it with any positive integer in addition to stringified addresses, and since you can directly convert between the two sub-classes at any time you can use all functionality with just `iplib3.IPAddress`. Since `iplib3.IPv4` and `iplib3.IPv6` are subclasses of `iplib3.IPAddress`, you can use `isinstance` to recognise any of the three types.

Some basic usage examples:

```python
from iplib3 import IPAddress, IPv6

address = IPAddress('222.173.190.239')
print(address) # 222.173.190.239

print(address.port) # None, because we never specified one
address.port = 80
print(address) # 222.173.190.239:80

print(repr(address)) # iplib3.IPv4('222.173.190.239:80')


ipv6_address = address.as_ipv6
print(ipv6_address) # [0:0:0:0:0:0:DEAD:BEEF]:80
ipv6_address.port = None
print(ipv6_address) # 0:0:0:0:0:0:DEAD:BEEF

print(repr(ipv6_address)) # iplib3.IPv6('0:0:0:0:0:0:DEAD:BEEF')

foo = IPv6('[::1337:1337:1337:1337]:25565')
bar = IPv6('::1337:1337:1337:1337', 25565)
baz = IPv6('::1337:1337:1337:1337', port_num=25565)

print(f"Addresses are {'equal' if foo == bar == baz else 'not equal'}")
print(baz) # [::1337:1337:1337:1337]:25565

print(baz.as_ipv4.as_ipv6 == baz)

# If the string contains a port number and you also provide a port separately,
# then the separately provided port takes precedence
spam = IPv6('[::1337:1337:1337:1337]:80', port_num=25565)
print(spam) # [::1337:1337:1337:1337]:25565

print(address.hex) # 0xDEADBEEF
print(address.num) # 3735928559
```

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

## License

This project is licensed under an [MIT license](./LICENSE).

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FDiapolo10%2Fiplib3.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FDiapolo10%2Fiplib3?ref=badge_large)

            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/iplib3/",
    "name": "iplib3",
    "maintainer": "Lari Liuhamo",
    "docs_url": null,
    "requires_python": ">=3.9.0,<4.0.0",
    "maintainer_email": "lari.liuhamo+pypi@gmail.com",
    "keywords": "network,networking,ip,ipaddress,address,python3,pathlib",
    "author": "Lari Liuhamo",
    "author_email": "lari.liuhamo+pypi@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b4/49/2358cdcc3c099a2c945e5d749eb4c045f22a33df26715a47af50f3a4b7ea/iplib3-0.2.4.tar.gz",
    "platform": null,
    "description": "# IPLib3\n\nA `pathlib.Path`-equivalent for IP addresses.\n\n|              |   |\n|--------------|---|\n| PyPI         | ![Python versions](https://img.shields.io/pypi/pyversions/iplib3?logo=python) ![PyPI - Implementation](https://img.shields.io/pypi/implementation/iplib3) ![Wheel](https://img.shields.io/pypi/wheel/iplib3?logo=pypi) ![Downloads](https://img.shields.io/pypi/dm/iplib3?logo=pypi) [![Version](https://img.shields.io/pypi/v/iplib3)](https://pypi.org/project/iplib3/) |\n| Tests (main) | [![codecov](https://codecov.io/gh/Diapolo10/iplib3/branch/main/graph/badge.svg?token=JUWGSVLIF3)](https://codecov.io/gh/Diapolo10/iplib3) ![Unit tests](https://github.com/diapolo10/iplib3/workflows/Unit%20tests/badge.svg) ![Pylint](https://github.com/diapolo10/iplib3/workflows/Pylint/badge.svg) ![Flake8](https://github.com/diapolo10/iplib3/workflows/Flake8/badge.svg) ![Deploy to PyPI](https://github.com/diapolo10/iplib3/workflows/Deploy%20to%20PyPI/badge.svg) |\n| Tests (nightly) | [![codecov](https://codecov.io/gh/Diapolo10/iplib3/branch/nightly/graph/badge.svg?token=JUWGSVLIF3)](https://codecov.io/gh/Diapolo10/iplib3/branch/nightly) ![Unit tests](https://github.com/diapolo10/iplib3/workflows/Unit%20tests/badge.svg?branch=nightly) ![Pylint](https://github.com/diapolo10/iplib3/workflows/Pylint/badge.svg?branch=nightly) ![Flake8](https://github.com/diapolo10/iplib3/workflows/Flake8/badge.svg?branch=nightly) ![Deploy to PyPI](https://github.com/diapolo10/iplib3/workflows/Deploy%20to%20PyPI/badge.svg?branch=nightly) |\n| Docs         | [![Documentation Status](https://readthedocs.org/projects/iplib3/badge/?version=latest)](https://iplib3.readthedocs.io/en/latest/?badge=latest) |\n| Activity     | ![GitHub contributors](https://img.shields.io/github/contributors/diapolo10/iplib3) ![Last commit](https://img.shields.io/github/last-commit/diapolo10/iplib3?logo=github) ![GitHub all releases](https://img.shields.io/github/downloads/diapolo10/iplib3/total?logo=github) ![GitHub issues](https://img.shields.io/github/issues/diapolo10/iplib3) ![GitHub closed issues](https://img.shields.io/github/issues-closed/diapolo10/iplib3) ![GitHub pull requests](https://img.shields.io/github/issues-pr/diapolo10/iplib3) ![GitHub closed pull requests](https://img.shields.io/github/issues-pr-closed/diapolo10/iplib3) |\n| QA           | [![CodeFactor](https://www.codefactor.io/repository/github/diapolo10/iplib3/badge?logo=codefactor)](https://www.codefactor.io/repository/github/diapolo10/iplib3) [![Rating](https://img.shields.io/librariesio/sourcerank/pypi/iplib3)](https://libraries.io/github/Diapolo10/iplib3/sourcerank) |\n| Other        | [![License](https://img.shields.io/github/license/diapolo10/iplib3)](https://opensource.org/licenses/MIT) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FDiapolo10%2Fiplib3.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FDiapolo10%2Fiplib3?ref=badge_shield) [![Requirements Status](https://requires.io/github/Diapolo10/iplib3/requirements.svg?branch=nightly)](https://requires.io/github/Diapolo10/iplib3/requirements/?branch=nightly) ![Repository size](https://img.shields.io/github/repo-size/diapolo10/iplib3?logo=github) ![Code size](https://img.shields.io/github/languages/code-size/diapolo10/iplib3?logo=github) ![Lines of code](https://img.shields.io/tokei/lines/github/diapolo10/iplib3?logo=github) |\n\nThis module was heavily inspired by the built-in `pathlib` module to provide a similar, flexible interface for IP addresses. `iplib3` can effortlessly convert between IPv4, IPv6, raw numbers and hex values and it can also verify IP address syntax. It can recognise optional port numbers and store them separately from the main address. The `iplib.IPAddress` class works like `pathlib.Path` in that it accepts both IPv4 and IPv6 addresses, returning an object representing whichever format was used. The module also uses some unit tests, and these will be added more over time as functionality grows and becomes more set in stone.\n\nThe module is currently lacking in long-term vision as I used it as a practice project, but there are some plans to further flesh it out. It could incorporate URL support in the future and may be extended with `requests` integration.\n\nThis project is not affiliated with `iplib`, the naming similarity is merely a coincidence.\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FDiapolo10%2Fiplib3.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FDiapolo10%2Fiplib3?ref=badge_large)\n\n## Installation\n\n`iplib3` will work with Python versions 3.6 and above. It could be back-ported to 3.5 or for even earlier versions with relatively little change, but the maintainer doesn't see a good reason to focus on earlier versions.\n\nThis module will not support Python 2.\n\nUse the package manager [`pip`](https://pip.pypa.io/en/stable/) to install `iplib3`.\n\nOn Windows:\n\n```sh\npy -m pip install iplib3\n```\n\nOn most Unix-like platforms:\n\n```sh\npip3 install iplib3\n```\n\nOn other platforms, you may try:\n\n```sh\npip install iplib3\n```\n\nThe library is distributed as wheels and source distributions, and the source distributions use Poetry as the build back-end instead of `setuptools`.\n\n## Usage\n\nThe module mainly provides a single class, `iplib3.IPAddress`, which can be used to initialise IP address objects of any supported type. However, it is possible to use the provided `iplib3.IPv4` and `iplib3.IPv6` classes directly if needed.\n\nThe primary class has the advantage that it also supports raw numbers; you can initialise it with any positive integer in addition to stringified addresses, and since you can directly convert between the two sub-classes at any time you can use all functionality with just `iplib3.IPAddress`. Since `iplib3.IPv4` and `iplib3.IPv6` are subclasses of `iplib3.IPAddress`, you can use `isinstance` to recognise any of the three types.\n\nSome basic usage examples:\n\n```python\nfrom iplib3 import IPAddress, IPv6\n\naddress = IPAddress('222.173.190.239')\nprint(address) # 222.173.190.239\n\nprint(address.port) # None, because we never specified one\naddress.port = 80\nprint(address) # 222.173.190.239:80\n\nprint(repr(address)) # iplib3.IPv4('222.173.190.239:80')\n\n\nipv6_address = address.as_ipv6\nprint(ipv6_address) # [0:0:0:0:0:0:DEAD:BEEF]:80\nipv6_address.port = None\nprint(ipv6_address) # 0:0:0:0:0:0:DEAD:BEEF\n\nprint(repr(ipv6_address)) # iplib3.IPv6('0:0:0:0:0:0:DEAD:BEEF')\n\nfoo = IPv6('[::1337:1337:1337:1337]:25565')\nbar = IPv6('::1337:1337:1337:1337', 25565)\nbaz = IPv6('::1337:1337:1337:1337', port_num=25565)\n\nprint(f\"Addresses are {'equal' if foo == bar == baz else 'not equal'}\")\nprint(baz) # [::1337:1337:1337:1337]:25565\n\nprint(baz.as_ipv4.as_ipv6 == baz)\n\n# If the string contains a port number and you also provide a port separately,\n# then the separately provided port takes precedence\nspam = IPv6('[::1337:1337:1337:1337]:80', port_num=25565)\nprint(spam) # [::1337:1337:1337:1337]:25565\n\nprint(address.hex) # 0xDEADBEEF\nprint(address.num) # 3735928559\n```\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n\nThis project is licensed under an [MIT license](./LICENSE).\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FDiapolo10%2Fiplib3.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FDiapolo10%2Fiplib3?ref=badge_large)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A modern, object-oriented approach to IP addresses.",
    "version": "0.2.4",
    "project_urls": {
        "Changelog": "https://github.com/Diapolo10/iplib3/blob/nightly/CHANGELOG.md",
        "Documentation": "https://github.com/Diapolo10/iplib3/tree/main/docs",
        "Homepage": "https://pypi.org/project/iplib3/",
        "Repository": "https://github.com/Diapolo10/iplib3",
        "Source code": "https://github.com/Diapolo10/iplib3",
        "Tracker": "https://github.com/Diapolo10/iplib3/issues"
    },
    "split_keywords": [
        "network",
        "networking",
        "ip",
        "ipaddress",
        "address",
        "python3",
        "pathlib"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "daa1a21c1aedcc5337f59c60be2421b559ded96fa6f369ba7e3571b477fd511e",
                "md5": "4228e1ffff4874daefe38a49fda04777",
                "sha256": "5b219af33b78e18ebac7034c9e2998c69ff7560f9d8aa1f20de063a3a4fecf6c"
            },
            "downloads": -1,
            "filename": "iplib3-0.2.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4228e1ffff4874daefe38a49fda04777",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9.0,<4.0.0",
            "size": 17647,
            "upload_time": "2023-09-18T16:15:19",
            "upload_time_iso_8601": "2023-09-18T16:15:19.815626Z",
            "url": "https://files.pythonhosted.org/packages/da/a1/a21c1aedcc5337f59c60be2421b559ded96fa6f369ba7e3571b477fd511e/iplib3-0.2.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b4492358cdcc3c099a2c945e5d749eb4c045f22a33df26715a47af50f3a4b7ea",
                "md5": "06c99eb7f57a1c4c9b28d051766fa497",
                "sha256": "59db0c8225837873b9b28aea53207d0dfee79bfb47dec1d4eb1ec9ea0e4ad684"
            },
            "downloads": -1,
            "filename": "iplib3-0.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "06c99eb7f57a1c4c9b28d051766fa497",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9.0,<4.0.0",
            "size": 17138,
            "upload_time": "2023-09-18T16:15:21",
            "upload_time_iso_8601": "2023-09-18T16:15:21.370812Z",
            "url": "https://files.pythonhosted.org/packages/b4/49/2358cdcc3c099a2c945e5d749eb4c045f22a33df26715a47af50f3a4b7ea/iplib3-0.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-18 16:15:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Diapolo10",
    "github_project": "iplib3",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "iplib3"
}
        
Elapsed time: 0.34867s