1+ """C extension database reader and related classes."""
2+
13from ipaddress import IPv4Address , IPv6Address
24from os import PathLike
35from typing import IO , Any , AnyStr
@@ -7,24 +9,60 @@ from typing_extensions import Self
79from maxminddb .types import Record
810
911class Reader :
12+ """A C extension implementation of a reader for the MaxMind DB format.
13+
14+ IP addresses can be looked up using the ``get`` method.
15+ """
16+
1017 closed : bool = ...
1118
1219 def __init__ (
1320 self ,
1421 database : AnyStr | int | PathLike | IO ,
1522 mode : int = ...,
16- ) -> None : ...
17- def close (self ) -> None : ...
18- def get (self , ip_address : str | IPv6Address | IPv4Address ) -> Record | None : ...
23+ ) -> None :
24+ """Reader for the MaxMind DB file format.
25+
26+ Arguments:
27+ database: A path to a valid MaxMind DB file such as a GeoIP2 database
28+ file, or a file descriptor in the case of MODE_FD.
29+ mode: mode to open the database with. The only supported modes are
30+ MODE_AUTO and MODE_MMAP_EXT.
31+
32+ """
33+
34+ def close (self ) -> None :
35+ """Close the MaxMind DB file and returns the resources to the system."""
36+
37+ def get (self , ip_address : str | IPv6Address | IPv4Address ) -> Record | None :
38+ """Return the record for the ip_address in the MaxMind DB.
39+
40+ Arguments:
41+ ip_address: an IP address in the standard string notation
42+
43+ """
44+
1945 def get_with_prefix_len (
2046 self ,
2147 ip_address : str | IPv6Address | IPv4Address ,
22- ) -> tuple [Record | None , int ]: ...
23- def metadata (self ) -> Metadata : ...
48+ ) -> tuple [Record | None , int ]:
49+ """Return a tuple with the record and the associated prefix length.
50+
51+ Arguments:
52+ ip_address: an IP address in the standard string notation
53+
54+ """
55+
56+ def metadata (self ) -> Metadata :
57+ """Return the metadata associated with the MaxMind DB file."""
58+
2459 def __enter__ (self ) -> Self : ...
2560 def __exit__ (self , * args ) -> None : ... # noqa: ANN002
2661
62+ # pylint: disable=too-few-public-methods
2763class Metadata :
64+ """Metadata for the MaxMind DB reader."""
65+
2866 binary_format_major_version : int
2967 """
3068 The major version number of the binary format used when creating the
@@ -74,4 +112,5 @@ class Metadata:
74112 The bit size of a record in the search tree.
75113 """
76114
77- def __init__ (self , ** kwargs : Any ) -> None : ... # noqa: ANN401
115+ def __init__ (self , ** kwargs : Any ) -> None : # noqa: ANN401
116+ """Create new Metadata object. kwargs are key/value pairs from spec."""
0 commit comments