aiopyfcm


Nameaiopyfcm JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/837477/aiopyfcm
Summaryaiopyfcm is Python Asynchronous FCM Push Controller
upload_time2024-08-17 08:52:08
maintainerNone
docs_urlNone
author837477
requires_pythonNone
licenseMIT License
keywords aiopyfcm is python asynchronous fcm push controller
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <br><br><br>
<p align="center">
  <a href="https://github.com/837477/aiopyfcm"><img src="https://github.com/user-attachments/assets/5825c842-8031-4ada-ab37-e2be74653e69"></a>
</p>
<p align="center">
    <em>From now on, easily send FCM (Firebase Cloud Messages) through "aiopyfcm"</em>
</p>
<p align="center">
<a href="https://github.com/837477/aiopyfcm/blob/main/LICENSE" target="_blank">
    <img src="https://img.shields.io/pypi/l/aiopyfcm?color=FEC301" alt="License">
</a>
<a href="https://pypi.org/project/aiopyfcm" target="_blank">
    <img src="https://img.shields.io/pypi/v/aiopyfcm?color=FEC301" alt="Package version">
</a>
<a href="https://pypi.org/project/aiopyfcm" target="_blank">
    <img src="https://img.shields.io/pypi/pyversions/aiopyfcm?color=FEC301" alt="Supported Python versions">
</a>
</p>
<br><br><br>

---

**Documnets**: <a href="https://github.com/837477/aiopyfcm" target="_blank">https://github.com/837477/aiopyfcm </a>

---

You can now easily send asynchronous FCM messages.<br>
`aiopyfcm` has the following features:

- Support for sending Python Asyncio FCM messages
- Supports all types of messages handled by FCM
- Very convenient message sending interface
- Easily handle Firebase credentials (Json File / Json String / Dict)
- Supports automatic access token refresh.
- Increase performance efficiency by maintaining asynchronous sessions depending on the situation.
- All exception situations in FCM can be controlled.


## Requirements

If you are planning to use FCM now, I think you have already studied FCM.<br>
As you know, `google_application_credentials` is required to use FCM.<br>
**The existing Cloud Messaging API server key will be deprecated on June 20, 2024, so it is recommended to obtain a `google_application_credentials` key in the future.**

To authenticate a service account and authorize it to access Firebase services, you must generate a private key file in JSON format.

To generate a private key file for your service account: <br>
1. In the Firebase console, open Settings > <a href="https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk?_gl=1*pput8o*_up*MQ..*_ga*MTQ0NTkyMjIzOC4xNzExMTMyOTM2*_ga_CW55HF8NVT*MTcxMTEzMjkzNi4xLjAuMTcxMTEzMjkzNi4wLjAuMA.." target="_blank">Service Accounts. </a>
2. Click Generate New Private Key, then confirm by clicking Generate Key.
3. Securely store the JSON file containing the key.

For a more detailed explanation, please refer to the following official document.<br>
https://firebase.google.com/docs/cloud-messaging/migrate-v1#provide-credentials-using-adc


## Installation

```console
$ pip install aiopyfcm
```

## Example

You can use it flexibly according to your development situation.
* You can check it in the `example.py` file.

