Metadata-Version: 2.1
Name: exponent_server_sdk
Version: 1.0.3
Summary: Expo Server SDK for Python
Home-page: https://github.com/expo/exponent-server-sdk-python
Author: Expo Team
Author-email: exponent.team@gmail.com
License: MIT
Description: # exponent-server-sdk-python
        
        This repo is maintained by Expo's awesome community :heart_eyes:! So, if you have problems with the code in this repository, please feel free to open an issue, and make a PR. Thanks!
        
        ## Installation
        
        ```
        pip install exponent_server_sdk
        ```
        
        ## Usage
        
        Use to send push notifications to Exponent Experiences from a Python server.
        
        [Full documentation](https://docs.expo.io/versions/latest/guides/push-notifications#http2-api) on the API is available if you want to dive into the details.
        
        Here's an example on how to use this with retries and reporting via [pyrollbar](https://github.com/rollbar/pyrollbar).
        ```python
        from exponent_server_sdk import (
            DeviceNotRegisteredError,
            PushClient,
            PushMessage,
            PushResponseError,
            PushServerError,
        ) 
        from requests.exceptions import ConnectionError, HTTPError
        
        
        # Basic arguments. You should extend this function with the push features you
        # want to use, or simply pass in a `PushMessage` object.
        def send_push_message(token, message, extra=None):
            try:
                response = PushClient().publish(
                    PushMessage(to=token,
                                body=message,
                                data=extra))
            except PushServerError as exc:
                # Encountered some likely formatting/validation error.
                rollbar.report_exc_info(
                    extra_data={
                        'token': token,
                        'message': message,
                        'extra': extra,
                        'errors': exc.errors,
                        'response_data': exc.response_data,
                    })
                raise
            except (ConnectionError, HTTPError) as exc:
                # Encountered some Connection or HTTP error - retry a few times in
                # case it is transient.
                rollbar.report_exc_info(
                    extra_data={'token': token, 'message': message, 'extra': extra})
                raise self.retry(exc=exc)
        
            try:
                # We got a response back, but we don't know whether it's an error yet.
                # This call raises errors so we can handle them with normal exception
                # flows.
                response.validate_response()
            except DeviceNotRegisteredError:
                # Mark the push token as inactive
                from notifications.models import PushToken
                PushToken.objects.filter(token=token).update(active=False)
            except PushTicketError as exc:
                # Encountered some other per-notification error.
                rollbar.report_exc_info(
                    extra_data={
                        'token': token,
                        'message': message,
                        'extra': extra,
                        'push_response': exc.push_response._asdict(),
                    })
                raise self.retry(exc=exc)
        ```
        
Platform: UNKNOWN
Description-Content-Type: text/markdown
