async-pyfcm


Nameasync-pyfcm JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/837477/async-pyfcm
SummaryPython Asynchronous FCM Push Controller
upload_time2024-03-26 03:04:50
maintainerNone
docs_urlNone
author837477
requires_pythonNone
licenseMIT License
keywords python asynchronous fcm push controller
VCS
bugtrack_url
requirements aiohttp aiosignal attrs cachetools certifi charset-normalizer frozenlist google-auth idna multidict pyasn1 pyasn1-modules requests rsa urllib3 yarl
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <br><br><br>
<p align="center">
  <a href="https://github.com/837477/async-pyfcm"><img src="https://github.com/837477/async-pyfcm/assets/37999795/249c6b6f-5f82-4b80-8c4f-e2c3311f1f15"></a>
</p>
<p align="center">
    <em>From now on, easily send FCM (Firebase Cloud Messages) through Python asyncio!</em>
</p>
<p align="center">
<a href="https://github.com/837477/async-pyfcm/blob/main/LICENSE" target="_blank">
    <img src="https://img.shields.io/pypi/l/async-pyfcm?color=FEC301" alt="License">
</a>
<a href="https://pypi.org/project/async-pyfcm" target="_blank">
    <img src="https://img.shields.io/pypi/v/async-pyfcm?color=FEC301" alt="Package version">
</a>
<a href="https://pypi.org/project/async-pyfcm" target="_blank">
    <img src="https://img.shields.io/pypi/pyversions/async-pyfcm?color=FEC301" alt="Supported Python versions">
</a>
</p>
<br><br><br>

---

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

---

