Skip to main content

The official client library for ipify: A Simple IP Address API.

Project description

The official client library for ipify: A Simple IP Address API.

python-ipify Release python-ipify Downloads python-ipify Build https://coveralls.io/repos/rdegges/python-ipify/badge.svg?branch=master

Meta

Purpose

ipify is the best IP address lookup service on the internet. It’s fast, simple, scalable, open source, and well-funded (by me!).

In short: if you need a way to pragmatically get your public IP address, ipify is the best possible choice!

This library will retrieve your public IP address from ipify’s API service, and return it as a string. It can’t get any simpler than that.

This library also has some other nice features you might care about:

  • 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 ipify, simply run:

$ pip install ipify

This will install the latest version of the library automatically.

Usage

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

>>> from ipify import get_ip
>>> ip = get_ip()
>>> ip
u'96.41.136.144'

Now, in regards to exception handling, there are several ways this can fail:

  • The ipify service is down (not likely), or:

  • Your machine is unable to get the request to ipify because of a network error of some sort (DNS, no internet, etc.).

Here’s how you can handle all of these edge cases:

from ipify import get_ip
from ipify.exceptions import ConnectionError, ServiceError

try:
    ip = get_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, you could also do the following (it will catch any sort of ipify related errors regardless of what type they may be):

from ipify import get_ip
from ipify.exceptions import IpifyException

try:
    ip = get_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.

Contributing

This project is only possible due to the amazing contributors who work on it!

If you’d like to improve this library, please send me a pull request! I’m happy to review and merge pull requests.

The standard contribution workflow should look something like this:

  • Fork this project on Github.

  • Make some changes in the master branch (this project is simple, so no need to complicate things).

  • Send a pull request when ready.

Also, if you’re making changes, please write tests for your changes – this project has a full test suite you can easily modify / test.

To run the test suite, you can use the following commands:

$ pip install -e .
$ pip install -r requirements.txt
$ python manage.py test

Change Log

All library changes, in descending order.

Version 1.0.0

Released May 6, 2015.

  • First release!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ipify-1.0.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

ipify-1.0.0-py2.py3-none-any.whl (8.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file ipify-1.0.0.tar.gz.

File metadata

  • Download URL: ipify-1.0.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ipify-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9941659b9a89a09478b491ec355446b97b8dec1770e317dd56b4c26bbab50840
MD5 ee9260258d72fd6e85f78de96e5818d7
BLAKE2b-256 2e184fbcf738517e3d21cd79f4e822c588491a9b09e3c639bf50c4ceadfa80b0

See more details on using hashes here.

File details

Details for the file ipify-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for ipify-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e0d486997e484adbf49008a22b4b5370f675320100ab1af4aaba7e3070fb5d35
MD5 4b60638caaef9f4179b7b2fc773a4838
BLAKE2b-256 6ef0eeeea218faaef1cd4db0ef7578ec43be1c9ea4e56fc2df797d4b0df8e2e7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page