Skip to main content

InternetData InternetData Flask Extension

PyPI license

The official Flask extension for the InternetData API.

It looks up the visitor behind each request, where they are, which network they come from and whether it's a VPN, a proxy, Tor or a hosting server, and hands the answer to your views. Blocking is opt-in.

Getting Started

pip install internetdata-flask

Requires Python 3.11 or newer and Flask 3.0 or newer.

Without an API key a lookup is on Unlimited, the free plan: the country, the network and the company behind the address, Tor, relay, anycast, carrier and satellite space and the service flags, with no daily or monthly cap. Every lookup your app makes comes from your server's one address, though, so a busy site will see bursts refused. A paid plan answers every field, VPN, the proxy flags, hosting, CDN and the city among them; create a key in the console. A free account tries every field.

from flask import Flask
from internetdata_flask import InternetData

app = Flask(__name__)
InternetData(app, api_key=os.environ.get("INTERNETDATA_API_KEY"))

init_app(app) is supported for the application-factory pattern.

from internetdata_flask import lookup


@app.route("/")
def index():
    found = lookup()
    country = found.result.location.country_name if found and found.result else "somewhere"
    return f"Hello, visitor from {country}"

By default nothing is blocked. Every request gets an answer and your own code decides what it means: a currency to show, a sign-up to review, a page to keep from some countries. A request your skip claims gets no answer, and lookup() is None for it.

Blocking

Pass a block_condition and a matching request is answered with 403 and never reaches your views.

InternetData(
    app,
    api_key=os.environ.get("INTERNETDATA_API_KEY"),
    block_condition={"location": {"country": ["CU", "IR", "KP"]}},
)

A condition is written in the shape of a result, keyed by the same names the API uses, and only the members you name are considered, so it can refuse on anything in the answer. The country works on every plan, and so do the first two of these:

{"asn": {"type": "hosting"}}  # the network's type
[{"is_anycast": True}, {"is_satellite": True}]  # anycast and satellite space
[{"is_hosting": True}, {"is_cdn": True}]  # traffic from servers, not people
[{"is_vpn": True}, {"is_tor": True}, {"is_resproxy": True}]  # anonymity: a list is OR
{"is_vpn": True, "vpn": {"provider": "nordvpn"}}  # one provider
{"resproxy": {"hits": {"gte": 5}}}  # a numeric threshold

Values are matched by equality, strings without regard to case. A list means any-of. A dict of gte/gt/lte/lt compares numbers, and every bound you give must hold, so two of them are a range. Members set to False or None are ignored, so a condition states the signals you act on; one that constrains nothing would match every request, and is refused when the extension is built rather than silently blocking all your traffic.

Replace the refusal with on_blocked, which takes the answer and returns a response:

InternetData(
    app,
    api_key=os.environ.get("INTERNETDATA_API_KEY"),
    block_condition={"location": {"country": ["CU", "IR", "KP"]}},
    on_blocked=lambda found: (render_template("unavailable.html"), 451),
)

Blocking one view

block_condition applies to every view. To refuse a visitor on some views only, decorate them below the route, sync or async:

from internetdata_flask import block_if


@app.get("/checkout")
@block_if({"location": {"country": ["CU", "IR", "KP"]}})
def checkout(): ...

block_if takes the same condition, on_blocked, fail_closed and on_missing_field. It judges the answer the extension already attached, so a visitor is looked up once however many views check them, and it warns once for a member your plan doesn't include. A request skip claimed reaches the view. The extension still has to be registered: on an app without it, a decorated view raises RuntimeError instead of letting everyone through.

Where the client address comes from

This is the setting that decides whether any of the above works, and it is the one thing only you can get right.

By default the extension uses request.remote_addr, which is the socket peer unless you have wrapped the app in werkzeug's ProxyFix. Behind a load balancer without it, every visitor looks like the load balancer, and that is the address that gets looked up: every visitor gets your proxy's country and network, and if it is a hosting address, a hosting rule blocks everyone. A load balancer in your own network usually has a private address, which the extension answers locally without a lookup, as an address with no country, and logs a warning. Adding ProxyFix is Flask's own answer and everything else here follows from it. It counts proxies from the right (x_for=1 believes the last X-Forwarded-For entry), so it is right only when the app cannot be reached except through those proxies: anyone who connects to the app directly writes that entry themselves.

