Skip to main content
File added late

1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.

A fork from 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 setup.py test

Change Log

All library changes, in descending order.

Version 1.0.1

Released January 26, 2022.

  • Improving test to actually validate IP addresses. Thanks to @lethargilistic for the pull request!

  • Fixing URLs in the README / comments to point to https URLs. Thanks to @ktdreyer for the pull request!

  • Fixing typo in the README. Thanks @prologic for the find!

  • Adding a working test for exercising ServiceError exceptions. Improves test coverage a bit =)

  • Removing unnecessary assertions / tests.

  • Adding test to improve test coverage to 100% =)

  • Fixing minor style issues. I’m really obsessed with code style / quality, don’t judge me!

  • Adding Python 3.5 / 3.6 support.

  • Adding Python 3.10 support.

Version 1.0.0

Released May 6, 2015.

  • First release!

Release files for ipify-py 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

File added late

1 file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release files before installing.

Source distribution (sdist)

Source distribution for ipify-py 1.0.1
File Size Uploaded
ipify-py-1.0.1.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ipify-py 1.0.1
File Interpreter ABI Platform
ipify_py-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / ipify-py-1.0.1.tar.gz

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL ipify-py-1.0.1.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
44bf2dcad7791b8f53ff7b00563f48d6b3e3464b90a1a1fd8f68297f084c266f
BLAKE2b-256 checksum
How to use checksums
0dd77219441d38b4f7e07585c98e118fadba8b69012b0f0e69ad3b47c893183e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.0

Release files / ipify_py-1.0.1-py3-none-any.whl

Download URL ipify_py-1.0.1-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
50eb018c41b20e275a8c9a62c7ea70d1fd0ca9744ba126442e2ab42d9955f81f
BLAKE2b-256 checksum
How to use checksums
fa712eca0eba297e09f5d01eb373b114124e01a784048b3e2343c5c097d6b20a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page