geoip2


Namegeoip2 JSON
Version 4.8.0 PyPI version JSON
download
home_page
SummaryMaxMind GeoIP2 API
upload_time2023-12-05 22:31:13
maintainer
docs_urlhttps://pythonhosted.org/geoip2/
author
requires_python>=3.8
licenseApache License, Version 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            =========================
MaxMind GeoIP2 Python API
=========================

Description
-----------

This package provides an API for the GeoIP2 and GeoLite2 `web services
<https://dev.maxmind.com/geoip/docs/web-services?lang=en>`_ and `databases
<https://dev.maxmind.com/geoip/docs/databases?lang=en>`_.

Installation
------------

To install the ``geoip2`` module, type:

.. code-block:: bash

    $ pip install geoip2

If you are not able to use pip, you may also use easy_install from the
source directory:

.. code-block:: bash

    $ easy_install .

Database Reader Extension
^^^^^^^^^^^^^^^^^^^^^^^^^

If you wish to use the C extension for the database reader, you must first
install the `libmaxminddb C API <https://github.com/maxmind/libmaxminddb>`_.
Please `see the instructions distributed with it
<https://github.com/maxmind/libmaxminddb/blob/main/README.md>`_.

IP Geolocation Usage
--------------------

IP geolocation is inherently imprecise. Locations are often near the center of
the population. Any location provided by a GeoIP2 database or web service
should not be used to identify a particular address or household.

Web Service Usage
-----------------

To use this API, you first construct either a ``geoip2.webservice.Client`` or
``geoip2.webservice.AsyncClient``, passing your MaxMind ``account_id`` and
``license_key`` to the constructor. To use the GeoLite2 web service instead of
the GeoIP2 web service, set the optional ``host`` keyword argument to
``geolite.info``. To use the Sandbox GeoIP2 web service instead of the
production GeoIP2 web service, set the optional ``host`` keyword argument to
``sandbox.maxmind.com``.

After doing this, you may call the method corresponding to request type
(e.g., ``city`` or ``country``), passing it the IP address you want to look up.

If the request succeeds, the method call will return a model class for the
endpoint you called. This model in turn contains multiple record classes,
each of which represents part of the data returned by the web service.

If the request fails, the client class throws an exception.

Sync Web Service Example
------------------------

.. code-block:: pycon

    >>> import geoip2.webservice
    >>>
    >>> # This creates a Client object that can be reused across requests.
    >>> # Replace "42" with your account ID and "license_key" with your license
    >>> # key. Set the "host" keyword argument to "geolite.info" to use the
    >>> # GeoLite2 web service instead of the GeoIP2 web service. Set the
    >>> # "host" keyword argument to "sandbox.maxmind.com" to use the Sandbox
    >>> # GeoIP2 web service instead of the production GeoIP2 web service.
    >>> with geoip2.webservice.Client(42, 'license_key') as client:
    >>>
    >>>     # Replace "city" with the method corresponding to the web service
    >>>     # that you are using, i.e., "country", "city", or "insights". Please
    >>>     # note that Insights is not supported by the GeoLite2 web service.
    >>>     response = client.city('203.0.113.0')
    >>>
    >>>     response.country.iso_code
    'US'
    >>>     response.country.name
    'United States'
    >>>     response.country.names['zh-CN']
    u'美国'
    >>>
    >>>     response.subdivisions.most_specific.name
    'Minnesota'
    >>>     response.subdivisions.most_specific.iso_code
    'MN'
    >>>
    >>>     response.city.name
    'Minneapolis'
    >>>
    >>>     response.postal.code
    '55455'
    >>>
    >>>     response.location.latitude
    44.9733
    >>>     response.location.longitude
    -93.2323
    >>>
    >>>     response.traits.network
    IPv4Network('203.0.113.0/32')

Async Web Service Example
-------------------------

.. code-block:: pycon

    >>> import asyncio
    >>>
    >>> import geoip2.webservice
    >>>
    >>> async def main():
    >>>     # This creates an AsyncClient object that can be reused across
    >>>     # requests on the running event loop. If you are using multiple event
    >>>     # loops, you must ensure the object is not used on another loop.
    >>>     #
    >>>     # Replace "42" with your account ID and "license_key" with your license
    >>>     # key. Set the "host" keyword argument to "geolite.info" to use the
    >>>     # GeoLite2 web service instead of the GeoIP2 web service. Set the
    >>>     # "host" keyword argument to "sandbox.maxmind.com" to use the Sandbox
    >>>     # GeoIP2 web service instead of the production GeoIP2 web service.
    >>>     async with geoip2.webservice.AsyncClient(42, 'license_key') as client:
    >>>
    >>>         # Replace "city" with the method corresponding to the web service
    >>>         # that you are using, i.e., "country", "city", or "insights". Please
    >>>         # note that Insights is not supported by the GeoLite2 web service.
    >>>         response = await client.city('203.0.113.0')
    >>>
    >>>         response.country.iso_code
    'US'
    >>>         response.country.name
    'United States'
    >>>         response.country.names['zh-CN']
    u'美国'
    >>>
    >>>         response.subdivisions.most_specific.name
    'Minnesota'
    >>>         response.subdivisions.most_specific.iso_code
    'MN'
    >>>
    >>>         response.city.name
    'Minneapolis'
    >>>
    >>>         response.postal.code
    '55455'
    >>>
    >>>         response.location.latitude
    44.9733
    >>>         response.location.longitude
    -93.2323
    >>>
    >>>         response.traits.network
    IPv4Network('203.0.113.0/32')
    >>>
    >>> asyncio.run(main())

