Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ def __init__(
continent: dict[str, Any] | None = None,
country: dict[str, Any] | None = None,
# ... other keyword-only parameters
**_: Any, # ignore unknown keys
**_: object, # ignore unknown keys
) -> None:
```

Key points:
- Use `*` to enforce keyword-only arguments
- Accept `**_: Any` to ignore unknown keys from the API
- Accept `**_: object` to ignore unknown keys from the API
- Use `| None = None` for optional parameters
- Boolean fields default to `False` if not present

Expand Down Expand Up @@ -251,7 +251,7 @@ When creating a new model class:
3. **Extend the appropriate base class** (e.g., `Country`, `City`, `SimpleModel`)
4. **Use type hints** for all attributes
5. **Use keyword-only arguments** with `*` separator
6. **Accept `**_: Any`** to ignore unknown API keys
6. **Accept `**_: object`** to ignore unknown API keys
7. **Provide comprehensive docstrings** for all attributes
8. **Add corresponding tests** with full coverage

Expand Down
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ History
``aiohttp.encode_basic_auth()`` instead of the ``aiohttp.BasicAuth`` /
``auth=`` parameter, which are deprecated as of aiohttp 3.14.0. As a result,
the minimum required ``aiohttp`` version is now 3.14.0.
* A new ``residential`` attribute has been added to
``geoip2.records.Anonymizer``. This is a ``geoip2.records.AnonymizerFeed``
object providing residential proxy data for the network and contains the
following fields: ``confidence``, ``network_last_seen``, and
``provider_name``. This attribute may be populated even when no other
anonymizer attributes are set, so the ``anonymizer`` object may now
contain only this attribute.

5.2.0 (2025-11-20)
++++++++++++++++++
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ ignore = [

[tool.ruff.lint.per-file-ignores]
"docs/*" = ["ALL"]
"src/geoip2/{models,records}.py" = [ "ANN401", "D107", "PLR0913" ]
"src/geoip2/{models,records}.py" = [ "D107", "PLR0913" ]
# FBT003: We use assertIs with boolean literals to verify values are actual
# booleans (True/False), not just truthy/falsy values
"tests/*" = ["ANN201", "D", "FBT003"]
Expand Down
18 changes: 9 additions & 9 deletions src/geoip2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(
registered_country: dict[str, Any] | None = None,
represented_country: dict[str, Any] | None = None,
traits: dict[str, Any] | None = None,
**_: Any,
**_: object,
) -> None:
self._locales = locales
self.continent = geoip2.records.Continent(locales, **(continent or {}))
Expand Down Expand Up @@ -127,7 +127,7 @@ def __init__(
represented_country: dict[str, Any] | None = None,
subdivisions: list[dict[str, Any]] | None = None,
traits: dict[str, Any] | None = None,
**_: Any,
**_: object,
) -> None:
super().__init__(
locales,
Expand Down Expand Up @@ -171,7 +171,7 @@ def __init__(
represented_country: dict[str, Any] | None = None,
subdivisions: list[dict[str, Any]] | None = None,
traits: dict[str, Any] | None = None,
**_: Any,
**_: object,
) -> None:
super().__init__(
locales,
Expand Down Expand Up @@ -301,7 +301,7 @@ def __init__(
is_tor_exit_node: bool = False,
network: str | None = None,
prefix_len: int | None = None,
**_: Any,
**_: object,
) -> None:
super().__init__(ip_address, network, prefix_len)
self.is_anonymous = is_anonymous
Expand Down Expand Up @@ -345,7 +345,7 @@ def __init__(
network_last_seen: str | None = None,
prefix_len: int | None = None,
provider_name: str | None = None,
**_: Any,
**_: object,
) -> None:
super().__init__(
is_anonymous=is_anonymous,
Expand Down Expand Up @@ -383,7 +383,7 @@ def __init__(
autonomous_system_organization: str | None = None,
network: str | None = None,
prefix_len: int | None = None,
**_: Any,
**_: object,
) -> None:
super().__init__(ip_address, network, prefix_len)
self.autonomous_system_number = autonomous_system_number
Expand Down Expand Up @@ -412,7 +412,7 @@ def __init__(
connection_type: str | None = None,
network: str | None = None,
prefix_len: int | None = None,
**_: Any,
**_: object,
) -> None:
super().__init__(ip_address, network, prefix_len)
self.connection_type = connection_type
Expand All @@ -431,7 +431,7 @@ def __init__(
domain: str | None = None,
network: str | None = None,
prefix_len: int | None = None,
**_: Any,
**_: object,
) -> None:
super().__init__(ip_address, network, prefix_len)
self.domain = domain
Expand Down Expand Up @@ -470,7 +470,7 @@ def __init__(
organization: str | None = None,
network: str | None = None,
prefix_len: int | None = None,
**_: Any,
**_: object,
) -> None:
super().__init__(
autonomous_system_number=autonomous_system_number,
Expand Down
76 changes: 66 additions & 10 deletions src/geoip2/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(
confidence: int | None = None,
geoname_id: int | None = None,
names: dict[str, str] | None = None,
**_: Any,
**_: object,
) -> None:
self.confidence = confidence
self.geoname_id = geoname_id
Expand Down Expand Up @@ -102,7 +102,7 @@ def __init__(
code: str | None = None,
geoname_id: int | None = None,
names: dict[str, str] | None = None,
**_: Any,
**_: object,
) -> None:
self.code = code
self.geoname_id = geoname_id
Expand Down Expand Up @@ -139,7 +139,7 @@ def __init__(
is_in_european_union: bool = False,
iso_code: str | None = None,
names: dict[str, str] | None = None,
**_: Any,
**_: object,
) -> None:
self.confidence = confidence
self.geoname_id = geoname_id
Expand Down Expand Up @@ -172,7 +172,7 @@ def __init__(
iso_code: str | None = None,
names: dict[str, str] | None = None,
type: str | None = None, # noqa: A002
**_: Any,
**_: object,
) -> None:
self.type = type
super().__init__(
Expand Down Expand Up @@ -239,7 +239,7 @@ def __init__(
metro_code: int | None = None,
population_density: int | None = None,
time_zone: str | None = None,
**_: Any,
**_: object,
) -> None:
self.average_income = average_income
self.accuracy_radius = accuracy_radius
Expand All @@ -258,15 +258,63 @@ class MaxMind(Record):
calling.
"""

def __init__(self, *, queries_remaining: int | None = None, **_: Any) -> None:
def __init__(self, *, queries_remaining: int | None = None, **_: object) -> None:
self.queries_remaining = queries_remaining


class AnonymizerFeed(Record):
"""Contains data for one type of anonymizer detection.

This class contains data for one type of anonymizer detection,
currently residential proxies. Additional feeds may be added in the
future.

This record is returned by ``insights`` as the ``residential`` attribute
of :py:class:`Anonymizer`.
"""

confidence: int | None
"""A score ranging from 1 to 99 that represents our percent confidence
that the network is currently part of this anonymizer feed. This
attribute is only available from the Insights end point.
"""

network_last_seen: datetime.date | None
"""The last day that the network was sighted in our analysis of this
anonymizer feed. This attribute is only available from the Insights end
point.
"""

provider_name: str | None
"""The name of the provider associated with the network in this
anonymizer feed. This attribute is only available from the Insights end
point.
"""

def __init__(
self,
*,
confidence: int | None = None,
network_last_seen: str | None = None,
provider_name: str | None = None,
**_: object,
) -> None:
Comment thread
coderabbitai[bot] marked this conversation as resolved.
self.confidence = confidence
self.network_last_seen = (
datetime.date.fromisoformat(network_last_seen)
if network_last_seen
else None
)
self.provider_name = provider_name


class Anonymizer(Record):
"""Contains data for the anonymizer record associated with an IP address.

This class contains the anonymizer data associated with an IP address.

Note that this object may contain only the ``residential`` attribute.

This record is returned by ``insights``.
"""

Expand All @@ -288,6 +336,12 @@ class Anonymizer(Record):
point.
"""

residential: AnonymizerFeed
"""Residential proxy data for the network associated with the IP address.
This may be populated even when no other anonymizer attributes are set.
This attribute is only available from the Insights end point.
"""

is_anonymous: bool
"""This is true if the IP address belongs to any sort of anonymous network.
This attribute is only available from the Insights end point.
Expand Down Expand Up @@ -337,7 +391,8 @@ def __init__(
is_tor_exit_node: bool = False,
network_last_seen: str | None = None,
provider_name: str | None = None,
**_: Any,
residential: dict[str, Any] | None = None,
**_: object,
) -> None:
self.confidence = confidence
self.is_anonymous = is_anonymous
Expand All @@ -352,6 +407,7 @@ def __init__(
else None
)
self.provider_name = provider_name
self.residential = AnonymizerFeed(**(residential or {}))


class Postal(Record):
Expand All @@ -378,7 +434,7 @@ def __init__(
*,
code: str | None = None,
confidence: int | None = None,
**_: Any,
**_: object,
) -> None:
self.code = code
self.confidence = confidence
Expand Down Expand Up @@ -412,7 +468,7 @@ def __init__(
geoname_id: int | None = None,
iso_code: str | None = None,
names: dict[str, str] | None = None,
**_: Any,
**_: object,
) -> None:
self.confidence = confidence
self.geoname_id = geoname_id
Expand Down Expand Up @@ -708,7 +764,7 @@ def __init__(
mobile_country_code: str | None = None,
mobile_network_code: str | None = None,
is_anycast: bool = False,
**_: Any,
**_: object,
) -> None:
self.autonomous_system_number = autonomous_system_number
self.autonomous_system_organization = autonomous_system_organization
Expand Down
Loading
Loading