```Python
import json
import asyncio
import aiopyfcm


async def credentials_sample_1():
    """
    This example demonstrates an authorization method using a JSON file.
    """

    # Initialize the AioPyFCM object.
    aiopyfcm_module = aiopyfcm.AioPyFCM()

    # Initialize the credentials from the JSON file. (Be required)
    aiopyfcm_module.init_credentials_from_file(
        credentials_file_path="<your_credentials_path>/credentials.json",
        auto_refresh=True  # Default is True
    )

    return aiopyfcm_module


async def credentials_sample_2():
    """
    This example demonstrates how to authenticate by converting the contents of a JSON file into a <Dict> or <String>.
    """
    credentials_dict = {
        "type": "service_account",
        "project_id": "837477-Sample",
        "private_key_id": "XXXX...",
        "private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
        "client_email": "firebase-adminsdk-XXXX...",
        "client_id": "XXXX...",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token",
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-XXXX...",
        "universe_domain": "googleapis.com"
    }
    credentials_dumps = json.dumps(credentials_dict)

    # Initialize the AioPyFCM object.
    aiopyfcm_module = aiopyfcm.AioPyFCM()

    # Initialize the credentials from the <Dict> or <JSON string>. (Be required)
    aiopyfcm_module.init_credentials(
        credentials=credentials_dict or credentials_dumps,
        auto_refresh=True  # Default is True
    )

    return aiopyfcm_module


async def send_stateful_sample():
    """
    This sample is used when you want to maintain an asynchronous session of aiohttp.
    You can use resources efficiently by not opening a session every time you send.
    """

    # Initialize the AioPyFCM object.
    aiopyfcm_module = await credentials_sample_1()

    # Create a message object.
    message = {
        "notification": {
            "title": "Sample Title",
            "body": "Sample Body",
            "image": "https://example.com/sample.jpg"
        }
    }

    # Send the message. (Stateful - Recommended)
    async with aiopyfcm_module as async_fcm:
        responses = await asyncio.gather(
            async_fcm.send(message),
            async_fcm.send(message),
            async_fcm.send(message),
        )
        print(responses)


async def send_stateless_sample():
    """
    This sample uses the AsyncPyFCM object by declaring it.
    This method does not maintain the aiohttp asynchronous session,
    so it connects the session every time you send.
    """

    # Initialize the AioPyFCM object.
    aiopyfcm_module = await credentials_sample_1()

    # Create a message object.
    message = {
        "token": "<FCM_TOKEN>",
        "notification": {
            "title": "Sample Title",
            "body": "Sample Body",
            "image": "https://example.com/sample.jpg"
        }
    }

    # Send the message. (Stateless)
    responses = await asyncio.gather(
        aiopyfcm_module.send(message),
        aiopyfcm_module.send(message),
        aiopyfcm_module.send(message),
    )
    print(responses)

```

## Contributing
The following is a set of guidelines for contributing to `aiopyfcm`. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.

1. Please create a branch in this format, **`<Issue Number>-<Some name>`**
2. Open a terminal and navigate to your project path. And enter this.
   **`git config --global commit.template .gitmessage.txt`**
3. You can use the template, with `git commit` through vi. **Not** `git commit -m`
4. If you want to merge your work, please pull request to the `dev` branch.
5. Enjoy contributing!

If you have any other opinions, please feel free to suggest 😀

## License