Web Service Client Exceptions
-----------------------------

For details on the possible errors returned by the web service itself, see
https://dev.maxmind.com/geoip/docs/web-services?lang=en for the GeoIP2 web
service docs.

If the web service returns an explicit error document, this is thrown as a
``AddressNotFoundError``, ``AuthenticationError``, ``InvalidRequestError``, or
``OutOfQueriesError`` as appropriate. These all subclass ``GeoIP2Error``.

If some other sort of error occurs, this is thrown as an ``HTTPError``. This
is thrown when some sort of unanticipated error occurs, such as the web
service returning a 500 or an invalid error document. If the web service
returns any status code besides 200, 4xx, or 5xx, this also becomes an
``HTTPError``.

Finally, if the web service returns a 200 but the body is invalid, the client
throws a ``GeoIP2Error``.

Database Usage
--------------

To use the database API, you first construct a ``geoip2.database.Reader`` using
the path to the file as the first argument. After doing this, you may call the
method corresponding to database type (e.g., ``city`` or ``country``), passing it
the IP address you want to look up.

If the lookup succeeds, the method call will return a model class for the
database method you called. This model in turn contains multiple record classes,
each of which represents part of the data for the record.

If the request fails, the reader class throws an exception.

Database Example
----------------

City Database
^^^^^^^^^^^^^

.. code-block:: pycon

    >>> import geoip2.database
    >>>
    >>> # This creates a Reader object. You should use the same object
    >>> # across multiple requests as creation of it is expensive.
    >>> with geoip2.database.Reader('/path/to/GeoLite2-City.mmdb') as reader:
    >>>
    >>>     # Replace "city" with the method corresponding to the database
    >>>     # that you are using, e.g., "country".
    >>>     response = reader.city('203.0.113.0')
    >>>
    >>>     response.country.iso_code
    'US'
    >>>     response.country.name
    'United States'
    >>>     response.country.names['zh-CN']
    u'美国'
    >>>
    >>>     response.subdivisions.most_specific.name
    'Minnesota'
    >>>     response.subdivisions.most_specific.iso_code
    'MN'
    >>>
    >>>     response.city.name
    'Minneapolis'
    >>>
    >>>     response.postal.code
    '55455'
    >>>
    >>>     response.location.latitude
    44.9733
    >>>     response.location.longitude
    -93.2323
    >>>
    >>>     response.traits.network
    IPv4Network('203.0.113.0/24')

Anonymous IP Database
^^^^^^^^^^^^^^^^^^^^^

.. code-block:: pycon

    >>> import geoip2.database
    >>>
    >>> # This creates a Reader object. You should use the same object
    >>> # across multiple requests as creation of it is expensive.
    >>> with geoip2.database.Reader('/path/to/GeoIP2-Anonymous-IP.mmdb') as reader:
    >>>
    >>>     response = reader.anonymous_ip('203.0.113.0')
    >>>
    >>>     response.is_anonymous
    True
    >>>     response.is_anonymous_vpn
    False
    >>>     response.is_hosting_provider
    False
    >>>     response.is_public_proxy
    False
    >>>     response.is_residential_proxy
    False
    >>>     response.is_tor_exit_node
    True
    >>>     response.ip_address
    '203.0.113.0'
    >>>     response.network
    IPv4Network('203.0.113.0/24')

ASN Database
^^^^^^^^^^^^

.. code-block:: pycon

    >>> import geoip2.database
    >>>
    >>> # This creates a Reader object. You should use the same object
    >>> # across multiple requests as creation of it is expensive.
    >>> with geoip2.database.Reader('/path/to/GeoLite2-ASN.mmdb') as reader:
    >>>     response = reader.asn('203.0.113.0')
    >>>     response.autonomous_system_number
    1221
    >>>     response.autonomous_system_organization
    'Telstra Pty Ltd'
    >>>     response.ip_address
    '203.0.113.0'
    >>>     response.network
    IPv4Network('203.0.113.0/24')

