coip — Columnar IP Database Format (.coi)
English | 简体中文
coip is a modern, open-source, read-only columnar IP database format (.coi) with a Rust toolkit, an offline Web UI server (coip-web), and a zero-cgo pure-Go reader. It stores arbitrary structured IP→Record databases (including MaxMind .mmdb files such as GeoIP2/GeoLite2 City, Country, ASN, ISP, Enterprise, DB-IP, IPinfo, or custom CSV/JSONL feeds) at ~5× smaller on-disk size (GeoIP2-City.mmdb 104.27 MB → 20.98 MB), while providing microsecond random point-lookups, compile-once column projection, and build-time --keep-fields pruning.
Key Features
- Exact Type Fidelity & Simplified MMDB Import: Preserves numeric widths, IEEE-754
f64bit patterns,Nonevsfalse/0/""optionality, and IPv6→IPv4 DAG alias semantics. When converting.mmdb -> .coi, multi-languagenamesmaps are automatically removed and flattened into a single Englishnamefield (strictly takingen; omitted ifenis absent). - Self-Describing 6-Primitive Schema: No hardcoded GeoIP fields; supports arbitrary schemas, dynamic inspection, build-time
--keep-fieldspruning, and compile-once Column Projection. - Two Tuned Profiles:
Compact(Zstd +Section 3: ZstdDicts+ZeroSkipDelta/LocalDictSplit): 4.97× smaller than.mmdb(20.98 MB).UltraFast(pure-Rust LZ4): 3.52× smaller than.mmdb(29.62 MB), 21.2 µs cold 5-field lookup, 1.07 µs warm 5-field lookup (1.65× faster thanmaxminddb), and 3.06M QPS across 8 threads.
- Zero-C Pure-Rust & Pure-Go Readers:
coip-readerdefaults to pure-Rustruzstd+lz4_flex(optionalzstd-cfeature);bindings/goprovides a standaloneCGO_ENABLED=0pure-Go COI v1.0 reader. - CLI & Standalone Intranet Web UI:
coipsupports persistentcoip bindconfig, Nushell-style rounded tables,coip <IP>shorthand, and stdin piping;crates/coip-webembeds a zero-dependency Web UI & HTTP API server with batch IP extraction and hot reload. - Open Binary Specification: Byte-level specification in
docs/SPEC.md(中文导读), detailed benchmark report indocs/BENCHMARKS.md(中文压测报告), and cross-language golden vectors intest-vectors/.
Simplified MMDB Output Format
Converting any MaxMind .mmdb to .coi replaces every nested multi-language names map (city, continent, country, registered_country, represented_country, subdivisions[*]) with a flat English name string:
Real-World Benchmark (GeoIP2-City.mmdb, 672,963 unique records, simplified en name)
Measured on Intel Core i7-13700 (Windows x64, coip bench with zstd-c). Full section breakdown and Go benchmarks are in docs/BENCHMARKS.md.
| Format / Profile | File Size | Ratio vs MMDB | Cold 5-Field (serde) |
Warm 5-Field (1T) | Warm 8-Thread QPS |
|---|---|---|---|---|---|
MaxMind GeoIP2-City.mmdb (maxminddb 5-field) |
104.27 MB | 1.00× | 2.06–2.24 µs | 1.77–1.88 µs | 2.98–3.12M QPS |
MaxMind GeoIP2-City.mmdb (maxminddb full) |
104.27 MB | 1.00× | 2.93–3.56 µs | 2.32–2.49 µs | — |
coip Compact (Zstd + 4 ZstdDicts) |
20.98 MB | 4.97× | 95.4 µs | 1.22 µs (822K QPS) | 2.94M QPS |
coip UltraFast (pure-Rust LZ4) |
29.62 MB | 3.52× | 21.2 µs | 1.07 µs (937K QPS) | 3.06M QPS |
coip Country-only pruned (--keep-fields) |
1.06 MB | 98.65× | 26.1 µs | 0.35 µs (2.86M QPS) | 6.43M QPS |
Workspace Layout
| Path | Description |
|---|---|
docs/SPEC.md / docs/SPEC.zh-CN.md |
Canonical COI v1.0 binary format specification (EN & ZH-CN) |
docs/BENCHMARKS.md / docs/BENCHMARKS.zh-CN.md |
Compression evolution, section breakdown, latency/QPS & architecture analysis |
crates/coip-format |
Header, Footer, Section Directory, Schema, Varint, CRC32C (no_std + alloc) |
crates/coip-builder |
Generic .coi builder, simplified .mmdb importer (names -> name), LPM resolver, --keep-fields pruning, CSV/JSONL import |
crates/coip-reader |
mmap / &[u8] / File reader, sharded LRU caches, Column Projection, streaming serde |
crates/coip-cli |
CLI: coip bind | convert | import | export | diff | lookup | query | inspect | verify | bench |
crates/coip-web |
Standalone offline intranet Web UI & HTTP API server (single & batch lookup, log IP extraction, hot reload) |
bindings/go |
Standalone pure-Go (CGO_ENABLED=0) COI v1.0 reader (中文文档) |
test-vectors/ |
Cross-language golden .coi test vectors (Compact + UltraFast) and expected JSON |
benches/ |
Criterion benchmark suite comparing coip-reader vs maxminddb |
Installation
CLI (coip)
# Pure-Rust build (zero C dependencies)
# Optional: link system/bundled libzstd for faster Compact cold lookups
Rust Libraries (crates.io)
| Crate | Crates.io | Docs | Purpose |
|---|---|---|---|
coip-reader |
docs.rs | High-performance read-only .coi reader (mmap, LRU cache, Column Projection, streaming serde) |
|
coip-builder |
docs.rs | Generic .coi builder, simplified .mmdb (names -> name) / CSV / JSONL importer, LPM & pruning |
|
coip-format |
docs.rs | Core binary format, schema, varint, CRC32C (no_std + alloc) |
|
coip-cli |
docs.rs | coip CLI binary |
# Optional: if building or converting .coi databases in Rust
CLI Quick Start
Once installed via cargo install coip-cli, run coip directly (or cargo run --release -p coip-cli -- ... from this repo):
# Convert an MMDB file to .coi (automatically simplifies `names` -> English `name`; Compact Zstd + ZstdDicts, 4.97x smaller)
# Convert with UltraFast profile (pure-Rust LZ4, 21.2 µs cold / 1.07 µs warm, 3.52x smaller)
# Build-time field pruning or .coi -> .coi repacking (no .mmdb needed!)
# Import any custom JSONL or CSV IP dataset (supports overlapping LPM CIDRs & IP ranges)
# Export a .coi database as canonical CIDR + JSONL (with optional projection)
# Diff two .coi databases (exact dual-stack IP additions, removals, and changes)
# Inspect schema, dictionaries, ZstdDicts, and section sizes
# Bind a default database once (saved to ~/.coip/config.toml; supports aliases & default --format)
# Direct top-level IP lookup (defaults to Nushell-style rounded table; uses bound DB, COIP_DB, or single .coi/.coip in cwd)
|
# Or specify a file/alias explicitly (table by default; --json for pure JSON; --line for `ip => json`)
# Exhaustively verify exact equivalence against source MMDB (with simplified English `name`)
# Benchmark cold / warm / multi-threaded concurrent lookups vs maxminddb
# Start the offline Web UI & HTTP API server (auto-loads ~/.coip/config.toml & ~/.coip/*.coi(p))
Rust Library Example
use IpAddr;
use Reader;
use Deserialize;
See full runnable examples in crates/coip-reader/examples/basic_lookup.rs and crates/coip-builder/examples/custom_db.rs:
Pure-Go Reader (bindings/go)
import coip "github.com/netkn001/coip/bindings/go"
r, err := coip.Open("GeoIP2-City.coi")
if err != nil
defer r.Close()
proj, _ := coip.CompileProjection("country.iso_code", "country.name", "location.latitude", "location.longitude")
rec, found, err := r.LookupProjectedString("8.8.8.8", proj)
See bindings/go/README.md (简体中文) for full Go documentation.
License
MIT License — see LICENSE.