upchatpy


Nameupchatpy JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/vertyco/upchatpy
SummaryA type hinted async Python wrapper for the Upgrade.Chat API
upload_time2024-08-18 17:02:32
maintainerNone
docs_urlNone
authorvertyco
requires_python>=3.9
licenseNone
keywords upgrade.chat chat bot discord upgradechat donations subscriptions monetization payment api wrapper client
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <img src="https://repository-images.githubusercontent.com/719405304/08bd8dbc-7215-42d7-8bf8-361cc84af957" width="40%" />
</p>

# UpChatPy: Upgrade.Chat Python Wrapper

This package provides a fully async, type-complete wraper for the **[Upgrade.Chat](https://upgrade.chat/developers/documentation)** API.

[![PyPi](https://img.shields.io/pypi/v/upchatpy)](https://pypi.org/project/upchatpy/)
[![Downloads](https://img.shields.io/pypi/dm/upchatpy)](https://pypi.org/project/upchatpy/)
![GitHub License](https://img.shields.io/github/license/vertyco/upchatpy)

[![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-3913/)
[![Python 3.10](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-31011/)
[![Python 3.11](https://img.shields.io/badge/python-3.11-blue.svg)](https://www.python.org/downloads/release/python-3116/)
[![Python 3.12](https://img.shields.io/badge/python-3.12-blue.svg)](https://www.python.org/downloads/release/python-3125/)

#### Pydantic Cross Compatibility

[![Pydantic v1](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v1.json)](https://docs.pydantic.dev/1.10/contributing/#badges)
[![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://docs.pydantic.dev/latest/contributing/#badges)

#### References

Upgrade.Chat is a platform that facilitates monetization for community services, particularly Discord. This wrapper aims to simplify integration with other 3rd party apps.

- [Homepage](https://upgrade.chat/)
- [FAQ](https://docs.upgrade.chat/)
- [API Docs](https://upgrade.chat/developers/documentation)

## Installation

To install the package, run the following command:

```bash
pip install upchatpy
```

## Usage

Before you can start using the API, you need to obtain your client ID and client secret from Upgrade.Chat. Once you have them, you can begin by creating a `Client` instance:

```python
from upchatpy import Client

client_id = 'your_client_id'
client_secret = 'your_client_secret'

client = Client(client_id, client_secret)
```

### Authentication

The wrapper handles authentication automatically when making API calls. However, you can manually authenticate and retrieve the access token as follows:

```python
auth = await client.get_auth()
print(auth.access_token)  # Access token is now available
or
print(client.auth.access_token)  # Access token also available via client instance
```

### Fetching Orders

To fetch orders, use the following method:

```python
orders_response = await client.get_orders()
for order in orders_response.data:
    print(order.uuid, order.total)
```

To fetch all orders with pagination support:

```python
async for orders_response in client.aget_orders():
    for order in orders_response.data:
        print(order.uuid, order.total)
```

To fetch a specific order by UUID:

```python
order_uuid = 'your_order_uuid'
order_response = await client.get_order(order_uuid)
print(order_response.data.total)
```

### Fetching Products

Fetch a list of products using:

```python
products_response = await client.get_products()
for product in products_response.data:
    print(product.uuid, product.name)
```

To fetch all products with pagination support:

```python
async for products_response in client.aget_products():
    for product in products_response.data:
        print(product.uuid, product.name)
```

To fetch a product order by UUID:

```python
product_uuid = 'your_product_uuid'
product_response = await client.get_product(product_uuid)
print(product_response.data.name)
```

### Fetching Users

To get a list of users, you can do:

```python
users_response = await client.get_users()
for user in users_response.data:
    print(user.discord_id, user.username)
```

### Fetching Webhooks

Fetch a list of webhooks using:

```python
webhooks_response = await client.get_webhooks()
for webhook in webhooks_response.data:
    print(webhook.id, webhook.uri)
```

To fetch all webhooks with pagination support:

```python
async for webhooks_response in client.aget_webhooks():
    for webhook in webhooks_response.data:
        print(webhook.id, webhook.url)
```

To fetch a specific webhook by ID:

```python
webhook_id = 'your_webhook_id'
webhook_response = await client.get_webhook(webhook_id)
print(webhook_response.data.id, webhook_response.data.url)
```

### Fetching Webhook Events

Fetch a list of webhooks events using:

```python
webhook_events_response = await client.get_webhook_events()
for webhook_event in webhook_events_response.data:
    print(webhook_event.id, webhook_event.webhook_id)
```

To fetch a list of webhook events with pagination support:

```python
async for webhook_events_response in client.aget_webhook_events():
    for webhook_event in webhook_events_response.data:
        print(webhook_event.id, webhook_event.webhook_id)
```

To fetch a specific webhook event by ID:

```python
event_id = 'your_event_id'
webhook_event_response = await client.get_webhook_event(event_id)
print(webhook_event_response.data.id)
```

### Validating Webhook Events

To validate a webhook event by ID:

```python
event_id = 'your_event_id'
webhook_valid_response = await client.validate_webhook_event(event_id)
print(webhook_valid_response.data.is_valid)
```

### Checking Subscriptions

The `user_is_subscribed` method enables you to check if a user is currently subscribed to a specific product. This can be useful for verifying user access to features or content based on their subscription status.

```python
# Replace the following with the actual product UUID and user Discord ID
product_uuid = "c1eaaee5-9620-4343-b9da-test123"
user_discord_id = "12312312312312312"

is_subscribed = await client.user_is_subscribed(product_id, user_discord_id)
print(is_subscribed)
>> True or False
```

## Exception Handling

The Upgrade.Chat Python Wrapper provides custom exceptions to help you handle potential errors that may occur during API interaction.

### Custom Exceptions

- `AuthenticationError`: Raised when there is a problem with client authentication, such as incorrect client ID or client secret.
- `HTTPError`: Raised for general HTTP-related errors when making API requests.
- `ResourceNotFoundError`: Raised when a requested resource is not found on the Upgrade.Chat API.

### Example Usage

```python
from upchatpy import Client
from upchatpy.exceptions import AuthenticationError, HTTPError, ResourceNotFoundError

client_id = 'your_client_id'
client_secret = 'your_client_secret'
client = Client(client_id, client_secret)

async def main():
    try:
        orders_response = await client.get_orders()
        for order in orders_response.data:
            print(order.uuid, order.total)
    except AuthenticationError as e:
        print(f"Authentication failed with status code {e.status_code}: {e.message}")
    except ResourceNotFoundError as e:
        print(f"Resource not found with status code {e.status_code}: {e.message}")
    except HTTPError as e:
        print(f"HTTP error with status code {e.status_code}: {e.message}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")
```

## Development

This package is under active development, and contributions are welcome! If you encounter any issues or have feature requests, please submit them to the project's issue tracker.

## License

This wrapper is distributed under the MIT license. See the `LICENSE` file for more information.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vertyco/upchatpy",
    "name": "upchatpy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "Upgrade.Chat, chat, bot, discord, upgradechat, donations, subscriptions, monetization, payment, api, wrapper, client",
    "author": "vertyco",
    "author_email": "alex.c.goble@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2b/10/06f721d61a452b81b7c3c63b16cd1441ad43a68b6c75d4c79a86fb274fd1/upchatpy-1.1.0.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\r\n  <img src=\"https://repository-images.githubusercontent.com/719405304/08bd8dbc-7215-42d7-8bf8-361cc84af957\" width=\"40%\" />\r\n</p>\r\n\r\n# UpChatPy: Upgrade.Chat Python Wrapper\r\n\r\nThis package provides a fully async, type-complete wraper for the **[Upgrade.Chat](https://upgrade.chat/developers/documentation)** API.\r\n\r\n[![PyPi](https://img.shields.io/pypi/v/upchatpy)](https://pypi.org/project/upchatpy/)\r\n[![Downloads](https://img.shields.io/pypi/dm/upchatpy)](https://pypi.org/project/upchatpy/)\r\n![GitHub License](https://img.shields.io/github/license/vertyco/upchatpy)\r\n\r\n[![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-3913/)\r\n[![Python 3.10](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-31011/)\r\n[![Python 3.11](https://img.shields.io/badge/python-3.11-blue.svg)](https://www.python.org/downloads/release/python-3116/)\r\n[![Python 3.12](https://img.shields.io/badge/python-3.12-blue.svg)](https://www.python.org/downloads/release/python-3125/)\r\n\r\n#### Pydantic Cross Compatibility\r\n\r\n[![Pydantic v1](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v1.json)](https://docs.pydantic.dev/1.10/contributing/#badges)\r\n[![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://docs.pydantic.dev/latest/contributing/#badges)\r\n\r\n#### References\r\n\r\nUpgrade.Chat is a platform that facilitates monetization for community services, particularly Discord. This wrapper aims to simplify integration with other 3rd party apps.\r\n\r\n- [Homepage](https://upgrade.chat/)\r\n- [FAQ](https://docs.upgrade.chat/)\r\n- [API Docs](https://upgrade.chat/developers/documentation)\r\n\r\n## Installation\r\n\r\nTo install the package, run the following command:\r\n\r\n```bash\r\npip install upchatpy\r\n```\r\n\r\n## Usage\r\n\r\nBefore you can start using the API, you need to obtain your client ID and client secret from Upgrade.Chat. Once you have them, you can begin by creating a `Client` instance:\r\n\r\n```python\r\nfrom upchatpy import Client\r\n\r\nclient_id = 'your_client_id'\r\nclient_secret = 'your_client_secret'\r\n\r\nclient = Client(client_id, client_secret)\r\n```\r\n\r\n### Authentication\r\n\r\nThe wrapper handles authentication automatically when making API calls. However, you can manually authenticate and retrieve the access token as follows:\r\n\r\n```python\r\nauth = await client.get_auth()\r\nprint(auth.access_token)  # Access token is now available\r\nor\r\nprint(client.auth.access_token)  # Access token also available via client instance\r\n```\r\n\r\n### Fetching Orders\r\n\r\nTo fetch orders, use the following method:\r\n\r\n```python\r\norders_response = await client.get_orders()\r\nfor order in orders_response.data:\r\n    print(order.uuid, order.total)\r\n```\r\n\r\nTo fetch all orders with pagination support:\r\n\r\n```python\r\nasync for orders_response in client.aget_orders():\r\n    for order in orders_response.data:\r\n        print(order.uuid, order.total)\r\n```\r\n\r\nTo fetch a specific order by UUID:\r\n\r\n```python\r\norder_uuid = 'your_order_uuid'\r\norder_response = await client.get_order(order_uuid)\r\nprint(order_response.data.total)\r\n```\r\n\r\n### Fetching Products\r\n\r\nFetch a list of products using:\r\n\r\n```python\r\nproducts_response = await client.get_products()\r\nfor product in products_response.data:\r\n    print(product.uuid, product.name)\r\n```\r\n\r\nTo fetch all products with pagination support:\r\n\r\n```python\r\nasync for products_response in client.aget_products():\r\n    for product in products_response.data:\r\n        print(product.uuid, product.name)\r\n```\r\n\r\nTo fetch a product order by UUID:\r\n\r\n```python\r\nproduct_uuid = 'your_product_uuid'\r\nproduct_response = await client.get_product(product_uuid)\r\nprint(product_response.data.name)\r\n```\r\n\r\n### Fetching Users\r\n\r\nTo get a list of users, you can do:\r\n\r\n```python\r\nusers_response = await client.get_users()\r\nfor user in users_response.data:\r\n    print(user.discord_id, user.username)\r\n```\r\n\r\n### Fetching Webhooks\r\n\r\nFetch a list of webhooks using:\r\n\r\n```python\r\nwebhooks_response = await client.get_webhooks()\r\nfor webhook in webhooks_response.data:\r\n    print(webhook.id, webhook.uri)\r\n```\r\n\r\nTo fetch all webhooks with pagination support:\r\n\r\n```python\r\nasync for webhooks_response in client.aget_webhooks():\r\n    for webhook in webhooks_response.data:\r\n        print(webhook.id, webhook.url)\r\n```\r\n\r\nTo fetch a specific webhook by ID:\r\n\r\n```python\r\nwebhook_id = 'your_webhook_id'\r\nwebhook_response = await client.get_webhook(webhook_id)\r\nprint(webhook_response.data.id, webhook_response.data.url)\r\n```\r\n\r\n### Fetching Webhook Events\r\n\r\nFetch a list of webhooks events using:\r\n\r\n```python\r\nwebhook_events_response = await client.get_webhook_events()\r\nfor webhook_event in webhook_events_response.data:\r\n    print(webhook_event.id, webhook_event.webhook_id)\r\n```\r\n\r\nTo fetch a list of webhook events with pagination support:\r\n\r\n```python\r\nasync for webhook_events_response in client.aget_webhook_events():\r\n    for webhook_event in webhook_events_response.data:\r\n        print(webhook_event.id, webhook_event.webhook_id)\r\n```\r\n\r\nTo fetch a specific webhook event by ID:\r\n\r\n```python\r\nevent_id = 'your_event_id'\r\nwebhook_event_response = await client.get_webhook_event(event_id)\r\nprint(webhook_event_response.data.id)\r\n```\r\n\r\n### Validating Webhook Events\r\n\r\nTo validate a webhook event by ID:\r\n\r\n```python\r\nevent_id = 'your_event_id'\r\nwebhook_valid_response = await client.validate_webhook_event(event_id)\r\nprint(webhook_valid_response.data.is_valid)\r\n```\r\n\r\n### Checking Subscriptions\r\n\r\nThe `user_is_subscribed` method enables you to check if a user is currently subscribed to a specific product. This can be useful for verifying user access to features or content based on their subscription status.\r\n\r\n```python\r\n# Replace the following with the actual product UUID and user Discord ID\r\nproduct_uuid = \"c1eaaee5-9620-4343-b9da-test123\"\r\nuser_discord_id = \"12312312312312312\"\r\n\r\nis_subscribed = await client.user_is_subscribed(product_id, user_discord_id)\r\nprint(is_subscribed)\r\n>> True or False\r\n```\r\n\r\n## Exception Handling\r\n\r\nThe Upgrade.Chat Python Wrapper provides custom exceptions to help you handle potential errors that may occur during API interaction.\r\n\r\n### Custom Exceptions\r\n\r\n- `AuthenticationError`: Raised when there is a problem with client authentication, such as incorrect client ID or client secret.\r\n- `HTTPError`: Raised for general HTTP-related errors when making API requests.\r\n- `ResourceNotFoundError`: Raised when a requested resource is not found on the Upgrade.Chat API.\r\n\r\n### Example Usage\r\n\r\n```python\r\nfrom upchatpy import Client\r\nfrom upchatpy.exceptions import AuthenticationError, HTTPError, ResourceNotFoundError\r\n\r\nclient_id = 'your_client_id'\r\nclient_secret = 'your_client_secret'\r\nclient = Client(client_id, client_secret)\r\n\r\nasync def main():\r\n    try:\r\n        orders_response = await client.get_orders()\r\n        for order in orders_response.data:\r\n            print(order.uuid, order.total)\r\n    except AuthenticationError as e:\r\n        print(f\"Authentication failed with status code {e.status_code}: {e.message}\")\r\n    except ResourceNotFoundError as e:\r\n        print(f\"Resource not found with status code {e.status_code}: {e.message}\")\r\n    except HTTPError as e:\r\n        print(f\"HTTP error with status code {e.status_code}: {e.message}\")\r\n    except Exception as e:\r\n        print(f\"An unexpected error occurred: {e}\")\r\n```\r\n\r\n## Development\r\n\r\nThis package is under active development, and contributions are welcome! If you encounter any issues or have feature requests, please submit them to the project's issue tracker.\r\n\r\n## License\r\n\r\nThis wrapper is distributed under the MIT license. See the `LICENSE` file for more information.\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A type hinted async Python wrapper for the Upgrade.Chat API",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/vertyco/upchatpy"
    },
    "split_keywords": [
        "upgrade.chat",
        " chat",
        " bot",
        " discord",
        " upgradechat",
        " donations",
        " subscriptions",
        " monetization",
        " payment",
        " api",
        " wrapper",
        " client"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b1006f721d61a452b81b7c3c63b16cd1441ad43a68b6c75d4c79a86fb274fd1",
                "md5": "4f710f104bbd0da84e3b5445354a5df5",
                "sha256": "b6c5d5382f3a0b7d2a2f070e69849865c27600c1a73361b3f7abbf12bb9462ca"
            },
            "downloads": -1,
            "filename": "upchatpy-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4f710f104bbd0da84e3b5445354a5df5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 17074,
            "upload_time": "2024-08-18T17:02:32",
            "upload_time_iso_8601": "2024-08-18T17:02:32.789958Z",
            "url": "https://files.pythonhosted.org/packages/2b/10/06f721d61a452b81b7c3c63b16cd1441ad43a68b6c75d4c79a86fb274fd1/upchatpy-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-18 17:02:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vertyco",
    "github_project": "upchatpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "upchatpy"
}
        
Elapsed time: 0.38554s