Connection-Type Database
^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: pycon

    >>> import geoip2.database
    >>>
    >>> # This creates a Reader object. You should use the same object
    >>> # across multiple requests as creation of it is expensive.
    >>> with geoip2.database.Reader('/path/to/GeoIP2-Connection-Type.mmdb') as reader:
    >>>     response = reader.connection_type('203.0.113.0')
    >>>     response.connection_type
    'Corporate'
    >>>     response.ip_address
    '203.0.113.0'
    >>>     response.network
    IPv4Network('203.0.113.0/24')


Domain Database
^^^^^^^^^^^^^^^

.. code-block:: pycon

    >>> import geoip2.database
    >>>
    >>> # This creates a Reader object. You should use the same object
    >>> # across multiple requests as creation of it is expensive.
    >>> with geoip2.database.Reader('/path/to/GeoIP2-Domain.mmdb') as reader:
    >>>     response = reader.domain('203.0.113.0')
    >>>     response.domain
    'umn.edu'
    >>>     response.ip_address
    '203.0.113.0'

Enterprise Database
^^^^^^^^^^^^^^^^^^^

.. code-block:: pycon

    >>> import geoip2.database
    >>>
    >>> # This creates a Reader object. You should use the same object
    >>> # across multiple requests as creation of it is expensive.
    >>> with geoip2.database.Reader('/path/to/GeoIP2-Enterprise.mmdb') as reader:
    >>>
    >>>     # Use the .enterprise method to do a lookup in the Enterprise database
    >>>     response = reader.enterprise('203.0.113.0')
    >>>
    >>>     response.country.confidence
    99
    >>>     response.country.iso_code
    'US'
    >>>     response.country.name
    'United States'
    >>>     response.country.names['zh-CN']
    u'美国'
    >>>
    >>>     response.subdivisions.most_specific.name
    'Minnesota'
    >>>     response.subdivisions.most_specific.iso_code
    'MN'
    >>>     response.subdivisions.most_specific.confidence
    77
    >>>
    >>>     response.city.name
    'Minneapolis'
    >>>     response.country.confidence
    11
    >>>
    >>>     response.postal.code
    '55455'
    >>>
    >>>     response.location.accuracy_radius
    50
    >>>     response.location.latitude
    44.9733
    >>>     response.location.longitude
    -93.2323
    >>>
    >>>     response.traits.network
    IPv4Network('203.0.113.0/24')


ISP Database
^^^^^^^^^^^^

.. code-block:: pycon

    >>> import geoip2.database
    >>>
    >>> # This creates a Reader object. You should use the same object
    >>> # across multiple requests as creation of it is expensive.
    >>> with geoip2.database.Reader('/path/to/GeoIP2-ISP.mmdb') as reader:
    >>>     response = reader.isp('203.0.113.0')
    >>>     response.autonomous_system_number
    1221
    >>>     response.autonomous_system_organization
    'Telstra Pty Ltd'
    >>>     response.isp
    'Telstra Internet'
    >>>     response.organization
    'Telstra Internet'
    >>>     response.ip_address
    '203.0.113.0'
    >>>     response.network
    IPv4Network('203.0.113.0/24')

Database Reader Exceptions
--------------------------

If the database file does not exist or is not readable, the constructor will
raise a ``FileNotFoundError`` or a ``PermissionError``. If the IP address passed
to a method is invalid, a ``ValueError`` will be raised. If the file is invalid
or there is a bug in the reader, a ``maxminddb.InvalidDatabaseError`` will be
raised with a description of the problem. If an IP address is not in the
database, a ``AddressNotFoundError`` will be raised.

``AddressNotFoundError`` references the largest subnet where no address would be
found. This can be used to efficiently enumerate entire subnets:

.. code-block:: python

    import geoip2.database
    import geoip2.errors
    import ipaddress

    # This creates a Reader object. You should use the same object
    # across multiple requests as creation of it is expensive.
    with geoip2.database.Reader('/path/to/GeoLite2-ASN.mmdb') as reader:
        network = ipaddress.ip_network("192.128.0.0/15")

        ip_address = network[0]
        while ip_address in network:
            try:
                response = reader.asn(ip_address)
                response_network = response.network
            except geoip2.errors.AddressNotFoundError as e:
                response = None
                response_network = e.network
            print(f"{response_network}: {response!r}")
            ip_address = response_network[-1] + 1  # move to next subnet

Values to use for Database or Dictionary Keys
---------------------------------------------

**We strongly discourage you from using a value from any ``names`` property as
a key in a database or dictionaries.**

These names may change between releases. Instead we recommend using one of the
following:

