MIT License

项目介绍

ipapi-co/ipapi-python 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 MIT License 许可证,目前获得 69 个 Star、20 次 Fork。

仓库全名
ipapi-co/ipapi-python
开源许可证
MIT License
Star 数
69
Fork 数
20

README 摘要

ipapi Python Library ipapi.co by Kloudend, Inc. IP Address Location | IP Lookup | IP Geolocation API The ipapi Python library provides convenient access to the IP address location service from applications written in the Python language. It makes it easy to harness the potential of the IP geolocation API. Details on free IP lookup and ipapi pricing plans Documentation See the ipapi API docs Installation or Install…

完整内容见 GitHub 原始 README 或本页 。

常见问题

ipapi-python 用什么语言开发?

主要使用 Python 编写,采用 MIT License 许可证,目前有 69 个 Star。

ipapi-python 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 ipapi-python 的源码?

可以直接克隆仓库:git clone https://github.com/ipapi-co/ipapi-python.git,默认分支为 master;安装与运行步骤见仓库 README。

ipapi-python 最近还在维护吗?

仓库最近一次更新为 2024年2月16日,当前没有未关闭的 Issue;Star 数为 69,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

Python bindings for https://ipapi.co (IP Address Location) - Use with python / django / flask for IP address location lookup

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

语言占比

Python

Release

贡献者

README

ipapi Python Library ~ ipapi.co by Kloudend, Inc.

IP Address Location | IP Lookup | IP Geolocation API

The ipapi Python library provides convenient access to the IP address location service from applications written in the Python language. It makes it easy to harness the potential of the IP geolocation API.

Details on free IP lookup and ipapi pricing plans

Documentation

See the ipapi API docs

Installation

pip install --upgrade ipapi

or Install from source with:

python setup.py install

Requirements

Python 2.7+ or Python 3.4+

QuickStart

>>> import ipapi

>>> ipapi.location()
{
  "ip": "8.8.8.8",
  "city": "Mountain View",
  "country": "US",
  "timezone": "America/Los_Angeles",
  ...
}

Usage : As an IP Location library

import ipapi

ipapi.location(ip, key, output)

Options

Argument Description
ip IP Address (IPv4 or IPv6) that you wish to locate.
If omitted, it defaults to the your machine’s IP
key API key (for paid plans).
Omit it or set key=None for usage under free IP Location tier.
output The desired output from the API.
For complete IP location object, valid values are json, csv, xml, yaml.
To retrieve a specific field (e.g. city, country etc. as text), valid values are [1].
If omitted or None, gets the entire location data as json

[1] Fields supported by the API : ip, city, region, region_code, country, country_code, country_code_iso3, country_capital, country_tld, country_name, continent_code, in_eu, postal, latitude, longitude, timezone, utc_offset, country_calling_code, currency, currency_name, languages, country_area, country_population, latlong, asn, org

Examples
  1. Find the location of your IP address
>>> ipapi.location()

The output would be a JSON object like this (assuming your IP is ‘50.1.2.3’) :

{
    "ip": "50.1.2.3",
    "city": "Sacramento",
    "region": "California",
    "region_code": "CA",
    "country": "US",
    "country_code": "US",
    "country_code_iso3": "USA",
    "country_capital": "Washington",
    "country_tld": ".us",
    "country_name": "United States",
    "continent_code": "NA",
    "in_eu": false,
    "postal": "95817",
    "latitude": 38.548,
    "longitude": -121.4597,
    "timezone": "America/Los_Angeles",
    "utc_offset": "-0700",
    "country_calling_code": "+1",
    "currency": "USD",
    "currency_name": "Dollar",
    "languages": "en-US,es-US,haw,fr",
    "country_area": 9629091.0,
    "country_population": 310232863.0,
    "asn": "AS7065",
    "org": "SONOMA"
}
  1. Find the location of an IP address
