Skip to content

Commit

Permalink
- Update README, prep for 1.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nwithan8 committed Sep 20, 2023
1 parent 040a63b commit 1b12608
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 176 deletions.
115 changes: 115 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
ipify2
============

An updated unofficial clone of the now-deprecated `ipify` library, allowing you to determine your IPv4 and IPv6 programmatically via [ipify.org](https://www.ipify.org)

.. image:: https://img.shields.io/pypi/v/ipify2.svg
:alt: ipify2 Release
:target: https://pypi.python.org/pypi/ipify2

.. image:: https://img.shields.io/pypi/dm/ipify2.svg
:alt: ipify2 Downloads
:target: https://pypi.python.org/pypi/ipify2


Meta
----

### Original

- Author: Randall Degges
- Email: [email protected]
- Site: http://www.rdegges.com

### Maintainer

- Author: Nate Harris
- Email: [email protected]
- Site: https://nateharr.is


Purpose
-------

[ipify.org](https://www.ipify.org) is a reliable IP address lookup service, an easy way to get your public IP address in Python.

This library will retrieve your public IP address from ipify's API service, and return it as a string.

Additional features:

- If a request fails for any reason, it is re-attempted 3 times using an exponential backoff algorithm for maximum effectiveness.
- This library handles exceptions properly, and usage examples below show you how to deal with errors in a foolproof way.
- This library only makes API requests over HTTPS.


Installation
------------

To install ``ipify2``, simply run:

```shell
pip install ipify2
```

This will install the latest version of the library automatically.


Usage
-----

Using this library is very simple. Here's a simple example:

```python
from ipify2 import get_ipv4

ip = get_ipv4()
print(ip) # '96.41.136.144'
```

```python
from ipify2 import get_ipv6
ip = get_ipv6()
print(ip) # '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
```

### Error Handling
There are several reasons a request fail:
- The ipify service is down
- Your machine is unable to get the request to ipify because of a network error
of some sort (DNS, no internet, etc.).

To handle these errors, you can do the following:

```python
from ipify2 import get_universal_ip
from ipify2.exceptions import ConnectionError, ServiceError

try:
ip = get_universal_ip()
except ConnectionError:
# If you get here, it means you were unable to reach the ipify service,
# most likely because of a network error on your end.
except ServiceError:
# If you get here, it means ipify is having issues, so the request
# couldn't be completed :(
except:
# Something else happened (non-ipify related). Maybe you hit CTRL-C
# while the program was running, the kernel is killing your process, or
# something else all together.
```

If you want to simplify the above error handling by catching all errors, you could also do the following:

```python
from ipify2 import get_universal_ip
from ipify2.exceptions import IpifyException

try:
ip = get_universal_ip()
except IpifyException:
# If you get here, then some ipify exception occurred.
except:
# If you get here, some non-ipify related exception occurred.
```

One thing to keep in mind: regardless of how you decide to handle exceptions, the ipify library will retry any failed requests 3 times before ever raising exceptions -- so if you *do* need to handle exceptions, just remember that retry logic has already been attempted.
152 changes: 0 additions & 152 deletions README.rst

This file was deleted.

2 changes: 1 addition & 1 deletion ipify2/__info__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.0.2'
__version__ = '1.1.0'

__title__ = "ipify2"
__author__ = 'Nate Harris'
Expand Down
2 changes: 1 addition & 1 deletion ipify2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"""


from .ipify import get_ipv4, get_universal_ip
from .ipify import get_ipv4, get_ipv6, get_universal_ip
6 changes: 3 additions & 3 deletions ipify2/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
class IpifyException(Exception):
"""
There was an ambiguous exception that occurred while attempting to fetch
your machine's public IP address from the ipify2 service.
your machine's public IP address from the ipify service.
"""
pass


class ServiceError(IpifyException):
"""
The request failed because the ipify2 service is currently down or
The request failed because the ipify service is currently down or
experiencing issues.
"""
pass


class ConnectionError(IpifyException):
"""
The request failed because it wasn't able to reach the ipify2 service. This
The request failed because it wasn't able to reach the ipify service. This
is most likely due to a networking error of some sort.
"""
pass
Loading

0 comments on commit 1b12608

Please sign in to comment.