* ``geoip2.records.City`` - ``city.geoname_id``
* ``geoip2.records.Continent`` - ``continent.code`` or ``continent.geoname_id``
* ``geoip2.records.Country`` and ``geoip2.records.RepresentedCountry`` - ``country.iso_code`` or ``country.geoname_id``
* ``geoip2.records.subdivision`` - ``subdivision.iso_code`` or ``subdivision.geoname_id``

What data is returned?
----------------------

While many of the models contain the same basic records, the attributes which
can be populated vary between web service endpoints or databases. In
addition, while a model may offer a particular piece of data, MaxMind does not
always have every piece of data for any given IP address.

Because of these factors, it is possible for any request to return a record
where some or all of the attributes are unpopulated.

The only piece of data which is always returned is the ``ip_address``
attribute in the ``geoip2.records.Traits`` record.

Integration with GeoNames
-------------------------

`GeoNames <https://www.geonames.org/>`_ offers web services and downloadable
databases with data on geographical features around the world, including
populated places. They offer both free and paid premium data. Each feature is
uniquely identified by a ``geoname_id``, which is an integer.

Many of the records returned by the GeoIP web services and databases include a
``geoname_id`` field. This is the ID of a geographical feature (city, region,
country, etc.) in the GeoNames database.

Some of the data that MaxMind provides is also sourced from GeoNames. We
source things like place names, ISO codes, and other similar data from the
GeoNames premium data set.

Reporting Data Problems
-----------------------

If the problem you find is that an IP address is incorrectly mapped, please
`submit your correction to MaxMind <https://www.maxmind.com/en/correction>`_.

