vpndetection-fastapi 2.2.6__tar.gz → 2.2.7__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.
@@ -2,6 +2,12 @@
2
2
 
3
3
  What each release changed for you, newest first. Each line is a commit's summary, linked to its full description and diff. Releases before 2.0.5 are described by their release commits.
4
4
 
5
+ ## 2.2.7 - 2026-11-29
6
+
7
+ ### Features
8
+
9
+ - Require vpndetection 5.25.0: an answer without is_vpn reads, and a condition on it is a plan gap ([`73a5288`](https://github.com/vpndetection-io/sdk-python-fastapi/commit/73a5288079a200b728fa3b118f529a27e6b5b643))
10
+
5
11
  ## 2.2.6 - 2026-11-27
6
12
 
7
13
  ### Features
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: vpndetection-fastapi
3
- Version: 2.2.6
3
+ Version: 2.2.7
4
4
  Summary: Official FastAPI and Starlette middleware for the VPNDetection API. Detect VPNs, proxies, Tor, hosting and CDN visitors on every request.
5
5
  Project-URL: Homepage, https://vpndetection.io
6
6
  Project-URL: Source, https://github.com/vpndetection-io/sdk-python-fastapi
@@ -20,7 +20,7 @@ Classifier: Topic :: Security
20
20
  Classifier: Typing :: Typed
21
21
  Requires-Python: >=3.11
22
22
  Requires-Dist: starlette>=0.37
23
- Requires-Dist: vpndetection<6,>=5.24.0
23
+ Requires-Dist: vpndetection<6,>=5.25.0
24
24
  Provides-Extra: dev
25
25
  Requires-Dist: fastapi>=0.115; extra == 'dev'
26
26
  Requires-Dist: mypy>=1.11; extra == 'dev'
@@ -45,7 +45,7 @@ pip install vpndetection-fastapi
45
45
 
46
46
  Requires Python 3.11 or newer.
47
47
 
48
- No API key needed to start. Without one, a lookup is on Unlimited, the free plan, which answers VPN, Tor and relay detection with no daily or monthly cap. A paid plan's key adds the hosting, CDN and proxy flags and the provider behind each flag: create one in the [console](https://app.vpndetection.io). A free account tries every field.
48
+ Lookups need no API key to try: the free plan answers each address's first lookups of the day without one. A free API key answers your organization's first lookups each day with every field, and the basics with no cap. The Data plan answers every field on every lookup, with the hosting, CDN and proxy flags and the provider behind each flag: create a key in the [console](https://app.vpndetection.io).
49
49
 
50
50
  ```python
51
51
  from fastapi import FastAPI
@@ -106,7 +106,7 @@ app.add_middleware(
106
106
  )
107
107
  ```
108
108
 
109
- With it on, a condition can name the verdict, refusing a forged crawler: `{"user_agent": {"verdict": "spoofed"}}`. Only a paid plan's answer carries `user_agent`: a keyless client, or a free key past its trial, never gets a verdict and lets no crawler through, and the middleware warns once when that happens. `bot` and `is_bot` are a paid plan's too, so a keyless app gets no bot pass.
109
+ With it on, a condition can name the verdict, refusing a forged crawler: `{"user_agent": {"verdict": "spoofed"}}`. Only a paid plan's answer carries `user_agent`: a keyless client, or a free key past its organization's full answers for the day, never gets a verdict and lets no crawler through, and the middleware warns once when that happens. `bot` and `is_bot` are a paid plan's too, so a keyless app gets no bot pass.
110
110
 
111
111
  ### Blocking one endpoint
112
112
 
@@ -161,7 +161,7 @@ Beyond a few million distinct visitors a day, stop calling the API per request:
161
161
 
162
162
  ## Absent is not false
163
163
 
164
- Unlimited, with a key or without one, leaves out `is_hosting`, `is_cdn`, the four proxy flags, `is_bot`, the carrier, satellite and service flags, `bot`, `company` and `abuse`, the AS's `type`, and of the detail behind each flag it answers only Tor's and relay's. A field your plan does not include is `None`, which means "not in your plan" rather than "checked, and no". The AS's `type` is the exception: it stays a `str` and reads `""` when the answer leaves it out.
164
+ The free plan's answer, without a key or past a free key's full answers for the day, leaves out `is_hosting`, `is_cdn`, the four proxy flags, `is_bot`, the carrier, satellite and service flags, `bot`, `company` and `abuse`, the AS's `type`, and of the detail behind each flag it answers only Tor's and relay's. A field your plan does not include is `None`, which means "not in your plan" rather than "checked, and no". The AS's `type` and `is_vpn` are the exceptions: they stay a `str` and a `bool`, and read `""` and `False` when the answer leaves them out. `is_vpn` is absent from a free key's answer past its organization's full answers for the day, when `trial_expired` is true, and that `False` means "not in this answer", never "not a VPN": a `block_condition` on it never matches such an answer, and the middleware reports it as a member the plan does not include.
165
165
 
166
166
  ```python
167
167
  lookup(request).result.is_hosting # None when your plan does not include it
@@ -15,7 +15,7 @@ pip install vpndetection-fastapi
15
15
 
16
16
  Requires Python 3.11 or newer.
17
17
 
18
- No API key needed to start. Without one, a lookup is on Unlimited, the free plan, which answers VPN, Tor and relay detection with no daily or monthly cap. A paid plan's key adds the hosting, CDN and proxy flags and the provider behind each flag: create one in the [console](https://app.vpndetection.io). A free account tries every field.
18
+ Lookups need no API key to try: the free plan answers each address's first lookups of the day without one. A free API key answers your organization's first lookups each day with every field, and the basics with no cap. The Data plan answers every field on every lookup, with the hosting, CDN and proxy flags and the provider behind each flag: create a key in the [console](https://app.vpndetection.io).
19
19
 
20
20
  ```python
21
21
  from fastapi import FastAPI
@@ -76,7 +76,7 @@ app.add_middleware(
76
76
  )
77
77
  ```
78
78
 
79
- With it on, a condition can name the verdict, refusing a forged crawler: `{"user_agent": {"verdict": "spoofed"}}`. Only a paid plan's answer carries `user_agent`: a keyless client, or a free key past its trial, never gets a verdict and lets no crawler through, and the middleware warns once when that happens. `bot` and `is_bot` are a paid plan's too, so a keyless app gets no bot pass.
79
+ With it on, a condition can name the verdict, refusing a forged crawler: `{"user_agent": {"verdict": "spoofed"}}`. Only a paid plan's answer carries `user_agent`: a keyless client, or a free key past its organization's full answers for the day, never gets a verdict and lets no crawler through, and the middleware warns once when that happens. `bot` and `is_bot` are a paid plan's too, so a keyless app gets no bot pass.
80
80
 
81
81
  ### Blocking one endpoint
82
82
 
@@ -131,7 +131,7 @@ Beyond a few million distinct visitors a day, stop calling the API per request:
131
131
 
132
132
  ## Absent is not false
133
133
 
134
- Unlimited, with a key or without one, leaves out `is_hosting`, `is_cdn`, the four proxy flags, `is_bot`, the carrier, satellite and service flags, `bot`, `company` and `abuse`, the AS's `type`, and of the detail behind each flag it answers only Tor's and relay's. A field your plan does not include is `None`, which means "not in your plan" rather than "checked, and no". The AS's `type` is the exception: it stays a `str` and reads `""` when the answer leaves it out.
134
+ The free plan's answer, without a key or past a free key's full answers for the day, leaves out `is_hosting`, `is_cdn`, the four proxy flags, `is_bot`, the carrier, satellite and service flags, `bot`, `company` and `abuse`, the AS's `type`, and of the detail behind each flag it answers only Tor's and relay's. A field your plan does not include is `None`, which means "not in your plan" rather than "checked, and no". The AS's `type` and `is_vpn` are the exceptions: they stay a `str` and a `bool`, and read `""` and `False` when the answer leaves them out. `is_vpn` is absent from a free key's answer past its organization's full answers for the day, when `trial_expired` is true, and that `False` means "not in this answer", never "not a VPN": a `block_condition` on it never matches such an answer, and the middleware reports it as a member the plan does not include.
135
135
 
136
136
  ```python
137
137
  lookup(request).result.is_hosting # None when your plan does not include it
@@ -24,7 +24,7 @@ classifiers = [
24
24
  "Topic :: Security",
25
25
  "Typing :: Typed",
26
26
  ]
27
- dependencies = ["vpndetection>=5.24.0,<6", "starlette>=0.37"]
27
+ dependencies = ["vpndetection>=5.25.0,<6", "starlette>=0.37"]
28
28
 
29
29
  [project.urls]
30
30
  Homepage = "https://vpndetection.io"
@@ -45,7 +45,7 @@ __all__ = [
45
45
  "xff_ip_selector",
46
46
  ]
47
47
 
48
- __version__ = "2.2.6"
48
+ __version__ = "2.2.7"
49
49
 
50
50
  # Set on a request ``skip`` claimed, so block_if can tell it from one the middleware
51
51
  # never saw.
@@ -1839,8 +1839,8 @@
1839
1839
  }
1840
1840
  },
1841
1841
  {
1842
- "name": "unlimited-location-asn",
1843
- "why": "The Unlimited tier's answer, with a key or without one: Tor and relay beside the VPN flag, and where the address is and which AS announces it. location and asn carry every key whenever present, so each maps whole.",
1842
+ "name": "free-location-asn",
1843
+ "why": "The free plan's answer, with a key or without one: Tor and relay beside the VPN flag, and where the address is and which AS announces it. location and asn carry every key whenever present, so each maps whole.",
1844
1844
  "status": 200,
1845
1845
  "body": {
1846
1846
  "ip": "146.70.116.130",
@@ -1922,7 +1922,7 @@
1922
1922
  },
1923
1923
  {
1924
1924
  "name": "flags-without-detail",
1925
- "why": "Every flag, but no detail object behind the six flags past the Unlimited tier's and no vpn object. Each flag maps on its own, and the detail it lacks stays absent rather than empty.",
1925
+ "why": "Every flag, but no detail object behind the six flags past the free plan's and no vpn object. Each flag maps on its own, and the detail it lacks stays absent rather than empty.",
1926
1926
  "status": 200,
1927
1927
  "body": {
1928
1928
  "ip": "146.70.116.130",
@@ -2010,8 +2010,8 @@
2010
2010
  }
2011
2011
  },
2012
2012
  {
2013
- "name": "trial-full-answer",
2014
- "why": "A free-plan key within its trial: every field, as a paid plan answers it, and trial_expired false. trial_expired maps on presence like any flag.",
2013
+ "name": "free-key-full-answer",
2014
+ "why": "A free-plan key within its organization's full answers for the day: every field, as a paid plan answers it, and trial_expired false. trial_expired maps on presence like any flag.",
2015
2015
  "status": 200,
2016
2016
  "body": {
2017
2017
  "ip": "146.70.116.130",
@@ -2117,12 +2117,11 @@
2117
2117
  }
2118
2118
  },
2119
2119
  {
2120
- "name": "trial-expired-answer",
2121
- "why": "A free-plan key past its trial: Unlimited's answer, and trial_expired true. What the trial no longer answers is absent, never false.",
2120
+ "name": "free-key-basics",
2121
+ "why": "A free-plan key past its organization's full answers for the day: the basics, with no is_vpn and no AS type, and trial_expired true. What the day no longer answers is absent, never false. A binding whose public is_vpn is a plain boolean reads it false here and keeps it among the members the wire left out, as it keeps asn.type, so a condition on it is a plan gap.",
2122
2122
  "status": 200,
2123
2123
  "body": {
2124
2124
  "ip": "146.70.116.130",
2125
- "is_vpn": true,
2126
2125
  "is_relay": false,
2127
2126
  "is_tor": false,
2128
2127
  "relay": {},
@@ -2153,12 +2152,12 @@
2153
2152
  "ip": "146.70.116.130",
2154
2153
  "isBogon": false,
2155
2154
  "present": {
2156
- "is_vpn": true,
2157
2155
  "is_relay": false,
2158
2156
  "is_tor": false,
2159
2157
  "trial_expired": true
2160
2158
  },
2161
2159
  "absent": [
2160
+ "is_vpn",
2162
2161
  "is_hosting",
2163
2162
  "is_cdn",
2164
2163
  "is_resproxy",
@@ -2201,7 +2200,7 @@
2201
2200
  },
2202
2201
  {
2203
2202
  "name": "cap-reached-answer",
2204
- "why": "A paid-plan key past its organization's overage cap: Unlimited's answer, not billed, and cap_reached true. What the cap no longer answers is absent, never false.",
2203
+ "why": "A paid-plan key past its organization's overage cap: the basics and is_vpn, not billed, and cap_reached true. What the cap no longer answers is absent, never false.",
2205
2204
  "status": 200,
2206
2205
  "body": {
2207
2206
  "ip": "146.70.116.130",
@@ -2284,8 +2283,8 @@
2284
2283
  }
2285
2284
  },
2286
2285
  {
2287
- "name": "unlimited-anycast-hostname",
2288
- "why": "Unlimited's answer, with a key or without one, also carries is_anycast, hostname, and the AS's country and RPKI status. The paid members, is_bot among them, stay absent, never false or empty.",
2286
+ "name": "free-anycast-hostname",
2287
+ "why": "The free plan's answer, with a key or without one, also carries is_anycast, hostname, and the AS's country and RPKI status. The paid members, is_bot among them, stay absent, never false or empty.",
2289
2288
  "status": 200,
2290
2289
  "body": {
2291
2290
  "ip": "1.1.1.1",
@@ -3049,8 +3048,8 @@
3049
3048
  }
3050
3049
  },
3051
3050
  {
3052
- "name": "unlimited-bot",
3053
- "why": "Unlimited's answer for an address a bot uses, here a verified Googlebot crawler's: is_bot and the bot object are a paid plan's and stay absent, never false or empty.",
3051
+ "name": "free-bot",
3052
+ "why": "The free plan's answer for an address a bot uses, here a verified Googlebot crawler's: is_bot and the bot object are a paid plan's and stay absent, never false or empty.",
3054
3053
  "status": 200,
3055
3054
  "body": {
3056
3055
  "ip": "66.249.66.1",
@@ -3384,14 +3383,14 @@
3384
3383
  }
3385
3384
  },
3386
3385
  {
3387
- "name": "unlimited-rate-limit-is-retryable",
3388
- "why": "Retry-After present. A lookup on Unlimited, the free plan, with a key or without one, that the API is protecting itself from is told when to come back, which is a rate limit, so retrying after the wait WILL succeed.",
3386
+ "name": "free-rate-limit-is-retryable",
3387
+ "why": "Retry-After present. A lookup on the free plan, with a key or without one, that the API is protecting itself from is told when to come back, which is a rate limit, so retrying after the wait WILL succeed.",
3389
3388
  "status": 429,
3390
3389
  "headers": {
3391
3390
  "Retry-After": "1"
3392
3391
  },
3393
3392
  "body": {
3394
- "error": "rate limit for Unlimited lookups exceeded; retry shortly, or use a paid plan"
3393
+ "error": "rate limit for free lookups exceeded; retry shortly, or use a paid plan"
3395
3394
  },
3396
3395
  "expect": {
3397
3396
  "kind": "rate_limited",
@@ -3426,6 +3425,19 @@
3426
3425
  "retryable": false
3427
3426
  }
3428
3427
  },
3428
+ {
3429
+ "name": "keyless-day-spent-is-not-retryable",
3430
+ "why": "No Retry-After. A lookup with no key past its address's lookups for the day: a spent allowance, which a free API key answers past, so it is sent once and reaches the caller as quota_exceeded with the API's message.",
3431
+ "status": 429,
3432
+ "headers": {},
3433
+ "body": {
3434
+ "error": "lookups without an API key are used up for today; a free key answers on: https://app.vpndetection.io/auth/signup"
3435
+ },
3436
+ "expect": {
3437
+ "kind": "quota_exceeded",
3438
+ "retryable": false
3439
+ }
3440
+ },
3429
3441
  {
3430
3442
  "name": "server-error-is-retryable",
3431
3443
  "status": 500,
@@ -8454,7 +8466,7 @@
8454
8466
  },
8455
8467
  {
8456
8468
  "name": "asn-type-matches",
8457
- "why": "The network's type is a paid plan's: Unlimited does not serve it, so the term can never match and is reported by its path.",
8469
+ "why": "The network's type is a paid plan's: the free plan does not serve it, so the term can never match and is reported by its path.",
8458
8470
  "body": {
8459
8471
  "ip": "146.70.116.130",
8460
8472
  "is_vpn": true,
@@ -8495,6 +8507,47 @@
8495
8507
  ]
8496
8508
  }
8497
8509
  },
8510
+ {
8511
+ "name": "is-vpn-past-the-days-full-answers",
8512
+ "why": "A free-plan key past its organization's full answers for the day gets the basics, with no is_vpn: the term can never match, so it is reported as a plan gap, never read as false.",
8513
+ "body": {
8514
+ "ip": "146.70.116.130",
8515
+ "is_relay": false,
8516
+ "is_tor": false,
8517
+ "relay": {},
8518
+ "tor": {},
8519
+ "location": {
8520
+ "continent": "EU",
8521
+ "continent_name": "Europe",
8522
+ "country": "AT",
8523
+ "country_name": "Austria",
8524
+ "timezone": "Europe/Vienna",
8525
+ "currency_code": "EUR",
8526
+ "currency_name": "Euro",
8527
+ "currency_symbol": "€",
8528
+ "flag_emoji": "🇦🇹",
8529
+ "flag_unicode": "U+1F1E6 U+1F1F9"
8530
+ },
8531
+ "asn": {
8532
+ "asn": 9009,
8533
+ "name": "M247 Europe SRL",
8534
+ "domain": "m247global.com",
8535
+ "prefix": "146.70.116.0/24",
8536
+ "country": "US",
8537
+ "rpki_status": "valid"
8538
+ },
8539
+ "trial_expired": true
8540
+ },
8541
+ "condition": {
8542
+ "is_vpn": true
8543
+ },
8544
+ "expect": {
8545
+ "blocked": false,
8546
+ "missing": [
8547
+ "is_vpn"
8548
+ ]
8549
+ }
8550
+ },
8498
8551
  {
8499
8552
  "name": "asn-number-matches",
8500
8553
  "why": "The AS number compares as a number.",
@@ -11009,7 +11062,7 @@
11009
11062
  "cases": [
11010
11063
  {
11011
11064
  "name": "entitlement-plan-name",
11012
- "why": "The plan's name is what a client shows, and key is what it compares: the free plan's key is free and its name Unlimited. A binding that drops name leaves a client building one from the key, which a renamed plan then gets wrong.",
11065
+ "why": "The plan's name is what a client shows, and key is what it compares: the free plan's key is free and its name Free. A binding that drops name leaves a client building one from the key, which a renamed plan then gets wrong.",
11013
11066
  "call": "myEntitlement",
11014
11067
  "answer": {
11015
11068
  "org_id": "85bb51e4-2eb6-4a31-8e4d-02ba8b98fe61",
@@ -11020,7 +11073,7 @@
11020
11073
  },
11021
11074
  "plan": {
11022
11075
  "key": "free",
11023
- "name": "Unlimited",
11076
+ "name": "Free",
11024
11077
  "tier": "free"
11025
11078
  },
11026
11079
  "usage": {
@@ -11033,7 +11086,7 @@
11033
11086
  },
11034
11087
  "expect": {
11035
11088
  "plan.key": "free",
11036
- "plan.name": "Unlimited",
11089
+ "plan.name": "Free",
11037
11090
  "plan.tier": "free"
11038
11091
  }
11039
11092
  },
@@ -154,6 +154,31 @@ def test_an_answer_without_the_asn_type_is_read_and_a_condition_on_it_never_matc
154
154
  assert status == 403, "the same condition blocks an answer that carries the type"
155
155
 
156
156
 
157
+ def test_an_answer_without_is_vpn_is_read_and_a_condition_on_it_never_matches() -> None:
158
+ """A free key past its organization's full answers for the day gets the basics, with no
159
+ ``is_vpn``: read, attached as false, and a condition on it is a plan gap, never a block."""
160
+ warnings: list[str] = []
161
+ basics = serving({"is_relay": False, "is_tor": False, "asn": ASN, "trial_expired": True})
162
+ status, body = get(
163
+ app_with(
164
+ client=basics,
165
+ ip_selector=fixed_ip,
166
+ block_condition={"is_vpn": True},
167
+ on_warn=warnings.append,
168
+ )
169
+ )
170
+ assert status == 200
171
+ assert body["error"] is None and body["is_vpn"] is False, "the answer was read and attached"
172
+ reported = [w for w in warnings if "does not include" in w]
173
+ assert len(reported) == 1 and "is_vpn" in reported[0]
174
+
175
+ full = serving({"is_vpn": True, "asn": {**ASN, "type": "hosting"}})
176
+ status, _ = get(
177
+ app_with(client=full, ip_selector=fixed_ip, block_condition={"is_vpn": True})
178
+ )
179
+ assert status == 403, "the same condition blocks an answer that carries it"
180
+
181
+
157
182
  def test_a_condition_reaches_the_evidence_fields() -> None:
158
183
  nord = serving({"is_vpn": True, "vpn": {"provider": "nordvpn"}})
159
184
  status, _ = get(
@@ -464,7 +489,7 @@ def api_answering(
464
489
  ) -> list[str | None]:
465
490
  """The API's host, answering every lookup as a match for ``{"is_hosting": True}`` and,
466
491
  for a sent agent, with the verdict ``verdicts`` holds for it (None: no verdict, as
467
- Unlimited answers). Returns the ``user_agent`` each lookup sent."""
492
+ the free plan's answers). Returns the ``user_agent`` each lookup sent."""
468
493
  sent: list[str | None] = []
469
494
 
470
495
  async def handle(
@@ -570,3 +595,32 @@ def test_an_answer_without_a_verdict_warns_once(monkeypatch: pytest.MonkeyPatch)
570
595
 
571
596
  assert sent == [GOOGLEBOT, GOOGLEBOT]
572
597
  assert len([w for w in warnings if "user_agent verdict" in w]) == 1, warnings
598
+
599
+
600
+ @pytest.mark.parametrize("url", ["/", "/guarded"])
601
+ @pytest.mark.parametrize("action", ["raise", "warn"])
602
+ @pytest.mark.parametrize("peer", ["127.0.0.1", "10.0.0.1", "::1"])
603
+ def test_a_bogon_peer_with_a_crawlers_agent_is_no_plan_gap(
604
+ monkeypatch: pytest.MonkeyPatch, peer: str, action: str, url: str
605
+ ) -> None:
606
+ # Local development behind no proxy. This is NOT the public-peer test above: the peer is
607
+ # answered locally, so the question is only that no plan gap is reported for it.
608
+ sent = api_answering(monkeypatch, {GOOGLEBOT: "spoofed"})
609
+ warnings: list[str] = []
610
+ forged = {"user_agent": {"verdict": "spoofed"}}
611
+ options: dict[str, Any] = {
612
+ "allow_bots": True,
613
+ "on_missing_field": action,
614
+ "on_warn": warnings.append,
615
+ }
616
+ if url == "/":
617
+ options["block_condition"] = forged
618
+ app = fastapi_with(
619
+ {"condition": forged, "on_missing_field": "raise"},
620
+ api_key=os.environ["VPNDETECTION_API_KEY"],
621
+ **options,
622
+ )
623
+
624
+ assert visit(app, (GOOGLEBOT, url, peer)) == [200]
625
+ assert sent == [], "a bogon reached the API"
626
+ assert [w for w in warnings if "does not include" in w] == []