>>> ipapi.location(ip='8.8.8.8')
{
    "ip": "8.8.8.8",
    "city": "Mountain View",
    "region": "California",
    ...
}

You can also use an IPv6 address e.g.

>>> ipapi.location(ip='2001:4860:1::1')
  1. Find the location of an IP address in xmlformat (other formats :json, csv,yaml)
>>> ipapi.location(ip='8.8.8.8', output='xml')
'<?xml version="1.0" encoding="utf-8"?>
  <root>
    <ip>8.8.8.8</ip>
    <city>Mountain View</city>
    ...
  </root>'
  1. Find your external IP address
>>> ipapi.location(output='ip')
'50.1.2.3'
  1. Find the city from an IP address
>>> ipapi.location(ip='8.8.8.8', output='city')
'Mountain View'
  1. Find the country code from an IP address
>>> ipapi.location(ip='8.8.8.8', output='country_code')
'US'
  1. Find the region of an IP address
>>> ipapi.location(ip='8.8.8.8', output='region_code')
'CA'
  1. Find if an IP address is located in the European Union
>>> ipapi.location(ip='8.8.8.8', output='in_eu')
'False'
  1. Find the latitude and longitude of an IP address
>>> ipapi.location(ip='1.2.3.4', output='latlong')
'-27.473101,153.014046'
  1. Find the postal code of an IP address
>>> ipapi.location(ip='1.2.3.4', output='postal')
'4101'
  1. Find the timezone of an IP address
>>> ipapi.location(ip='1.2.3.4', output='timezone')
'Australia/Brisbane'
  1. Find the currency of an IP address
>>> ipapi.location(ip='1.2.3.4', output='currency')
'AUD'
  1. Find the ASN of an IP address
>>> ipapi.location(ip='1.1.1.1', output='asn')
'AS13335'
  1. Find the Organization of an IP address
>>> ipapi.location(ip='8.8.8.8', output='org')
'GOOGLE'

Usage : As an IP Location command line utility

ln -s /<virtual-env-path>/lib/python3.8/site-packages/ipapi ipapi

$ python ipapi -i <IP Address> -k <API KEY> -o <Output Format>
OR
$ python ipapi --ip <IP Address> --key <API KEY> --output <Output Format>

where the options ip, key, output are defined above.

Examples
  1. Get your IP Geolocation
$ python ipapi

The output would be a JSON object like this (assuming your IP is 50.1.2.3) :

{
    "ip": "50.1.2.3",
    "city": "Sacramento",
    "region": "California",
    "region_code": "CA",
    "country": "US",
    "country_code": "US",
    "country_code_iso3": "USA",
    "country_capital": "Washington",
    "country_tld": ".us",
    "country_name": "United States",
    "continent_code": "NA",
    "in_eu": false,
    "postal": "95817",
    "latitude": 38.548,
    "longitude": -121.4597,
    "timezone": "America/Los_Angeles",
    "utc_offset": "-0700",
    "country_calling_code": "+1",
    "currency": "USD",
    "currency_name": "Dollar",
    "languages": "en-US,es-US,haw,fr",
    "country_area": 9629091.0,
    "country_population": 310232863.0,
    "asn": "AS7065",
    "org": "SONOMA"
}
  1. Get the geolocation of an IP address
$ python ipapi -i '8.8.8.8'
{
    "ip": "8.8.8.8",
    "city": "Mountain View",
    "region": "California",
    ...
}
  1. Get the location of an IP in xml format (other formats : json, csv, yaml)
$ python ipapi -i '8.8.8.8' -o xml
'<?xml version="1.0" encoding="utf-8"?>
  <root>
    <ip>8.8.8.8</ip>
    <city>Mountain View</city>
    ...
  </root>'
  1. Get your external IP address
$ python ipapi -o ip
'50.1.2.3'
  1. Get the city of an IP address
$ python ipapi -i '8.8.8.8' -o city
'Mountain View'

评论

暂无评论