PyPI Module: ipgeo

2014/12/26

几天前在逛Github时发现huacnlee大神用Ruby写的Gem:ip-location。刚好我从未在PyPI上发布过模组,可以借此机会做一个Python语言的Port学习下如何发布到PyPi。

模组的介绍是这样的:

ipgeo is a python module inspired by another ruby gem huacnlee/ip-location.

The pypi page of ipgeo is https://pypi.python.org/pypi/ipgeo .

ipgeo is used to retrieve geo info for ip address via taobao ip service(http://ip.taobao.com) .

The Limitation of ipgeo is the query frequency should be less than 10 per second (http://ip.taobao.com/restrictions.php).

For more information, please visit ipgeo's github page (https://github.com/caiski/ipgeo) .

首先说明此模组是由huacnlee的ip-location启发而来,内部实现逻辑也完全一样,只是语言不同。实现非常简单,有兴趣的同学可到这个Repository查看源码。

该模组是通过淘宝IP地址服务实现,因此要受淘宝IP地址服务的QPS限制。

要编写符合PyPI要求的模组工程,还需要写好setup.py这个文件,感觉就像是为这个模组编写Meta信息。

from distutils.core import setup

setup(
  name = 'ipgeo',
  packages = ['ipgeo'],
  version = '0.2.3',
  description = 'Geo info retriver for ipv4 address using chinese taobao service',
  author = 'Ai Chao',
  author_email = 'aichaoguy@live.com',
  url = 'https://github.com/aichaoguy/ipgeo',
  download_url = 'https://github.com/aichaoguy/ipgeo/tarball/0.2.3',
  keywords = ['ip', 'geo', 'taobao'],
  classifiers = [
      "Programming Language :: Python",
      "Programming Language :: Python :: 2.6",
      "Programming Language :: Python :: 2.7",
      "Programming Language :: Python :: 3",
      "Environment :: Other Environment",
      "Operating System :: OS Independent",
      "Topic :: Software Development :: Libraries :: Python Modules",
    ],
)

各种本地工作完成后,便是打包和上传了。在.pypirc中设置号自己PyPI的账号密码后,使用Python自带的工具可以轻松完成。

python setup.py dist upload 后续版本更新时,要对setup.py文件中version、download_url等选项的同步更新。

一个简单的意义甚微的PyPI模组就这样诞生了。