internetdata-flask 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python: ['3.11', '3.12', '3.13', '3.14']
14
+ steps:
15
+ - uses: actions/checkout@v7
16
+ - uses: actions/setup-python@v7
17
+ with:
18
+ python-version: ${{ matrix.python }}
19
+ cache: pip
20
+ cache-dependency-path: pyproject.toml
21
+ - run: pip install -e ".[dev]"
22
+ - run: ruff check .
23
+ - run: ruff format --check .
24
+ - run: mypy src
25
+ - run: pytest
@@ -0,0 +1,63 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ['v*']
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
+ contents: read
12
+ # PyPI trusted publishing exchanges this OIDC token for a short-lived upload
13
+ # token. No API token in a repository secret.
14
+ id-token: write
15
+ steps:
16
+ - uses: actions/checkout@v7
17
+ - uses: actions/setup-python@v7
18
+ with:
19
+ python-version: '3.13'
20
+ cache: pip
21
+ cache-dependency-path: pyproject.toml
22
+ # The tag only TRIGGERS this; PyPI publishes whatever the built artifact says.
23
+ # Without this check, tagging v1.0.1 against a 1.0.0 package silently
24
+ # republishes 1.0.0, or fails as "already exists" with a confusing message.
25
+ - name: Tag must match the package version
26
+ run: |
27
+ tag="${GITHUB_REF_NAME#v}"
28
+ pkg="$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' src/internetdata_flask/__init__.py)"
29
+ if [ "$tag" != "$pkg" ] ; then
30
+ echo "tag $tag does not match __version__ $pkg" >&2
31
+ exit 1
32
+ fi
33
+ - run: pip install -e ".[dev]" build
34
+ - run: pytest
35
+ - run: python -m build
36
+ - uses: pypa/gh-action-pypi-publish@release/v1
37
+
38
+ # This version's section of CHANGELOG.md, as the tag's GitHub Release. It
39
+ # waits for the publish, so no release page names a version the registry
40
+ # cannot serve, and a re-run edits the release rather than failing on it.
41
+ github-release:
42
+ needs: publish
43
+ runs-on: ubuntu-latest
44
+ permissions:
45
+ contents: write
46
+ steps:
47
+ - uses: actions/checkout@v7
48
+ - name: GitHub Release from CHANGELOG.md
49
+ env:
50
+ GH_TOKEN: ${{ github.token }}
51
+ GH_REPO: ${{ github.repository }}
52
+ run: |
53
+ version="${GITHUB_REF_NAME#v}"
54
+ awk -v v="$version" '/^## /{ if (found) exit; found = ($2 == v); next } found' CHANGELOG.md > notes.md
55
+ if ! grep -q '^### ' notes.md ; then
56
+ echo "CHANGELOG.md has no section for ${version}" >&2
57
+ exit 1
58
+ fi
59
+ if gh release view "$GITHUB_REF_NAME" > /dev/null 2>&1 ; then
60
+ gh release edit "$GITHUB_REF_NAME" --notes-file notes.md
61
+ else
62
+ gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --notes-file notes.md --verify-tag
63
+ fi
@@ -0,0 +1,17 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+
4
+ # Build output.
5
+ build/
6
+ dist/
7
+ *.egg-info/
8
+
9
+ # Virtualenvs, including any made to run codegen. Keep them out of the tree entirely.
10
+ .venv/
11
+ venv/
12
+ .venv-*/
13
+
14
+ # Tool caches.
15
+ .pytest_cache/
16
+ .mypy_cache/
17
+ .ruff_cache/
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ What each release changed for you, newest first. Each line is a commit's summary, linked to its full description and diff.
4
+
5
+ ## 1.0.0 - 2026-11-14
6
+
7
+ ### Features
8
+
9
+ - Attach the visitor's InternetData record to every request, read with `lookup()`: the location, the network and the company behind the address, and the anonymity and hosting flags your plan serves ([`c4884fd`](https://github.com/internetdata/sdk-python-flask/commit/c4884fd4f098a724145f92abed8b722df2cb95a6))
10
+ - Refuse a request with a `block_condition` written in the shape of a result, by country, network type, anonymity or any other member, with 403 or an `on_blocked` of your own ([`c4884fd`](https://github.com/internetdata/sdk-python-flask/commit/c4884fd4f098a724145f92abed8b722df2cb95a6))
11
+ - Refuse one view with the `block_if` decorator, sync or async, judging the answer the extension already attached ([`c4884fd`](https://github.com/internetdata/sdk-python-flask/commit/c4884fd4f098a724145f92abed8b722df2cb95a6))
12
+ - Choose where the client address comes from: `request.remote_addr` by default, `xff_ip_selector`, `header_ip_selector` for a header your edge writes, or a callable of your own ([`c4884fd`](https://github.com/internetdata/sdk-python-flask/commit/c4884fd4f098a724145f92abed8b722df2cb95a6))
13
+ - Fail open on any lookup failure unless `fail_closed` is set, with a 2.5 s bound, no retry and a cache by default ([`c4884fd`](https://github.com/internetdata/sdk-python-flask/commit/c4884fd4f098a724145f92abed8b722df2cb95a6))
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mslm Dev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,185 @@
1
+ Metadata-Version: 2.5
2
+ Name: internetdata-flask
3
+ Version: 1.0.0
4
+ Summary: Official Flask extension for the InternetData API. Look up the visitor behind every request: location, network, VPN, proxy, Tor and hosting.
5
+ Project-URL: Homepage, https://internetdata.io
6
+ Project-URL: Source, https://github.com/internetdata/sdk-python-flask
7
+ Author-email: Mslm Dev <support@internetdata.io>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: asn,flask,geoblocking,hosting,internetdata,ip-geolocation,ip-intelligence,ip-lookup,middleware,proxy-detection,tor,vpn-detection
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Internet
19
+ Classifier: Topic :: Security
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: flask>=3.0
23
+ Requires-Dist: internetdata<3,>=2.12.0
24
+ Provides-Extra: dev
25
+ Requires-Dist: mypy>=1.11; extra == 'dev'
26
+ Requires-Dist: pytest>=8; extra == 'dev'
27
+ Requires-Dist: ruff>=0.6; extra == 'dev'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # [<img src="https://s3.internetdata.io/internetdata-public/brand/mark.svg" alt="InternetData" height="28"/>](https://internetdata.io/) InternetData Flask Extension
31
+
32
+ [![PyPI](https://img.shields.io/pypi/v/internetdata-flask.svg)](https://pypi.org/project/internetdata-flask/)
33
+ [![license](https://img.shields.io/pypi/l/internetdata-flask.svg)](LICENSE)
34
+
35
+ The official [Flask](https://flask.palletsprojects.com) extension for the [InternetData](https://internetdata.io) API.
36
+
37
+ 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.
38
+
39
+ ## Getting Started
40
+
41
+ ```bash
42
+ pip install internetdata-flask
43
+ ```
44
+
45
+ Requires Python 3.11 or newer and Flask 3.0 or newer.
46
+
47
+ 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](https://app.internetdata.io). A free account tries every field, 100 lookups a day.
48
+
49
+ ```python
50
+ from flask import Flask
51
+ from internetdata_flask import InternetData
52
+
53
+ app = Flask(__name__)
54
+ InternetData(app, api_key=os.environ.get("INTERNETDATA_API_KEY"))
55
+ ```
56
+
57
+ `init_app(app)` is supported for the application-factory pattern.
58
+
59
+ ```python
60
+ from internetdata_flask import lookup
61
+
62
+
63
+ @app.route("/")
64
+ def index():
65
+ found = lookup()
66
+ country = found.result.location.country_name if found and found.result else "somewhere"
67
+ return f"Hello, visitor from {country}"
68
+ ```
69
+
70
+ 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.
71
+
72
+ ## Blocking
73
+
74
+ Pass a `block_condition` and a matching request is answered with `403` and never reaches your views.
75
+
76
+ ```python
77
+ InternetData(
78
+ app,
79
+ api_key=os.environ.get("INTERNETDATA_API_KEY"),
80
+ block_condition={"location": {"country": ["CU", "IR", "KP"]}},
81
+ )
82
+ ```
83
+
84
+ 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:
85
+
86
+ ```python
87
+ {"asn": {"type": "hosting"}} # the network's type
88
+ [{"is_anycast": True}, {"is_satellite": True}] # anycast and satellite space
89
+ [{"is_hosting": True}, {"is_cdn": True}] # traffic from servers, not people
90
+ [{"is_vpn": True}, {"is_tor": True}, {"is_resproxy": True}] # anonymity: a list is OR
91
+ {"is_vpn": True, "vpn": {"provider": "nordvpn"}} # one provider
92
+ {"resproxy": {"hits": {"gte": 5}}} # a numeric threshold
93
+ ```
94
+
95
+ 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.
96
+
97
+ Replace the refusal with `on_blocked`, which takes the answer and returns a response:
98
+
99
+ ```python
100
+ InternetData(
101
+ app,
102
+ api_key=os.environ.get("INTERNETDATA_API_KEY"),
103
+ block_condition={"location": {"country": ["CU", "IR", "KP"]}},
104
+ on_blocked=lambda found: (render_template("unavailable.html"), 451),
105
+ )
106
+ ```
107
+
108
+ ### Blocking one view
109
+
110
+ `block_condition` applies to every view. To refuse a visitor on some views only, decorate them below the route, sync or async:
111
+
112
+ ```python
113
+ from internetdata_flask import block_if
114
+
115
+
116
+ @app.get("/checkout")
117
+ @block_if({"location": {"country": ["CU", "IR", "KP"]}})
118
+ def checkout(): ...
119
+ ```
120
+
121
+ `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.
122
+
123
+ ## Where the client address comes from
124
+
125
+ This is the setting that decides whether any of the above works, and it is the one thing only you can get right.
126
+
127
+ 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.
128
+
129
+ For an edge that writes the address into its own header, name the header:
130
+
131
+ ```python
132
+ from internetdata_flask import header_ip_selector
133
+
134
+ InternetData(
135
+ app,
136
+ api_key=os.environ.get("INTERNETDATA_API_KEY"),
137
+ ip_selector=header_ip_selector("CF-Connecting-IP"), # or True-Client-IP, or your own
138
+ )
139
+ ```
140
+
141
+ `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.
142
+
143
+ Anything else, pass your own callable. It receives the request and returns an address.
144
+
145
+ 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.
146
+
147
+ ## When a lookup fails
148
+
149
+ 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.
150
+
151
+ ## Cost and latency
152
+
153
+ 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`.
154
+
155
+ Skip what you do not care about:
156
+
157
+ ```python
158
+ InternetData(app, skip=lambda request: request.path.startswith("/static"))
159
+ ```
160
+
161
+ Beyond a few million distinct visitors a day, stop calling the API per request: look addresses up locally in [our databases](https://internetdata.io/databases) instead.
162
+
163
+ ## Absent is not false
164
+
165
+ 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".
166
+
167
+ ```python
168
+ lookup().result.flagged("is_vpn") # False rather than None on a plan without it
169
+ ```
170
+
171
+ 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.
172
+
173
+ ## Other Libraries
174
+
175
+ 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.
176
+
177
+ ## About InternetData
178
+
179
+ Geolocation, anonymity, ownership and network data for IP addresses, AS numbers and domains, as an API and as databases you download and query yourself.
180
+
181
+ [<img src="https://s3.internetdata.io/internetdata-public/brand/mark.svg" alt="InternetData" height="64"/>](https://internetdata.io/)
182
+
183
+ ## License
184
+
185
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,156 @@
1
+ # [<img src="https://s3.internetdata.io/internetdata-public/brand/mark.svg" alt="InternetData" height="28"/>](https://internetdata.io/) InternetData Flask Extension
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/internetdata-flask.svg)](https://pypi.org/project/internetdata-flask/)
4
+ [![license](https://img.shields.io/pypi/l/internetdata-flask.svg)](LICENSE)
5
+
6
+ The official [Flask](https://flask.palletsprojects.com) extension for the [InternetData](https://internetdata.io) API.
7
+
8
+ 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.
9
+
10
+ ## Getting Started
11
+
12
+ ```bash
13
+ pip install internetdata-flask
14
+ ```
15
+
16
+ Requires Python 3.11 or newer and Flask 3.0 or newer.
17
+
18
+ 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](https://app.internetdata.io). A free account tries every field, 100 lookups a day.
19
+
20
+ ```python
21
+ from flask import Flask
22
+ from internetdata_flask import InternetData
23
+
24
+ app = Flask(__name__)
25
+ InternetData(app, api_key=os.environ.get("INTERNETDATA_API_KEY"))
26
+ ```
27
+
28
+ `init_app(app)` is supported for the application-factory pattern.
29
+
30
+ ```python
31
+ from internetdata_flask import lookup
32
+
33
+
34
+ @app.route("/")
35
+ def index():
36
+ found = lookup()
37
+ country = found.result.location.country_name if found and found.result else "somewhere"
38
+ return f"Hello, visitor from {country}"
39
+ ```
40
+
41
+ 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.
42
+
43
+ ## Blocking
44
+
45
+ Pass a `block_condition` and a matching request is answered with `403` and never reaches your views.
46
+
47
+ ```python
48
+ InternetData(
49
+ app,
50
+ api_key=os.environ.get("INTERNETDATA_API_KEY"),
51
+ block_condition={"location": {"country": ["CU", "IR", "KP"]}},
52
+ )
53
+ ```
54
+
55
+ 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:
56
+
57
+ ```python
58
+ {"asn": {"type": "hosting"}} # the network's type
59
+ [{"is_anycast": True}, {"is_satellite": True}] # anycast and satellite space
60
+ [{"is_hosting": True}, {"is_cdn": True}] # traffic from servers, not people
61
+ [{"is_vpn": True}, {"is_tor": True}, {"is_resproxy": True}] # anonymity: a list is OR
62
+ {"is_vpn": True, "vpn": {"provider": "nordvpn"}} # one provider
63
+ {"resproxy": {"hits": {"gte": 5}}} # a numeric threshold
64
+ ```
65
+
66
+ 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.
67
+
68
+ Replace the refusal with `on_blocked`, which takes the answer and returns a response:
69
+
70
+ ```python
71
+ InternetData(
72
+ app,
73
+ api_key=os.environ.get("INTERNETDATA_API_KEY"),
74
+ block_condition={"location": {"country": ["CU", "IR", "KP"]}},
75
+ on_blocked=lambda found: (render_template("unavailable.html"), 451),
76
+ )
77
+ ```
78
+
79
+ ### Blocking one view
80
+
81
+ `block_condition` applies to every view. To refuse a visitor on some views only, decorate them below the route, sync or async:
82
+
83
+ ```python
84
+ from internetdata_flask import block_if
85
+
86
+
87
+ @app.get("/checkout")
88
+ @block_if({"location": {"country": ["CU", "IR", "KP"]}})
89
+ def checkout(): ...
90
+ ```
91
+
92
+ `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.
93
+
94
+ ## Where the client address comes from
95
+
96
+ This is the setting that decides whether any of the above works, and it is the one thing only you can get right.
97
+
98
+ 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.
99
+
100
+ For an edge that writes the address into its own header, name the header:
101
+
102
+ ```python
103
+ from internetdata_flask import header_ip_selector
104
+
105
+ InternetData(
106
+ app,
107
+ api_key=os.environ.get("INTERNETDATA_API_KEY"),
108
+ ip_selector=header_ip_selector("CF-Connecting-IP"), # or True-Client-IP, or your own
109
+ )
110
+ ```
111
+
112
+ `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.
113
+
114
+ Anything else, pass your own callable. It receives the request and returns an address.
115
+
116
+ 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.
117
+
118
+ ## When a lookup fails
119
+
120
+ 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.
121
+
122
+ ## Cost and latency
123
+
124
+ 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`.
125
+
126
+ Skip what you do not care about:
127
+
128
+ ```python
129
+ InternetData(app, skip=lambda request: request.path.startswith("/static"))
130
+ ```
131
+
132
+ Beyond a few million distinct visitors a day, stop calling the API per request: look addresses up locally in [our databases](https://internetdata.io/databases) instead.
133
+
134
+ ## Absent is not false
135
+
136
+ 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".
137
+
138
+ ```python
139
+ lookup().result.flagged("is_vpn") # False rather than None on a plan without it
140
+ ```
141
+
142
+ 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.
143
+
144
+ ## Other Libraries
145
+
146
+ 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.
147
+
148
+ ## About InternetData
149
+
150
+ Geolocation, anonymity, ownership and network data for IP addresses, AS numbers and domains, as an API and as databases you download and query yourself.
151
+
152
+ [<img src="https://s3.internetdata.io/internetdata-public/brand/mark.svg" alt="InternetData" height="64"/>](https://internetdata.io/)
153
+
154
+ ## License
155
+
156
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,5 @@
1
+ # Security policy
2
+
3
+ Please report a security issue in this repository by email to support@internetdata.io, not in a public issue, pull request or discussion. Include what you found and the steps that reproduce it.
4
+
5
+ Keep any testing against the InternetData API to your own account and API key, and give us a reasonable chance to fix the issue before you publish it.
@@ -0,0 +1,47 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "internetdata-flask"
7
+ dynamic = ["version"]
8
+ description = "Official Flask extension for the InternetData API. Look up the visitor behind every request: location, network, VPN, proxy, Tor and hosting."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.11"
13
+ authors = [{ name = "Mslm Dev", email = "support@internetdata.io" }]
14
+ keywords = ["internetdata", "ip-geolocation", "ip-intelligence", "ip-lookup", "geoblocking", "vpn-detection", "proxy-detection", "tor", "hosting", "asn", "middleware", "flask"]
15
+ classifiers = [
16
+ "Development Status :: 5 - Production/Stable",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: 3.14",
23
+ "Topic :: Internet",
24
+ "Topic :: Security",
25
+ "Typing :: Typed",
26
+ ]
27
+ dependencies = ["internetdata>=2.12.0,<3", "flask>=3.0"]
28
+
29
+ [project.urls]
30
+ Homepage = "https://internetdata.io"
31
+ Source = "https://github.com/internetdata/sdk-python-flask"
32
+
33
+ [project.optional-dependencies]
34
+ dev = ["pytest>=8", "mypy>=1.11", "ruff>=0.6"]
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["src/internetdata_flask"]
38
+
39
+ [tool.hatch.version]
40
+ path = "src/internetdata_flask/__init__.py"
41
+
42
+ [tool.ruff]
43
+ line-length = 96
44
+
45
+ [tool.mypy]
46
+ python_version = "3.11"
47
+ strict = true