You can now easily send asynchronous FCM messages.<br>
`AsyncPyfcm` 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 / Json Object[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 async-pyfcm
```

## Example

### AsyncPyFCM Initialization

```Python
from async_pyfcm import AsyncPyFCM

# AsyncPyFCM requires one required parameter and one optional parameter.

# [param] google_application_credentials:
# Private key issued from Firebase's project service account
# (Json File Path / Json String inside File / Json Object(dict) inside File)

# [param] token_auto_refresh:
# Google API's Access Token expires after a certain period of time.
# Decide whether to automatically refresh the Access Token.

# True (Default): The Access Token is checked immediately before sending the message, and is automatically renewed 30 minutes before expiration.
# False: Access Token is not refreshed automatically.
#   - In this case, the AsyncPyFCM object must be created again.
#   - Suitable for short-term use.

# Case 1: Json File Path
async_pyfcm = AsyncPyFCM(
    google_application_credentials="google-application-credentials.json",
    token_auto_refresh=True
)

# Case 2: Json String inside File
async_pyfcm = AsyncPyFCM(
    google_application_credentials='{"type": "service_account", ...}',
    token_auto_refresh=True
)

# Case 3: Json Object(dict) inside File
async_pyfcm = AsyncPyFCM(
    google_application_credentials={
        "type": "service_account",
        ...
    },
    token_auto_refresh=True
)
```

You can use it flexibly according to your development situation.


### Asynchronous FCM message sending

* You can check it in the `example.py` file.

```Python
from async_pyfcm import AsyncPyFCM

async def stateful_session():
    # 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.
    async with AsyncPyFCM(google_application_credentials="path/to/your/credentials.json") as async_fcm:
        responses = await asyncio.gather(
            async_fcm.send(message),
            async_fcm.send(message),
            async_fcm.send(message),
        )
        return responses

async def stateless_session():
    # 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.
    async_pyfcm = AsyncPyFCM(
        google_application_credentials="path/to/your/credentials.json"
    )
    responses = await asyncio.gather(
        async_pyfcm.send(message),
        async_pyfcm.send(message),
        async_pyfcm.send(message),
    )
    return responses
```


### Message Resource

* You can check it in the `message.py` file.

```Python
# All message formats provided by FCM documents are supported.
class Message(TypedDict):
    """
    FCM Message Resource
    https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages
    """
    name: str
    data: dict[str, str]
    notification: Notification
    android: AndroidConfig
    webpush: WebpushConfig
    apns: ApnsConfig
    fcm_options: FcmOptions
    token: str
    topic: str
    condition: str
```

## Contributing
The following is a set of guidelines for contributing to `async-pyfcm`. 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/async-pyfcm",
    "name": "async-pyfcm",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "Python Asynchronous FCM Push Controller",
    "author": "837477",
    "author_email": "8374770@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a5/7f/df2b23127216cf4f4a6066292a5a2c03548bdab275160f40a35cb3fb797f/async-pyfcm-0.1.4.tar.gz",
    "platform": "any",
    "description": "<br><br><br>\n<p align=\"center\">\n  <a href=\"https://github.com/837477/async-pyfcm\"><img src=\"https://github.com/837477/async-pyfcm/assets/37999795/249c6b6f-5f82-4b80-8c4f-e2c3311f1f15\"></a>\n</p>\n<p align=\"center\">\n    <em>From now on, easily send FCM (Firebase Cloud Messages) through Python asyncio!</em>\n</p>\n<p align=\"center\">\n<a href=\"https://github.com/837477/async-pyfcm/blob/main/LICENSE\" target=\"_blank\">\n    <img src=\"https://img.shields.io/pypi/l/async-pyfcm?color=FEC301\" alt=\"License\">\n</a>\n<a href=\"https://pypi.org/project/async-pyfcm\" target=\"_blank\">\n    <img src=\"https://img.shields.io/pypi/v/async-pyfcm?color=FEC301\" alt=\"Package version\">\n</a>\n<a href=\"https://pypi.org/project/async-pyfcm\" target=\"_blank\">\n    <img src=\"https://img.shields.io/pypi/pyversions/async-pyfcm?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/async-pyfcm\" target=\"_blank\">https://github.com/837477/async-pyfcm </a>\n\n---\n\nYou can now easily send asynchronous FCM messages.<br>\n`AsyncPyfcm` 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 / Json Object[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 async-pyfcm\n```\n\n## Example\n\n### AsyncPyFCM Initialization\n\n```Python\nfrom async_pyfcm import AsyncPyFCM\n\n# AsyncPyFCM requires one required parameter and one optional parameter.\n\n# [param] google_application_credentials:\n# Private key issued from Firebase's project service account\n# (Json File Path / Json String inside File / Json Object(dict) inside File)\n\n# [param] token_auto_refresh:\n# Google API's Access Token expires after a certain period of time.\n# Decide whether to automatically refresh the Access Token.\n\n# True (Default): The Access Token is checked immediately before sending the message, and is automatically renewed 30 minutes before expiration.\n# False: Access Token is not refreshed automatically.\n#   - In this case, the AsyncPyFCM object must be created again.\n#   - Suitable for short-term use.\n\n# Case 1: Json File Path\nasync_pyfcm = AsyncPyFCM(\n    google_application_credentials=\"google-application-credentials.json\",\n    token_auto_refresh=True\n)\n\n# Case 2: Json String inside File\nasync_pyfcm = AsyncPyFCM(\n    google_application_credentials='{\"type\": \"service_account\", ...}',\n    token_auto_refresh=True\n)\n\n# Case 3: Json Object(dict) inside File\nasync_pyfcm = AsyncPyFCM(\n    google_application_credentials={\n        \"type\": \"service_account\",\n        ...\n    },\n    token_auto_refresh=True\n)\n```\n\nYou can use it flexibly according to your development situation.\n\n\n### Asynchronous FCM message sending\n\n* You can check it in the `example.py` file.\n\n```Python\nfrom async_pyfcm import AsyncPyFCM\n\nasync def stateful_session():\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    async with AsyncPyFCM(google_application_credentials=\"path/to/your/credentials.json\") 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        return responses\n\nasync def stateless_session():\n    # This sample uses the AsyncPyFCM object by declaring it.\n    # This method does not maintain the aiohttp asynchronous session, so it connects the session every time you send.\n    async_pyfcm = AsyncPyFCM(\n        google_application_credentials=\"path/to/your/credentials.json\"\n    )\n    responses = await asyncio.gather(\n        async_pyfcm.send(message),\n        async_pyfcm.send(message),\n        async_pyfcm.send(message),\n    )\n    return responses\n```\n\n\n### Message Resource\n\n* You can check it in the `message.py` file.\n\n```Python\n# All message formats provided by FCM documents are supported.\nclass Message(TypedDict):\n    \"\"\"\n    FCM Message Resource\n    https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages\n    \"\"\"\n    name: str\n    data: dict[str, str]\n    notification: Notification\n    android: AndroidConfig\n    webpush: WebpushConfig\n    apns: ApnsConfig\n    fcm_options: FcmOptions\n    token: str\n    topic: str\n    condition: str\n```\n\n## Contributing\nThe following is a set of guidelines for contributing to `async-pyfcm`. 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": "Python Asynchronous FCM Push Controller",
    "version": "0.1.4",
    "project_urls": {
        "Homepage": "https://github.com/837477/async-pyfcm"
    },
    "split_keywords": [
        "python",
        "asynchronous",
        "fcm",
        "push",
        "controller"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "55809f7e182c8d954739bad3847074e06a3b2a7a8d4d1f717232d8dacda0ed93",
                "md5": "ded429311bc165ebfc74f501a7beff8c",
                "sha256": "aae1e80f22e4248c2711f7631dce686a0cd114930220952e0ebff673750c4891"
            },
            "downloads": -1,
            "filename": "async_pyfcm-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ded429311bc165ebfc74f501a7beff8c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9140,
            "upload_time": "2024-03-26T03:04:49",
            "upload_time_iso_8601": "2024-03-26T03:04:49.018871Z",
            "url": "https://files.pythonhosted.org/packages/55/80/9f7e182c8d954739bad3847074e06a3b2a7a8d4d1f717232d8dacda0ed93/async_pyfcm-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a57fdf2b23127216cf4f4a6066292a5a2c03548bdab275160f40a35cb3fb797f",
                "md5": "52370fc9f2dcf75d16c1c307453459b5",
                "sha256": "74cf8a6c1ffecba63e038fd5ab186ae388541fc63e7a50b73726342b95f2251d"
            },
            "downloads": -1,
            "filename": "async-pyfcm-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "52370fc9f2dcf75d16c1c307453459b5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9790,
            "upload_time": "2024-03-26T03:04:50",
            "upload_time_iso_8601": "2024-03-26T03:04:50.765795Z",
            "url": "https://files.pythonhosted.org/packages/a5/7f/df2b23127216cf4f4a6066292a5a2c03548bdab275160f40a35cb3fb797f/async-pyfcm-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-26 03:04:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "837477",
    "github_project": "async-pyfcm",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "aiohttp",
            "specs": [
                [
                    "==",
                    "3.9.3"
                ]
            ]
        },
        {
            "name": "aiosignal",
            "specs": [
                [
                    "==",
                    "1.3.1"
                ]
            ]
        },
        {
            "name": "attrs",
            "specs": [
                [
                    "==",
                    "23.2.0"
                ]
            ]
        },
        {
            "name": "cachetools",
            "specs": [
                [
                    "==",
                    "5.3.3"
                ]
            ]
        },
        {
            "name": "certifi",
            "specs": [
                [
                    "==",
                    "2024.2.2"
                ]
            ]
        },
        {
            "name": "charset-normalizer",
            "specs": [
                [
                    "==",
                    "3.3.2"
                ]
            ]
        },
        {
            "name": "frozenlist",
            "specs": [
                [
                    "==",
                    "1.4.1"
                ]
            ]
        },
        {
            "name": "google-auth",
            "specs": [
                [
                    "==",
                    "2.29.0"
                ]
            ]
        },
        {
            "name": "idna",
            "specs": [
                [
                    "==",
                    "3.6"
                ]
            ]
        },
        {
            "name": "multidict",
            "specs": [
                [
                    "==",
                    "6.0.5"
                ]
            ]
        },
        {
            "name": "pyasn1",
            "specs": [
                [
                    "==",
                    "0.5.1"
                ]
            ]
        },
        {
            "name": "pyasn1-modules",
            "specs": [
                [
                    "==",
                    "0.3.0"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.31.0"
                ]
            ]
        },
        {
            "name": "rsa",
            "specs": [
                [
                    "==",
                    "4.9"
                ]
            ]
        },
        {
            "name": "urllib3",
            "specs": [
                [
                    "==",
                    "2.2.1"
                ]
            ]
        },
        {
            "name": "yarl",
            "specs": [
                [
                    "==",
                    "1.9.4"
                ]
            ]
        }
    ],
    "lcname": "async-pyfcm"
}
        
Elapsed time: 0.21986s