Sign inSign up

gitree/briefinfo

By gitree

•Updated 7 days ago

A lightweight internal proxy service that wraps Baidu IP portrait API.

Image
Networking
0

52

gitree/briefinfo repository overview

⁠Baidu BriefInfo Internal Proxy

A lightweight internal proxy service that wraps Baidu IP portrait API behind a clean, self-hosted HTTP endpoint. Built with FastAPI + pycurl on Python 3.14 Alpine, using a persistent curl handle for TCP/TLS session reuse.

⚠️ For internal / private use only. This image proxies a third-party, non-public API. Evaluate the upstream provider's Terms of Service before using it in any commercial or public-facing environment.


⁠Features

  • Single upstream call: GET /query?ip=<ip> → raw JSON from upstream
  • Keep-alive connection reuse: one persistent pycurl.Curl handle, with background keep-alive requests every 30s to maintain the TLS session
  • Explicit UTF-8: response is returned as application/json; charset=utf-8, no garbled Chinese output
  • Automatic decompression: gzip / deflate / brotli handled by libcurl
  • Multi-stage build: final image ~90 MB, non-root user
  • Timezone: Asia/Shanghai preconfigured

⁠Quick Start

docker run -d \
  --name briefinfo \
  -p 18000:18000 \
  --restart unless-stopped \
  gitree/briefinfo:beta

Then:

curl "http://127.0.0.1:18000/query?ip=8.8.8.8"

⁠API

⁠GET /query

Query the IP portrait / geo information for a given IPv4 or IPv6 address.

ParameterTypeRequiredDescription
ipstringyesIPv4 or IPv6 address

Example

curl "http://127.0.0.1:18000/query?ip=8.8.8.8"

Response

  • 200 OK — raw JSON body from upstream, Content-Type: application/json; charset=utf-8
  • Non-200 — upstream status code is passed through unchanged

Interactive docs (FastAPI built-in):

http://127.0.0.1:18000/docs

⁠Configuration

Env varDefaultDescription
TZAsia/ShanghaiContainer timezone

The upstream URL and request headers are currently compiled into the image. To change them, rebuild with a modified main.py.


⁠docker-compose

services:
  ip-api:
    image: <your-dockerhub-username>/ip-api:latest
    container_name: ip-api
    restart: unless-stopped
    ports:
      - "127.0.0.1:18000:18000"   # bind to loopback; expose via reverse proxy
    environment:
      - TZ=Asia/Shanghai
    mem_limit: 256m
    cpus: 1.0
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://127.0.0.1:18000/query?ip=8.8.8.8"]
      interval: 30s
      timeout: 5s
      retries: 3

⁠Resource Notes

  • Concurrency: a single curl handle serializes outbound requests. This image comfortably handles 5–10 QPS for internal use. Add a response cache (e.g. Redis / cachetools.TTLCache) if you need more.
  • Run only one worker. The process relies on a global curl handle and a single lock. Starting multiple uvicorn workers is not recommended with the bundled main.py.
  • Timeouts: connect timeout 5s, total timeout 10s.

⁠Security

  • Runs as non-root user appuser (UID 1000)
  • Bind to loopback and put a reverse proxy / API key in front if exposed beyond a trusted network
  • No authentication is built in — do not expose this container directly to the public internet

⁠License

No license declared. Third-party API usage is the operator's responsibility.

Tag summary

Content type

Image

Digest

sha256:e76459b7d…

Size

48.2 MB

Last updated

7 days ago

docker pull gitree/briefinfo:beta