If you find some other sort of mistake, like an incorrect spelling, please
check the `GeoNames site <https://www.geonames.org/>`_ first. Once you've
searched for a place and found it on the GeoNames map view, there are a
number of links you can use to correct data ("move", "edit", "alternate
names", etc.). Once the correction is part of the GeoNames data set, it
will be automatically incorporated into future MaxMind releases.

If you are a paying MaxMind customer and you're not sure where to submit a
correction, please `contact MaxMind support
<https://www.maxmind.com/en/support>`_ for help.

Requirements
------------

Python 3.8 or greater is required. Older versions are not supported.

The Requests HTTP library is also required. See
<https://pypi.org/project/requests/> for details.

Versioning
----------

The GeoIP2 Python API uses `Semantic Versioning <https://semver.org/>`_.

Support
-------

Please report all issues with this code using the `GitHub issue tracker
<https://github.com/maxmind/GeoIP2-python/issues>`_

If you are having an issue with a MaxMind service that is not specific to the
client API, please contact `MaxMind support
<https://www.maxmind.com/en/support>`_ for assistance.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "geoip2",
    "maintainer": "",
    "docs_url": "https://pythonhosted.org/geoip2/",
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "Gregory Oschwald <goschwald@maxmind.com>",
    "download_url": "https://files.pythonhosted.org/packages/a7/ae/892642e21881f95bdcb058580e74aaa3de0ee5ee4f76ccec02745f2a3abe/geoip2-4.8.0.tar.gz",
    "platform": null,
    "description": "=========================\nMaxMind GeoIP2 Python API\n=========================\n\nDescription\n-----------\n\nThis package provides an API for the GeoIP2 and GeoLite2 `web services\n<https://dev.maxmind.com/geoip/docs/web-services?lang=en>`_ and `databases\n<https://dev.maxmind.com/geoip/docs/databases?lang=en>`_.\n\nInstallation\n------------\n\nTo install the ``geoip2`` module, type:\n\n.. code-block:: bash\n\n    $ pip install geoip2\n\nIf you are not able to use pip, you may also use easy_install from the\nsource directory:\n\n.. code-block:: bash\n\n    $ easy_install .\n\nDatabase Reader Extension\n^^^^^^^^^^^^^^^^^^^^^^^^^\n\nIf you wish to use the C extension for the database reader, you must first\ninstall the `libmaxminddb C API <https://github.com/maxmind/libmaxminddb>`_.\nPlease `see the instructions distributed with it\n<https://github.com/maxmind/libmaxminddb/blob/main/README.md>`_.\n\nIP Geolocation Usage\n--------------------\n\nIP geolocation is inherently imprecise. Locations are often near the center of\nthe population. Any location provided by a GeoIP2 database or web service\nshould not be used to identify a particular address or household.\n\nWeb Service Usage\n-----------------\n\nTo use this API, you first construct either a ``geoip2.webservice.Client`` or\n``geoip2.webservice.AsyncClient``, passing your MaxMind ``account_id`` and\n``license_key`` to the constructor. To use the GeoLite2 web service instead of\nthe GeoIP2 web service, set the optional ``host`` keyword argument to\n``geolite.info``. To use the Sandbox GeoIP2 web service instead of the\nproduction GeoIP2 web service, set the optional ``host`` keyword argument to\n``sandbox.maxmind.com``.\n\nAfter doing this, you may call the method corresponding to request type\n(e.g., ``city`` or ``country``), passing it the IP address you want to look up.\n\nIf the request succeeds, the method call will return a model class for the\nendpoint you called. This model in turn contains multiple record classes,\neach of which represents part of the data returned by the web service.\n\nIf the request fails, the client class throws an exception.\n\nSync Web Service Example\n------------------------\n\n.. code-block:: pycon\n\n    >>> import geoip2.webservice\n    >>>\n    >>> # This creates a Client object that can be reused across requests.\n    >>> # Replace \"42\" with your account ID and \"license_key\" with your license\n    >>> # key. Set the \"host\" keyword argument to \"geolite.info\" to use the\n    >>> # GeoLite2 web service instead of the GeoIP2 web service. Set the\n    >>> # \"host\" keyword argument to \"sandbox.maxmind.com\" to use the Sandbox\n    >>> # GeoIP2 web service instead of the production GeoIP2 web service.\n    >>> with geoip2.webservice.Client(42, 'license_key') as client:\n    >>>\n    >>>     # Replace \"city\" with the method corresponding to the web service\n    >>>     # that you are using, i.e., \"country\", \"city\", or \"insights\". Please\n    >>>     # note that Insights is not supported by the GeoLite2 web service.\n    >>>     response = client.city('203.0.113.0')\n    >>>\n    >>>     response.country.iso_code\n    'US'\n    >>>     response.country.name\n    'United States'\n    >>>     response.country.names['zh-CN']\n    u'\u7f8e\u56fd'\n    >>>\n    >>>     response.subdivisions.most_specific.name\n    'Minnesota'\n    >>>     response.subdivisions.most_specific.iso_code\n    'MN'\n    >>>\n    >>>     response.city.name\n    'Minneapolis'\n    >>>\n    >>>     response.postal.code\n    '55455'\n    >>>\n    >>>     response.location.latitude\n    44.9733\n    >>>     response.location.longitude\n    -93.2323\n    >>>\n    >>>     response.traits.network\n    IPv4Network('203.0.113.0/32')\n\nAsync Web Service Example\n-------------------------\n\n.. code-block:: pycon\n\n    >>> import asyncio\n    >>>\n    >>> import geoip2.webservice\n    >>>\n    >>> async def main():\n    >>>     # This creates an AsyncClient object that can be reused across\n    >>>     # requests on the running event loop. If you are using multiple event\n    >>>     # loops, you must ensure the object is not used on another loop.\n    >>>     #\n    >>>     # Replace \"42\" with your account ID and \"license_key\" with your license\n    >>>     # key. Set the \"host\" keyword argument to \"geolite.info\" to use the\n    >>>     # GeoLite2 web service instead of the GeoIP2 web service. Set the\n    >>>     # \"host\" keyword argument to \"sandbox.maxmind.com\" to use the Sandbox\n    >>>     # GeoIP2 web service instead of the production GeoIP2 web service.\n    >>>     async with geoip2.webservice.AsyncClient(42, 'license_key') as client:\n    >>>\n    >>>         # Replace \"city\" with the method corresponding to the web service\n    >>>         # that you are using, i.e., \"country\", \"city\", or \"insights\". Please\n    >>>         # note that Insights is not supported by the GeoLite2 web service.\n    >>>         response = await client.city('203.0.113.0')\n    >>>\n    >>>         response.country.iso_code\n    'US'\n    >>>         response.country.name\n    'United States'\n    >>>         response.country.names['zh-CN']\n    u'\u7f8e\u56fd'\n    >>>\n    >>>         response.subdivisions.most_specific.name\n    'Minnesota'\n    >>>         response.subdivisions.most_specific.iso_code\n    'MN'\n    >>>\n    >>>         response.city.name\n    'Minneapolis'\n    >>>\n    >>>         response.postal.code\n    '55455'\n    >>>\n    >>>         response.location.latitude\n    44.9733\n    >>>         response.location.longitude\n    -93.2323\n    >>>\n    >>>         response.traits.network\n    IPv4Network('203.0.113.0/32')\n    >>>\n    >>> asyncio.run(main())\n\nWeb Service Client Exceptions\n-----------------------------\n\nFor details on the possible errors returned by the web service itself, see\nhttps://dev.maxmind.com/geoip/docs/web-services?lang=en for the GeoIP2 web\nservice docs.\n\nIf the web service returns an explicit error document, this is thrown as a\n``AddressNotFoundError``, ``AuthenticationError``, ``InvalidRequestError``, or\n``OutOfQueriesError`` as appropriate. These all subclass ``GeoIP2Error``.\n\nIf some other sort of error occurs, this is thrown as an ``HTTPError``. This\nis thrown when some sort of unanticipated error occurs, such as the web\nservice returning a 500 or an invalid error document. If the web service\nreturns any status code besides 200, 4xx, or 5xx, this also becomes an\n``HTTPError``.\n\nFinally, if the web service returns a 200 but the body is invalid, the client\nthrows a ``GeoIP2Error``.\n\nDatabase Usage\n--------------\n\nTo use the database API, you first construct a ``geoip2.database.Reader`` using\nthe path to the file as the first argument. After doing this, you may call the\nmethod corresponding to database type (e.g., ``city`` or ``country``), passing it\nthe IP address you want to look up.\n\nIf the lookup succeeds, the method call will return a model class for the\ndatabase method you called. This model in turn contains multiple record classes,\neach of which represents part of the data for the record.\n\nIf the request fails, the reader class throws an exception.\n\nDatabase Example\n----------------\n\nCity Database\n^^^^^^^^^^^^^\n\n.. code-block:: pycon\n\n    >>> import geoip2.database\n    >>>\n    >>> # This creates a Reader object. You should use the same object\n    >>> # across multiple requests as creation of it is expensive.\n    >>> with geoip2.database.Reader('/path/to/GeoLite2-City.mmdb') as reader:\n    >>>\n    >>>     # Replace \"city\" with the method corresponding to the database\n    >>>     # that you are using, e.g., \"country\".\n    >>>     response = reader.city('203.0.113.0')\n    >>>\n    >>>     response.country.iso_code\n    'US'\n    >>>     response.country.name\n    'United States'\n    >>>     response.country.names['zh-CN']\n    u'\u7f8e\u56fd'\n    >>>\n    >>>     response.subdivisions.most_specific.name\n    'Minnesota'\n    >>>     response.subdivisions.most_specific.iso_code\n    'MN'\n    >>>\n    >>>     response.city.name\n    'Minneapolis'\n    >>>\n    >>>     response.postal.code\n    '55455'\n    >>>\n    >>>     response.location.latitude\n    44.9733\n    >>>     response.location.longitude\n    -93.2323\n    >>>\n    >>>     response.traits.network\n    IPv4Network('203.0.113.0/24')\n\nAnonymous IP Database\n^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: pycon\n\n    >>> import geoip2.database\n    >>>\n    >>> # This creates a Reader object. You should use the same object\n    >>> # across multiple requests as creation of it is expensive.\n    >>> with geoip2.database.Reader('/path/to/GeoIP2-Anonymous-IP.mmdb') as reader:\n    >>>\n    >>>     response = reader.anonymous_ip('203.0.113.0')\n    >>>\n    >>>     response.is_anonymous\n    True\n    >>>     response.is_anonymous_vpn\n    False\n    >>>     response.is_hosting_provider\n    False\n    >>>     response.is_public_proxy\n    False\n    >>>     response.is_residential_proxy\n    False\n    >>>     response.is_tor_exit_node\n    True\n    >>>     response.ip_address\n    '203.0.113.0'\n    >>>     response.network\n    IPv4Network('203.0.113.0/24')\n\nASN Database\n^^^^^^^^^^^^\n\n.. code-block:: pycon\n\n    >>> import geoip2.database\n    >>>\n    >>> # This creates a Reader object. You should use the same object\n    >>> # across multiple requests as creation of it is expensive.\n    >>> with geoip2.database.Reader('/path/to/GeoLite2-ASN.mmdb') as reader:\n    >>>     response = reader.asn('203.0.113.0')\n    >>>     response.autonomous_system_number\n    1221\n    >>>     response.autonomous_system_organization\n    'Telstra Pty Ltd'\n    >>>     response.ip_address\n    '203.0.113.0'\n    >>>     response.network\n    IPv4Network('203.0.113.0/24')\n\nConnection-Type Database\n^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: pycon\n\n    >>> import geoip2.database\n    >>>\n    >>> # This creates a Reader object. You should use the same object\n    >>> # across multiple requests as creation of it is expensive.\n    >>> with geoip2.database.Reader('/path/to/GeoIP2-Connection-Type.mmdb') as reader:\n    >>>     response = reader.connection_type('203.0.113.0')\n    >>>     response.connection_type\n    'Corporate'\n    >>>     response.ip_address\n    '203.0.113.0'\n    >>>     response.network\n    IPv4Network('203.0.113.0/24')\n\n\nDomain Database\n^^^^^^^^^^^^^^^\n\n.. code-block:: pycon\n\n    >>> import geoip2.database\n    >>>\n    >>> # This creates a Reader object. You should use the same object\n    >>> # across multiple requests as creation of it is expensive.\n    >>> with geoip2.database.Reader('/path/to/GeoIP2-Domain.mmdb') as reader:\n    >>>     response = reader.domain('203.0.113.0')\n    >>>     response.domain\n    'umn.edu'\n    >>>     response.ip_address\n    '203.0.113.0'\n\nEnterprise Database\n^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: pycon\n\n    >>> import geoip2.database\n    >>>\n    >>> # This creates a Reader object. You should use the same object\n    >>> # across multiple requests as creation of it is expensive.\n    >>> with geoip2.database.Reader('/path/to/GeoIP2-Enterprise.mmdb') as reader:\n    >>>\n    >>>     # Use the .enterprise method to do a lookup in the Enterprise database\n    >>>     response = reader.enterprise('203.0.113.0')\n    >>>\n    >>>     response.country.confidence\n    99\n    >>>     response.country.iso_code\n    'US'\n    >>>     response.country.name\n    'United States'\n    >>>     response.country.names['zh-CN']\n    u'\u7f8e\u56fd'\n    >>>\n    >>>     response.subdivisions.most_specific.name\n    'Minnesota'\n    >>>     response.subdivisions.most_specific.iso_code\n    'MN'\n    >>>     response.subdivisions.most_specific.confidence\n    77\n    >>>\n    >>>     response.city.name\n    'Minneapolis'\n    >>>     response.country.confidence\n    11\n    >>>\n    >>>     response.postal.code\n    '55455'\n    >>>\n    >>>     response.location.accuracy_radius\n    50\n    >>>     response.location.latitude\n    44.9733\n    >>>     response.location.longitude\n    -93.2323\n    >>>\n    >>>     response.traits.network\n    IPv4Network('203.0.113.0/24')\n\n\nISP Database\n^^^^^^^^^^^^\n\n.. code-block:: pycon\n\n    >>> import geoip2.database\n    >>>\n    >>> # This creates a Reader object. You should use the same object\n    >>> # across multiple requests as creation of it is expensive.\n    >>> with geoip2.database.Reader('/path/to/GeoIP2-ISP.mmdb') as reader:\n    >>>     response = reader.isp('203.0.113.0')\n    >>>     response.autonomous_system_number\n    1221\n    >>>     response.autonomous_system_organization\n    'Telstra Pty Ltd'\n    >>>     response.isp\n    'Telstra Internet'\n    >>>     response.organization\n    'Telstra Internet'\n    >>>     response.ip_address\n    '203.0.113.0'\n    >>>     response.network\n    IPv4Network('203.0.113.0/24')\n\nDatabase Reader Exceptions\n--------------------------\n\nIf the database file does not exist or is not readable, the constructor will\nraise a ``FileNotFoundError`` or a ``PermissionError``. If the IP address passed\nto a method is invalid, a ``ValueError`` will be raised. If the file is invalid\nor there is a bug in the reader, a ``maxminddb.InvalidDatabaseError`` will be\nraised with a description of the problem. If an IP address is not in the\ndatabase, a ``AddressNotFoundError`` will be raised.\n\n``AddressNotFoundError`` references the largest subnet where no address would be\nfound. This can be used to efficiently enumerate entire subnets:\n\n.. code-block:: python\n\n    import geoip2.database\n    import geoip2.errors\n    import ipaddress\n\n    # This creates a Reader object. You should use the same object\n    # across multiple requests as creation of it is expensive.\n    with geoip2.database.Reader('/path/to/GeoLite2-ASN.mmdb') as reader:\n        network = ipaddress.ip_network(\"192.128.0.0/15\")\n\n        ip_address = network[0]\n        while ip_address in network:\n            try:\n                response = reader.asn(ip_address)\n                response_network = response.network\n            except geoip2.errors.AddressNotFoundError as e:\n                response = None\n                response_network = e.network\n            print(f\"{response_network}: {response!r}\")\n            ip_address = response_network[-1] + 1  # move to next subnet\n\nValues to use for Database or Dictionary Keys\n---------------------------------------------\n\n**We strongly discourage you from using a value from any ``names`` property as\na key in a database or dictionaries.**\n\nThese names may change between releases. Instead we recommend using one of the\nfollowing:\n\n* ``geoip2.records.City`` - ``city.geoname_id``\n* ``geoip2.records.Continent`` - ``continent.code`` or ``continent.geoname_id``\n* ``geoip2.records.Country`` and ``geoip2.records.RepresentedCountry`` - ``country.iso_code`` or ``country.geoname_id``\n* ``geoip2.records.subdivision`` - ``subdivision.iso_code`` or ``subdivision.geoname_id``\n\nWhat data is returned?\n----------------------\n\nWhile many of the models contain the same basic records, the attributes which\ncan be populated vary between web service endpoints or databases. In\naddition, while a model may offer a particular piece of data, MaxMind does not\nalways have every piece of data for any given IP address.\n\nBecause of these factors, it is possible for any request to return a record\nwhere some or all of the attributes are unpopulated.\n\nThe only piece of data which is always returned is the ``ip_address``\nattribute in the ``geoip2.records.Traits`` record.\n\nIntegration with GeoNames\n-------------------------\n\n`GeoNames <https://www.geonames.org/>`_ offers web services and downloadable\ndatabases with data on geographical features around the world, including\npopulated places. They offer both free and paid premium data. Each feature is\nuniquely identified by a ``geoname_id``, which is an integer.\n\nMany of the records returned by the GeoIP web services and databases include a\n``geoname_id`` field. This is the ID of a geographical feature (city, region,\ncountry, etc.) in the GeoNames database.\n\nSome of the data that MaxMind provides is also sourced from GeoNames. We\nsource things like place names, ISO codes, and other similar data from the\nGeoNames premium data set.\n\nReporting Data Problems\n-----------------------\n\nIf the problem you find is that an IP address is incorrectly mapped, please\n`submit your correction to MaxMind <https://www.maxmind.com/en/correction>`_.\n\nIf you find some other sort of mistake, like an incorrect spelling, please\ncheck the `GeoNames site <https://www.geonames.org/>`_ first. Once you've\nsearched for a place and found it on the GeoNames map view, there are a\nnumber of links you can use to correct data (\"move\", \"edit\", \"alternate\nnames\", etc.). Once the correction is part of the GeoNames data set, it\nwill be automatically incorporated into future MaxMind releases.\n\nIf you are a paying MaxMind customer and you're not sure where to submit a\ncorrection, please `contact MaxMind support\n<https://www.maxmind.com/en/support>`_ for help.\n\nRequirements\n------------\n\nPython 3.8 or greater is required. Older versions are not supported.\n\nThe Requests HTTP library is also required. See\n<https://pypi.org/project/requests/> for details.\n\nVersioning\n----------\n\nThe GeoIP2 Python API uses `Semantic Versioning <https://semver.org/>`_.\n\nSupport\n-------\n\nPlease report all issues with this code using the `GitHub issue tracker\n<https://github.com/maxmind/GeoIP2-python/issues>`_\n\nIf you are having an issue with a MaxMind service that is not specific to the\nclient API, please contact `MaxMind support\n<https://www.maxmind.com/en/support>`_ for assistance.\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "MaxMind GeoIP2 API",
    "version": "4.8.0",
    "project_urls": {
        "Documentation": "https://geoip2.readthedocs.org/",
        "Homepage": "https://www.maxmind.com/",
        "Issue Tracker": "https://github.com/maxmind/GeoIP2-python/issues",
        "Source Code": "https://github.com/maxmind/GeoIP2-python"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7c860cbbe4fb7f1d3c2b598988a4464954a768cd23c5e3cb47e7a0fc6bac3096",
                "md5": "6cc8e1135e004bc51e6f957b196a7cc0",
                "sha256": "39b38ec703575355d10475c0e6aa981827a2b4b5471d308c4ecb5e79cbe366ce"
            },
            "downloads": -1,
            "filename": "geoip2-4.8.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6cc8e1135e004bc51e6f957b196a7cc0",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 27099,
            "upload_time": "2023-12-05T22:31:11",
            "upload_time_iso_8601": "2023-12-05T22:31:11.919573Z",
            "url": "https://files.pythonhosted.org/packages/7c/86/0cbbe4fb7f1d3c2b598988a4464954a768cd23c5e3cb47e7a0fc6bac3096/geoip2-4.8.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a7ae892642e21881f95bdcb058580e74aaa3de0ee5ee4f76ccec02745f2a3abe",
                "md5": "ad58a2379172ad3a338c92537e4e354b",
                "sha256": "dd9cc180b7d41724240ea481d5d539149e65b234f64282b231b9170794a9ac35"
            },
            "downloads": -1,
            "filename": "geoip2-4.8.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ad58a2379172ad3a338c92537e4e354b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 174237,
            "upload_time": "2023-12-05T22:31:13",
            "upload_time_iso_8601": "2023-12-05T22:31:13.921353Z",
            "url": "https://files.pythonhosted.org/packages/a7/ae/892642e21881f95bdcb058580e74aaa3de0ee5ee4f76ccec02745f2a3abe/geoip2-4.8.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-05 22:31:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "maxmind",
    "github_project": "GeoIP2-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "geoip2"
}
        
Elapsed time: 0.14591s