This project is licensed under the terms of the MIT license.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/837477/aiopyfcm",
    "name": "aiopyfcm",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "aiopyfcm is Python Asynchronous FCM Push Controller",
    "author": "837477",
    "author_email": "8374770@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f7/b7/f1ee04bb6f5361bf63f3895323201356f45e9ad6e0f8d2f00bd85b1cf620/aiopyfcm-0.1.0.tar.gz",
    "platform": "any",
    "description": "<br><br><br>\n<p align=\"center\">\n  <a href=\"https://github.com/837477/aiopyfcm\"><img src=\"https://github.com/user-attachments/assets/5825c842-8031-4ada-ab37-e2be74653e69\"></a>\n</p>\n<p align=\"center\">\n    <em>From now on, easily send FCM (Firebase Cloud Messages) through \"aiopyfcm\"</em>\n</p>\n<p align=\"center\">\n<a href=\"https://github.com/837477/aiopyfcm/blob/main/LICENSE\" target=\"_blank\">\n    <img src=\"https://img.shields.io/pypi/l/aiopyfcm?color=FEC301\" alt=\"License\">\n</a>\n<a href=\"https://pypi.org/project/aiopyfcm\" target=\"_blank\">\n    <img src=\"https://img.shields.io/pypi/v/aiopyfcm?color=FEC301\" alt=\"Package version\">\n</a>\n<a href=\"https://pypi.org/project/aiopyfcm\" target=\"_blank\">\n    <img src=\"https://img.shields.io/pypi/pyversions/aiopyfcm?color=FEC301\" alt=\"Supported Python versions\">\n</a>\n</p>\n<br><br><br>\n\n---\n\n**Documnets**: <a href=\"https://github.com/837477/aiopyfcm\" target=\"_blank\">https://github.com/837477/aiopyfcm </a>\n\n---\n\nYou can now easily send asynchronous FCM messages.<br>\n`aiopyfcm` has the following features:\n\n- Support for sending Python Asyncio FCM messages\n- Supports all types of messages handled by FCM\n- Very convenient message sending interface\n- Easily handle Firebase credentials (Json File / Json String / Dict)\n- Supports automatic access token refresh.\n- Increase performance efficiency by maintaining asynchronous sessions depending on the situation.\n- All exception situations in FCM can be controlled.\n\n\n## Requirements\n\nIf you are planning to use FCM now, I think you have already studied FCM.<br>\nAs you know, `google_application_credentials` is required to use FCM.<br>\n**The existing Cloud Messaging API server key will be deprecated on June 20, 2024, so it is recommended to obtain a `google_application_credentials` key in the future.**\n\nTo authenticate a service account and authorize it to access Firebase services, you must generate a private key file in JSON format.\n\nTo generate a private key file for your service account: <br>\n1. In the Firebase console, open Settings > <a href=\"https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk?_gl=1*pput8o*_up*MQ..*_ga*MTQ0NTkyMjIzOC4xNzExMTMyOTM2*_ga_CW55HF8NVT*MTcxMTEzMjkzNi4xLjAuMTcxMTEzMjkzNi4wLjAuMA..\" target=\"_blank\">Service Accounts. </a>\n2. Click Generate New Private Key, then confirm by clicking Generate Key.\n3. Securely store the JSON file containing the key.\n\nFor a more detailed explanation, please refer to the following official document.<br>\nhttps://firebase.google.com/docs/cloud-messaging/migrate-v1#provide-credentials-using-adc\n\n\n## Installation\n\n```console\n$ pip install aiopyfcm\n```\n\n## Example\n\nYou can use it flexibly according to your development situation.\n* You can check it in the `example.py` file.\n\n```Python\nimport json\nimport asyncio\nimport aiopyfcm\n\n\nasync def credentials_sample_1():\n    \"\"\"\n    This example demonstrates an authorization method using a JSON file.\n    \"\"\"\n\n    # Initialize the AioPyFCM object.\n    aiopyfcm_module = aiopyfcm.AioPyFCM()\n\n    # Initialize the credentials from the JSON file. (Be required)\n    aiopyfcm_module.init_credentials_from_file(\n        credentials_file_path=\"<your_credentials_path>/credentials.json\",\n        auto_refresh=True  # Default is True\n    )\n\n    return aiopyfcm_module\n\n\nasync def credentials_sample_2():\n    \"\"\"\n    This example demonstrates how to authenticate by converting the contents of a JSON file into a <Dict> or <String>.\n    \"\"\"\n    credentials_dict = {\n        \"type\": \"service_account\",\n        \"project_id\": \"837477-Sample\",\n        \"private_key_id\": \"XXXX...\",\n        \"private_key\": \"-----BEGIN PRIVATE KEY-----\\n...\\n-----END PRIVATE KEY-----\\n\",\n        \"client_email\": \"firebase-adminsdk-XXXX...\",\n        \"client_id\": \"XXXX...\",\n        \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n        \"token_uri\": \"https://oauth2.googleapis.com/token\",\n        \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\",\n        \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-XXXX...\",\n        \"universe_domain\": \"googleapis.com\"\n    }\n    credentials_dumps = json.dumps(credentials_dict)\n\n    # Initialize the AioPyFCM object.\n    aiopyfcm_module = aiopyfcm.AioPyFCM()\n\n    # Initialize the credentials from the <Dict> or <JSON string>. (Be required)\n    aiopyfcm_module.init_credentials(\n        credentials=credentials_dict or credentials_dumps,\n        auto_refresh=True  # Default is True\n    )\n\n    return aiopyfcm_module\n\n\nasync def send_stateful_sample():\n    \"\"\"\n    This sample is used when you want to maintain an asynchronous session of aiohttp.\n    You can use resources efficiently by not opening a session every time you send.\n    \"\"\"\n\n    # Initialize the AioPyFCM object.\n    aiopyfcm_module = await credentials_sample_1()\n\n    # Create a message object.\n    message = {\n        \"notification\": {\n            \"title\": \"Sample Title\",\n            \"body\": \"Sample Body\",\n            \"image\": \"https://example.com/sample.jpg\"\n        }\n    }\n\n    # Send the message. (Stateful - Recommended)\n    async with aiopyfcm_module as async_fcm:\n        responses = await asyncio.gather(\n            async_fcm.send(message),\n            async_fcm.send(message),\n            async_fcm.send(message),\n        )\n        print(responses)\n\n\nasync def send_stateless_sample():\n    \"\"\"\n    This sample uses the AsyncPyFCM object by declaring it.\n    This method does not maintain the aiohttp asynchronous session,\n    so it connects the session every time you send.\n    \"\"\"\n\n    # Initialize the AioPyFCM object.\n    aiopyfcm_module = await credentials_sample_1()\n\n    # Create a message object.\n    message = {\n        \"token\": \"<FCM_TOKEN>\",\n        \"notification\": {\n            \"title\": \"Sample Title\",\n            \"body\": \"Sample Body\",\n            \"image\": \"https://example.com/sample.jpg\"\n        }\n    }\n\n    # Send the message. (Stateless)\n    responses = await asyncio.gather(\n        aiopyfcm_module.send(message),\n        aiopyfcm_module.send(message),\n        aiopyfcm_module.send(message),\n    )\n    print(responses)\n\n```\n\n## Contributing\nThe following is a set of guidelines for contributing to `aiopyfcm`. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.\n\n1. Please create a branch in this format, **`<Issue Number>-<Some name>`**\n2. Open a terminal and navigate to your project path. And enter this.\n   **`git config --global commit.template .gitmessage.txt`**\n3. You can use the template, with `git commit` through vi. **Not** `git commit -m`\n4. If you want to merge your work, please pull request to the `dev` branch.\n5. Enjoy contributing!\n\nIf you have any other opinions, please feel free to suggest \ud83d\ude00\n\n## License\n\nThis project is licensed under the terms of the MIT license.\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "aiopyfcm is Python Asynchronous FCM Push Controller",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/837477/aiopyfcm"
    },
    "split_keywords": [
        "aiopyfcm",
        "is",
        "python",
        "asynchronous",
        "fcm",
        "push",
        "controller"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d128fd9408a94ed52b88f0a5da93e263079ed50fcfef27e50de6198ad881b533",
                "md5": "5fe6cba8b918af4f60ca3330b77b9b3a",
                "sha256": "c79f4d4a72598ca7f559c6efa87abc42820091f1b04773a6bfcae70d7e274620"
            },
            "downloads": -1,
            "filename": "aiopyfcm-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5fe6cba8b918af4f60ca3330b77b9b3a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8706,
            "upload_time": "2024-08-17T08:52:07",
            "upload_time_iso_8601": "2024-08-17T08:52:07.025181Z",
            "url": "https://files.pythonhosted.org/packages/d1/28/fd9408a94ed52b88f0a5da93e263079ed50fcfef27e50de6198ad881b533/aiopyfcm-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f7b7f1ee04bb6f5361bf63f3895323201356f45e9ad6e0f8d2f00bd85b1cf620",
                "md5": "cecda6d559aa0414535a7ed3d64aba9c",
                "sha256": "4f2f32483fb5345592f8b8fa902ee3ce0e084291c0e0f239cf17a999406c7d1c"
            },
            "downloads": -1,
            "filename": "aiopyfcm-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "cecda6d559aa0414535a7ed3d64aba9c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10137,
            "upload_time": "2024-08-17T08:52:08",
            "upload_time_iso_8601": "2024-08-17T08:52:08.215955Z",
            "url": "https://files.pythonhosted.org/packages/f7/b7/f1ee04bb6f5361bf63f3895323201356f45e9ad6e0f8d2f00bd85b1cf620/aiopyfcm-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-17 08:52:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "837477",
    "github_project": "aiopyfcm",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "aiopyfcm"
}
        
Elapsed time: 0.35092s