Skip to main content

A Python library for efficient IP geolocation lookup using CZDB database

Project description

CZDB Searcher

CZDB Searcher 是一个用于高效 IP 地理位置查询的 Python 库,它使用紧凑的数据库格式和二叉树搜索算法,提供快速准确的 IP 查找功能。

特点

  • IP 地理位置查询
  • 支持 IPv4 和 IPv6 地址
  • 简单易用的 API

性能

请尽量使用单例来查询,避免每次查询都初始化DbSearcher,这会带来性能瓶颈。同时要注意BTREE模式查询时不是线程安全的

安装

pip install czdb-searcher

使用方法

以下是一个快速开始的示例:

import sys
from czdb.db_searcher import DbSearcher

database_path = "/path/to/your/database.czdb"
query_type = "BTREE"
key = "YourEncryptionKey"
ip = "8.8.8.8"

db_searcher = DbSearcher(database_path, query_type, key)

try:
    region = db_searcher.search(ip)
    print("搜索结果:")
    print(region)
except Exception as e:
    print(f"An error occurred during the search: {e}")

db_searcher.close()

请将 database_path 和 key 替换为您项目中实际的数据库路径和加密密钥。

配置

DbSearcher 构造函数接受以下参数:

  • databasePath:您的 CZDB 数据库文件路径。
  • searchMode:搜索模式(例如,"BTREE" 或者 "MEMORY")。
  • encryptionKey:密钥。

数据库文件和密钥可以从 www.cz88.net 获取。

模式选择

  • 批量查询:对于批量查询,建议使用 "MEMORY" 模式。这是因为 "MEMORY" 模式会将数据库加载到内存中,从而提高查询速度,尤其是在处理大量查询时。虽然这会增加内存的使用,但可以显著提高批量处理的效率。

  • 少量查询:如果每个请求只查询少量的 IP 地址,那么使用 "BTREE" 模式可能更合适。"BTREE" 模式不需要预先加载整个数据库到内存中,适用于处理较少量的查询请求,可以减少内存的使用,同时保持良好的查询性能。

贡献

欢迎贡献!请随时提交拉取请求或开启问题来改进库或添加新功能。

许可证

该项目在 Apache-2.0 许可下授权 - 详情见 LICENSE 文件。

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

czdb_searcher-0.1.2.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

czdb_searcher-0.1.2-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file czdb_searcher-0.1.2.tar.gz.

File metadata

  • Download URL: czdb_searcher-0.1.2.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for czdb_searcher-0.1.2.tar.gz
Algorithm Hash digest
SHA256 efe996ea492139379403ba79ad7d328b605761236a35e58ecbf6a9c21cf0abaa
MD5 a221a26ec2778a2831e4a6509376e78a
BLAKE2b-256 3e06ca7f535cb00742dcb9ca12d81ea0178db1c659ffeab5d202f5fc197975c8

See more details on using hashes here.

File details

Details for the file czdb_searcher-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: czdb_searcher-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for czdb_searcher-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1bdeab94aed30a080d3089e14784fd723dcb4a0f357d913dd6ee249e6446146e
MD5 d911cccbf9c9ff567e7d615018179837
BLAKE2b-256 fee375d4390b00faafecd34ef687e1d750e13ed01403e06794ab484edfa43e7c

See more details on using hashes here.

Supported by

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