pygeoquery


Namepygeoquery JSON
Version 0.1.6 PyPI version JSON
download
home_pagehttps://github.com/booncol/pygeoquery
SummaryGeoqueries on Firestore Database for Python
upload_time2023-10-30 22:24:20
maintainer
docs_urlNone
authorLukasz Majda
requires_python>=3.9
licenseMIT
keywords firestore geoquery geospatial geofire geohash
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pygeoquery

[![PyPI package](https://img.shields.io/badge/pip%20install-pygeoquery-brightgreen)](https://pypi.org/project/pygeoquery/)
[![Version](https://img.shields.io/pypi/v/pygeoquery)](https://pypi.org/project/pygeoquery/0.1.0/)
[![License](https://img.shields.io/github/license/booncol/pygeoquery)](https://github.com/booncol/pygeoquery/blob/main/LICENSE)

Perform geospatial queries on a Firestore database with ease.

pygeoquery allows you to retrieve documents within a certain radius of a given geographic point. It utilizes geohashes for efficient querying.

## Features
- query Firestore collections by geographic proximity.
- efficiently filter and retrieve documents within a specified radius.
- flexible and customizable query building.
- utilizes geohashes for high-performance geospatial queries.
- supports both synchronous and asynchronous Firestore clients.

## Installation
You can install the library using pip:

```bash
pip install pygeoquery
```

## Prerequisites

Before using this library, ensure that each document in the searched Firestore collection includes a field called **"geohash"** containing a geohash value generated from the geographical coordinates. This geohash field is essential for the library to perform accurate geospatial queries.

![Document preview](https://github.com/booncol/pygeoquery/blob/main/document_preview.png?raw=true)  

To generate geohashes, you can use Python libraries such as:

- [pygeohash](https://pypi.org/project/pygeohash/): Provides functions for decoding and encoding geohashes.
- [geohashr](https://pypi.org/project/geohashr/): Just another Python geohashing library.


## Usage

1) Initialize Firebase

    ```python
    from firebase_admin import initialize_app, credentials
    from google.cloud import firestore
    
    
    # Initialize Firebase
    cred = credentials.Certificate("path/to/your/serviceAccountKey.json")
    initialize_app(cred, {"projectId": "your-project-id"})
    ```

2) Create Firestore client

    ```python
   # Synchronous client
    db = firestore.Client()
    ```
    or    

    ```python
   # Asynchronous client
    db = firestore.AsyncClient()
    ```

3) Define callback functions

    ```python
    # Define a GeoPointFromCallback
    def geopoint_from_callback(data):
        return data.get("location")  # Replace with your data structure
    
    # Define query builder callback function (optional). This function allows you to customize your query.
    def query_builder_callback(query):
        return query.where("property", "==", "value")  # Customize your query
    ```

4) Create a GeoCollectionReference or GeoAsyncCollectionReference

    ```python
    # Create a GeoCollectionReference
    geocollection = GeoCollectionReference(db.collection("your_collection"))
   ```
   
    or

    ```python
    # Create a GeoAsyncCollectionReference (asynchronous client only)
    geocollection = GeoAsyncCollectionReference(db.collection("your_collection"))
   ```

5) Fetch documents within a radius of a GeoPoint

    ```python
    # Fetch documents within a radius of a GeoPoint
    center_point = GeoPoint(latitude, longitude)
    radius_km = 10.0
    
    result = geocollection.fetch_within(
        center_point,
        radius_km,
        geopoint_from_callback,
        query_builder_callback
    )
    
    # Process the retrieved documents
    for document in result:
        print(document)
    ```

    If you are using the asynchronous client, use the `await` keyword to wait for the result.

    ```python
    result = await geocollection.fetch_within(
        center_point,
        radius_km,
        geopoint_from_callback,
        query_builder_callback
    )
    ```   

## Acknowledgments
This project is inspired by the [geoflutterfire_plus](https://github.com/KosukeSaigusa/geoflutterfire_plus) Flutter module by [Kosuke Saigusa](https://github.com/kosukesaigusa), which provides similar geospatial querying functionality for Firestore databases in the Flutter framework.

## License
This project is licensed under the MIT License - see the [LICENSE](https://github.com/booncol/pygeoquery/blob/main/LICENSE) file for details.

## Contributing
Please read [CONTRIBUTING.md](https://github.com/booncol/pygeoquery/blob/main/CONTRIBUTING.md) for details on my code of conduct, and the process for submitting pull requests to me.

## Contact
If you have questions or need assistance, feel free to contact me.

**Happy querying!**

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/booncol/pygeoquery",
    "name": "pygeoquery",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "firestore geoquery geospatial geofire geohash",
    "author": "Lukasz Majda",
    "author_email": "lukasz.majda@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/20/86/b38f4ef5d2b31c28d0541df9439a020925b3ed1f68ef6c3a80e791b1a39e/pygeoquery-0.1.6.tar.gz",
    "platform": null,
    "description": "# pygeoquery\n\n[![PyPI package](https://img.shields.io/badge/pip%20install-pygeoquery-brightgreen)](https://pypi.org/project/pygeoquery/)\n[![Version](https://img.shields.io/pypi/v/pygeoquery)](https://pypi.org/project/pygeoquery/0.1.0/)\n[![License](https://img.shields.io/github/license/booncol/pygeoquery)](https://github.com/booncol/pygeoquery/blob/main/LICENSE)\n\nPerform geospatial queries on a Firestore database with ease.\n\npygeoquery allows you to retrieve documents within a certain radius of a given geographic point. It utilizes geohashes for efficient querying.\n\n## Features\n- query Firestore collections by geographic proximity.\n- efficiently filter and retrieve documents within a specified radius.\n- flexible and customizable query building.\n- utilizes geohashes for high-performance geospatial queries.\n- supports both synchronous and asynchronous Firestore clients.\n\n## Installation\nYou can install the library using pip:\n\n```bash\npip install pygeoquery\n```\n\n## Prerequisites\n\nBefore using this library, ensure that each document in the searched Firestore collection includes a field called **\"geohash\"** containing a geohash value generated from the geographical coordinates. This geohash field is essential for the library to perform accurate geospatial queries.\n\n![Document preview](https://github.com/booncol/pygeoquery/blob/main/document_preview.png?raw=true)  \n\nTo generate geohashes, you can use Python libraries such as:\n\n- [pygeohash](https://pypi.org/project/pygeohash/): Provides functions for decoding and encoding geohashes.\n- [geohashr](https://pypi.org/project/geohashr/): Just another Python geohashing library.\n\n\n## Usage\n\n1) Initialize Firebase\n\n    ```python\n    from firebase_admin import initialize_app, credentials\n    from google.cloud import firestore\n    \n    \n    # Initialize Firebase\n    cred = credentials.Certificate(\"path/to/your/serviceAccountKey.json\")\n    initialize_app(cred, {\"projectId\": \"your-project-id\"})\n    ```\n\n2) Create Firestore client\n\n    ```python\n   # Synchronous client\n    db = firestore.Client()\n    ```\n    or    \n\n    ```python\n   # Asynchronous client\n    db = firestore.AsyncClient()\n    ```\n\n3) Define callback functions\n\n    ```python\n    # Define a GeoPointFromCallback\n    def geopoint_from_callback(data):\n        return data.get(\"location\")  # Replace with your data structure\n    \n    # Define query builder callback function (optional). This function allows you to customize your query.\n    def query_builder_callback(query):\n        return query.where(\"property\", \"==\", \"value\")  # Customize your query\n    ```\n\n4) Create a GeoCollectionReference or GeoAsyncCollectionReference\n\n    ```python\n    # Create a GeoCollectionReference\n    geocollection = GeoCollectionReference(db.collection(\"your_collection\"))\n   ```\n   \n    or\n\n    ```python\n    # Create a GeoAsyncCollectionReference (asynchronous client only)\n    geocollection = GeoAsyncCollectionReference(db.collection(\"your_collection\"))\n   ```\n\n5) Fetch documents within a radius of a GeoPoint\n\n    ```python\n    # Fetch documents within a radius of a GeoPoint\n    center_point = GeoPoint(latitude, longitude)\n    radius_km = 10.0\n    \n    result = geocollection.fetch_within(\n        center_point,\n        radius_km,\n        geopoint_from_callback,\n        query_builder_callback\n    )\n    \n    # Process the retrieved documents\n    for document in result:\n        print(document)\n    ```\n\n    If you are using the asynchronous client, use the `await` keyword to wait for the result.\n\n    ```python\n    result = await geocollection.fetch_within(\n        center_point,\n        radius_km,\n        geopoint_from_callback,\n        query_builder_callback\n    )\n    ```   \n\n## Acknowledgments\nThis project is inspired by the [geoflutterfire_plus](https://github.com/KosukeSaigusa/geoflutterfire_plus) Flutter module by [Kosuke Saigusa](https://github.com/kosukesaigusa), which provides similar geospatial querying functionality for Firestore databases in the Flutter framework.\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE](https://github.com/booncol/pygeoquery/blob/main/LICENSE) file for details.\n\n## Contributing\nPlease read [CONTRIBUTING.md](https://github.com/booncol/pygeoquery/blob/main/CONTRIBUTING.md) for details on my code of conduct, and the process for submitting pull requests to me.\n\n## Contact\nIf you have questions or need assistance, feel free to contact me.\n\n**Happy querying!**\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Geoqueries on Firestore Database for Python",
    "version": "0.1.6",
    "project_urls": {
        "Homepage": "https://github.com/booncol/pygeoquery"
    },
    "split_keywords": [
        "firestore",
        "geoquery",
        "geospatial",
        "geofire",
        "geohash"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2086b38f4ef5d2b31c28d0541df9439a020925b3ed1f68ef6c3a80e791b1a39e",
                "md5": "46fb73ac5445091c2ac66af24653e303",
                "sha256": "d521064f8c35dbe26a730ce0fa0707a25e70c25c8c3826f3229131b26f827010"
            },
            "downloads": -1,
            "filename": "pygeoquery-0.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "46fb73ac5445091c2ac66af24653e303",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 8182,
            "upload_time": "2023-10-30T22:24:20",
            "upload_time_iso_8601": "2023-10-30T22:24:20.965363Z",
            "url": "https://files.pythonhosted.org/packages/20/86/b38f4ef5d2b31c28d0541df9439a020925b3ed1f68ef6c3a80e791b1a39e/pygeoquery-0.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-30 22:24:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "booncol",
    "github_project": "pygeoquery",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pygeoquery"
}
        
Elapsed time: 2.68010s