fastapi-geolocation


Namefastapi-geolocation JSON
Version 1.0.1 PyPI version JSON
download
home_page
SummaryFastAPI Geolocation
upload_time2024-02-25 23:34:10
maintainer
docs_urlNone
author
requires_python>=3.8
licenseThe MIT License (MIT) Copyright (c) 2024 Nurettin ABACI Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords fastapi geolocation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastAPI Geolocation

`fastapi-geolocation` is a simple middleware package for FastAPI that provides geolocation features by integrating IP-based location lookup. This package is particularly useful for FastAPI applications that need to determine the geographical location of their users.

## Features

- Easy integration with FastAPI applications.
- Utilizes the GeoIP class from Django for location lookup.
- Provides an easy-to-use middleware that enriches requests with geolocation data.

## Installation

To install `fastapi-geolocation`, run the following command:

```bash
pip install fastapi-geolocation
```

## Quick Start
Here is a simple example of how to use fastapi-geolocation in a FastAPI application:
```python3
import aioredis
from fastapi import FastAPI, Request
from fastapi_geolocation import GeoIPMiddleware

app = FastAPI()
redis_client = aioredis.from_url("redis://localhost", encoding="utf-8", decode_responses=True)
app.add_middleware(GeoIPMiddleware, redis_client=redis_client, license_key="mykey")

@app.get('/')
async def index(request: Request):
    geo_data = request.state.geo
    return {
        'country': geo_data.country.name if geo_data else 'Unknown',
    }
```

## Configuration
To set up the middleware, you need to add it to your FastAPI application with the necessary parameters:

redis_client: An instance of aioredis client for caching purpose.
license_key: Your MaxMind license key for the GeoIP database.


## Usage
After adding the middleware to your FastAPI application, you can access the geolocation data in your route handlers using the request.state.geo property.

## Contributing
Contributions are welcome! If you would like to contribute to the project, please follow these steps:

Fork the repository.
Create a new branch for your feature or fix.
Write your code and add tests if applicable.
Submit a pull request with a clear description of your changes.

##  License
fastapi-geolocation is open source software licensed as MIT.

## Credits
This project was inspired by the GeoIP functionality in Django and has been adapted for use in FastAPI applications.


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "fastapi-geolocation",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "fastapi,geolocation",
    "author": "",
    "author_email": "Nurettin Abac\u0131 <abacinurettin@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/5c/56/31814d027ab057fc03fb98023865494379bd784cfb67602fd43a940354d6/fastapi-geolocation-1.0.1.tar.gz",
    "platform": null,
    "description": "# FastAPI Geolocation\n\n`fastapi-geolocation` is a simple middleware package for FastAPI that provides geolocation features by integrating IP-based location lookup. This package is particularly useful for FastAPI applications that need to determine the geographical location of their users.\n\n## Features\n\n- Easy integration with FastAPI applications.\n- Utilizes the GeoIP class from Django for location lookup.\n- Provides an easy-to-use middleware that enriches requests with geolocation data.\n\n## Installation\n\nTo install `fastapi-geolocation`, run the following command:\n\n```bash\npip install fastapi-geolocation\n```\n\n## Quick Start\nHere is a simple example of how to use fastapi-geolocation in a FastAPI application:\n```python3\nimport aioredis\nfrom fastapi import FastAPI, Request\nfrom fastapi_geolocation import GeoIPMiddleware\n\napp = FastAPI()\nredis_client = aioredis.from_url(\"redis://localhost\", encoding=\"utf-8\", decode_responses=True)\napp.add_middleware(GeoIPMiddleware, redis_client=redis_client, license_key=\"mykey\")\n\n@app.get('/')\nasync def index(request: Request):\n    geo_data = request.state.geo\n    return {\n        'country': geo_data.country.name if geo_data else 'Unknown',\n    }\n```\n\n## Configuration\nTo set up the middleware, you need to add it to your FastAPI application with the necessary parameters:\n\nredis_client: An instance of aioredis client for caching purpose.\nlicense_key: Your MaxMind license key for the GeoIP database.\n\n\n## Usage\nAfter adding the middleware to your FastAPI application, you can access the geolocation data in your route handlers using the request.state.geo property.\n\n## Contributing\nContributions are welcome! If you would like to contribute to the project, please follow these steps:\n\nFork the repository.\nCreate a new branch for your feature or fix.\nWrite your code and add tests if applicable.\nSubmit a pull request with a clear description of your changes.\n\n##  License\nfastapi-geolocation is open source software licensed as MIT.\n\n## Credits\nThis project was inspired by the GeoIP functionality in Django and has been adapted for use in FastAPI applications.\n\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2024  Nurettin ABACI  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "FastAPI Geolocation",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/nurettn/fastapi-geolocation",
        "Repository": "https://github.com/nurettn/fastapi-geolocation"
    },
    "split_keywords": [
        "fastapi",
        "geolocation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "27e802f51a63e94105bc5839e4c7689f4b6542afd9192838b568591d443a3197",
                "md5": "f2d03b1e6f0d9aaa522de8fc8f04ee1f",
                "sha256": "a2ae3ba06ec91331f1bc0fd6959a350e111e79409d3175008cb41f3b2460a94d"
            },
            "downloads": -1,
            "filename": "fastapi_geolocation-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f2d03b1e6f0d9aaa522de8fc8f04ee1f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 10279,
            "upload_time": "2024-02-25T23:34:08",
            "upload_time_iso_8601": "2024-02-25T23:34:08.770416Z",
            "url": "https://files.pythonhosted.org/packages/27/e8/02f51a63e94105bc5839e4c7689f4b6542afd9192838b568591d443a3197/fastapi_geolocation-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5c5631814d027ab057fc03fb98023865494379bd784cfb67602fd43a940354d6",
                "md5": "b90d291702ab78d5810e575b179c9e11",
                "sha256": "1fc5fea4530f17f28ed8f7dee136af89f4da5446dfdc1f7ca83f285e6da3d9fd"
            },
            "downloads": -1,
            "filename": "fastapi-geolocation-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b90d291702ab78d5810e575b179c9e11",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 10322,
            "upload_time": "2024-02-25T23:34:10",
            "upload_time_iso_8601": "2024-02-25T23:34:10.706883Z",
            "url": "https://files.pythonhosted.org/packages/5c/56/31814d027ab057fc03fb98023865494379bd784cfb67602fd43a940354d6/fastapi-geolocation-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-25 23:34:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nurettn",
    "github_project": "fastapi-geolocation",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "fastapi-geolocation"
}
        
Elapsed time: 0.19820s