For an edge that writes the address into its own header, name the header:

from internetdata_flask import header_ip_selector

InternetData(
    app,
    api_key=os.environ.get("INTERNETDATA_API_KEY"),
    ip_selector=header_ip_selector("CF-Connecting-IP"),  # or True-Client-IP, or your own
)

xff_ip_selector() reads X-Forwarded-For directly. Be aware that the left-most entry is whatever the caller sent, because proxies append to that header, so it's only trustworthy when an edge you control overwrites it. If you know how many proxies sit in front, count from the right instead: xff_ip_selector(1) is the address your nearest proxy saw.

Anything else, pass your own callable. It receives the request and returns an address.

If the address resolves to a private one, the extension says so once through the internetdata logger. That is expected on localhost and is the signal to fix your configuration anywhere else.

When a lookup fails

The request is let through, and the reason is recorded on the answer's error. Our outage should not become yours, so a network failure, a rate limit or a rejected key all fail open. Pass fail_closed=True to block instead. Private addresses are answered locally and never fail, so this will not lock you out in development.

Cost and latency

Answers are cached for an hour, so a returning visitor costs nothing, and private addresses never leave the process. A cache miss is one request to our API, bounded at 2.5 seconds by default and not retried: on a request path, failing open quickly beats holding a visitor while we try again. Both are adjustable with timeout and retries, and the cache through an InternetData client you build yourself and pass as client.

Skip what you do not care about:

InternetData(app, skip=lambda request: request.path.startswith("/static"))

Beyond a few million distinct visitors a day, stop calling the API per request: look addresses up locally in our databases instead.

Absent is not false

Unlimited, with a key or without one, leaves out is_vpn, is_hosting, is_cdn and the four proxy flags, the detail behind them, and the paid members inside location, asn, company and abuse, such as location.city. A field your plan does not include is None, which means "not in your plan" rather than "checked, and no".

lookup().result.flagged("is_vpn")  # False rather than None on a plan without it

A block_condition naming a member your plan does not serve, location.city on Unlimited included, can never match, so the extension warns once instead of failing silently. Pass on_missing_field="raise" to make it an error.

Other Libraries

There are official InternetData client libraries available for many languages including PHP, Python, Go, Java, and Ruby. See our GitHub at https://github.com/internetdata for more.

About InternetData

Geolocation, anonymity, ownership and network data for IP addresses, AS numbers and domains, as an API and as databases you download and query yourself.

InternetData

License

This project is licensed under the MIT License.

Metadata

Release files for internetdata-flask 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for internetdata-flask 1.0.5
File Size Uploaded Provenance Actions
internetdata_flask-1.0.5.tar.gz 49.0 kB With provenance Details for internetdata_flask-1.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for internetdata-flask 1.0.5
File Interpreter ABI Platform Actions
internetdata_flask-1.0.5-py3-none-any.whl Python 3 none any Details for internetdata_flask-1.0.5-py3-none-any.whl

Total release size: 57.8 kB

Release files / internetdata_flask-1.0.5.tar.gz

Download URL internetdata_flask-1.0.5.tar.gz
Size 49.0 kB
Tags Source
SHA-256 checksum
How to use checksums
bd9f6473464381761a3386ff5813bd5aa1dbb688613edd25fcebcc3716fe6275
BLAKE2b-256 checksum
How to use checksums
71b6c26b2a2d94253201b289c3fa65f7deff7ddbd26d6f8473aced1408db9485
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / internetdata_flask-1.0.5-py3-none-any.whl

Download URL internetdata_flask-1.0.5-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e828996506f5fa3ff14fd63403ad1c377ee2fa401ef17f7b6e1231b53d7fd403
BLAKE2b-256 checksum
How to use checksums
3e5339ba755b6103859eac0c8b97a1636eddf06ecd4707fefb3063bfc80ea4ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for internetdata-flask 1.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for internetdata_flask-1.0.5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page