Skip to main content

Lookup location of IP in qqwry.dat, for Python 3.0+

Project description


已上传到PyPI,执行此命令即可安装:pip install qqwry-py3


  1. for Python 3.0+。

  2. 提供两套实现供选择。有一个查找速度更快,但加载慢、占用内存多。

  3. 在i3 3.6GHz,Python 3.6上查询速度达18.0万次/秒。

  4. 提供一个从纯真网络(更新qqwry.dat的小工具,用法见本文最后一部分。


>>> from qqwry import QQwry
>>> q = QQwry()
>>> q.load_file('qqwry.dat')
>>> q.lookup('')
('美国', '加利福尼亚州圣克拉拉县山景市谷歌公司DNS服务器')

解释q.load_file(filename, loadindex=False)函数


加载速度:很快,0.004 秒
进程内存:较少,16.9 MB
查询速度:较慢,5.3 万次/秒

加载速度:★★★非常慢,因为要额外加载索引,0.78 秒★★★
进程内存:较多,22.0 MB
查询速度:较快,18.0 万次/秒

(以上是在i3 3.6GHz, Win10, Python 3.6.2 64bit,qqwry.dat 8.86MB时的数据)


找到则返回一个含有两个字符串的元组,如:(‘国家’, ‘省份’)






>>> q.get_lastone()
('纯真网络', '2020年9月30日IP数据')


>>> from qqwry import updateQQwry
>>> ret = updateQQwry(filename)





  1. for Python 3.0+.

  2. Provide two sets of implementations for selection. One finds faster, but loads slowly and takes up more memory.

  3. The query speed on i3 3.6GHz and Python 3.6 is 180,000 times per second.

  4. Provide a small tool to update qqwry.dat from Chunzhen Network (, see the last part of this article for usage.


>>> from qqwry import QQwry
>>> q = QQwry()
>>> q.load_file('qqwry.dat')
>>> q.lookup('')
('United States','Google DNS server in Mountain View, Santa Clara County, California')

Explain the q.load_file(filename, loadindex=False) function

Load the qqwry.dat file. Return True on success, False on failure.
The parameter filename can be the file name of qqwry.dat (str type), or the file content of bytes type.

When the parameter loadindex=False (default parameter):
Program behavior: read the entire file into memory, search from it
Loading speed: very fast, 0.004 seconds
Process memory: less, 16.9 MB
Query speed: slower, 53,000 times per second
Suggestions for use: suitable for desktop programs, large, medium and small websites

When the parameter loadindex=True:
Program behavior: Read the entire file into memory. Load an additional index, read the index into a faster data structure
Loading speed: ★★★Very slow, because of the additional loading index, 0.78 seconds★★★
Process memory: more, 22.0 MB
Query speed: faster, 180,000 times per second
Recommendations for use: only suitable for high-load servers

(The above is the data when i3 3.6GHz, Win10, Python 3.6.2 64bit, qqwry.dat 8.86MB)

Explain the q.lookup(‘’) function

If found, return a tuple containing two strings, such as: (‘country’,’province’)
If no result is found, a None is returned

Explain the q.clear() function

Clear the loaded qqwry.dat
It is not necessary to execute q.clear() when calling load_file again

Explain the q.is_loaded() function

Whether the q object has loaded data, return True or False

Explain the q.get_lastone() function

Return the last piece of data, the last piece is usually the version number of the data
Return None if there is no data
>>> q.get_lastone()
('纯真网络', '2020年9月30日IP数据')

Update the widget of qqwry.dat from Chunzhen Network (

>>> from qqwry import updateQQwry
>>> ret = updateQQwry(filename)

When the parameter filename is of type str, it indicates the name of the file to be saved.
Upon success, it returns a positive integer, which is the number of bytes in the file;
Upon failure, it returns a negative integer.

When the parameter filename is None, the function directly returns the content of the qqwry.dat file (a bytes object).
Return a bytes object on success; return a negative integer on failure. Here to determine whether the type of the return value is bytes or int.

Errors represented by negative integers:
-1: An error occurred while downloading copywrite.rar
-2: Error when parsing copywrite.rar
-3: An error occurred when downloading qqwry.rar
-4: qqwry.rarfile size does not match the data of copywrite.rar
-5: Error when decompressing qqwry.rar
-6: An error occurred while saving to the final file

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

qqwry-py3-1.2.1.tar.gz (10.1 kB view hashes)

Uploaded source

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