# novu-py
Developer-friendly & type-safe Python SDK specifically catered to leverage *novu-py* API.
<div align="left">
<a href="https://www.speakeasy.com/?utm_source=novu-py&utm_campaign=python"><img src="https://custom-icon-badges.demolab.com/badge/-Built%20By%20Speakeasy-212015?style=for-the-badge&logoColor=FBE331&logo=speakeasy&labelColor=545454" /></a>
<a href="https://opensource.org/licenses/MIT">
<img src="https://img.shields.io/badge/License-MIT-blue.svg" style="width: 100px; height: 28px;" />
</a>
</div>
<br /><br />
<!-- Start Summary [summary] -->
## Summary
Novu API: Novu REST API. Please see https://docs.novu.co/api-reference for more details.
For more information about the API: [Novu Documentation](https://docs.novu.co)
<!-- End Summary [summary] -->
<!-- Start Table of Contents [toc] -->
## Table of Contents
<!-- $toc-max-depth=2 -->
* [novu-py](https://github.com/novuhq/novu-py/blob/master/#novu-py)
* [SDK Installation](https://github.com/novuhq/novu-py/blob/master/#sdk-installation)
* [IDE Support](https://github.com/novuhq/novu-py/blob/master/#ide-support)
* [SDK Example Usage](https://github.com/novuhq/novu-py/blob/master/#sdk-example-usage)
* [Available Resources and Operations](https://github.com/novuhq/novu-py/blob/master/#available-resources-and-operations)
* [Pagination](https://github.com/novuhq/novu-py/blob/master/#pagination)
* [Retries](https://github.com/novuhq/novu-py/blob/master/#retries)
* [Error Handling](https://github.com/novuhq/novu-py/blob/master/#error-handling)
* [Server Selection](https://github.com/novuhq/novu-py/blob/master/#server-selection)
* [Custom HTTP Client](https://github.com/novuhq/novu-py/blob/master/#custom-http-client)
* [Authentication](https://github.com/novuhq/novu-py/blob/master/#authentication)
* [Resource Management](https://github.com/novuhq/novu-py/blob/master/#resource-management)
* [Debugging](https://github.com/novuhq/novu-py/blob/master/#debugging)
* [Development](https://github.com/novuhq/novu-py/blob/master/#development)
* [Maturity](https://github.com/novuhq/novu-py/blob/master/#maturity)
* [Contributions](https://github.com/novuhq/novu-py/blob/master/#contributions)
<!-- End Table of Contents [toc] -->
<!-- Start SDK Installation [installation] -->
## SDK Installation
> [!NOTE]
> **Python version upgrade policy**
>
> Once a Python version reaches its [official end of life date](https://devguide.python.org/versions/), a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.
The SDK can be installed with either *pip* or *poetry* package managers.
### PIP
*PIP* is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.
```bash
pip install novu-py
```
### Poetry
*Poetry* is a modern tool that simplifies dependency management and package publishing by using a single `pyproject.toml` file to handle project metadata and dependencies.
```bash
poetry add novu-py
```
### Shell and script usage with `uv`
You can use this SDK in a Python shell with [uv](https://docs.astral.sh/uv/) and the `uvx` command that comes with it like so:
```shell
uvx --from novu-py python
```
It's also possible to write a standalone Python script without needing to set up a whole project like so:
```python
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "novu-py",
# ]
# ///
from novu_py import Novu
sdk = Novu(
# SDK arguments
)
# Rest of script here...
```
Once that is saved to a file, you can run it with `uv run script.py` where
`script.py` can be replaced with the actual file name.
<!-- End SDK Installation [installation] -->
<!-- Start IDE Support [idesupport] -->
## IDE Support
### PyCharm
Generally, the SDK will work well with most IDEs out of the box. However, when using PyCharm, you can enjoy much better integration with Pydantic by installing an additional plugin.
- [PyCharm Pydantic Plugin](https://docs.pydantic.dev/latest/integrations/pycharm/)
<!-- End IDE Support [idesupport] -->
<!-- Start SDK Example Usage [usage] -->
## SDK Example Usage
### Trigger Notification Event
```python
# Synchronous Example
import novu_py
from novu_py import Novu
import os
with Novu(
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = novu.trigger(trigger_event_request_dto=novu_py.TriggerEventRequestDto(
workflow_id="workflow_identifier",
to={
"subscriber_id": "<id>",
},
payload={
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides={
"fcm": {
"data": {
"key": "value",
},
},
},
))
# Handle response
print(res)
```
</br>
The same SDK client can also be used to make asychronous requests by importing asyncio.
```python
# Asynchronous Example
import asyncio
import novu_py
from novu_py import Novu
import os
async def main():
async with Novu(
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = await novu.trigger_async(trigger_event_request_dto=novu_py.TriggerEventRequestDto(
workflow_id="workflow_identifier",
to={
"subscriber_id": "<id>",
},
payload={
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides={
"fcm": {
"data": {
"key": "value",
},
},
},
))
# Handle response
print(res)
asyncio.run(main())
```
### Trigger Notification Events in Bulk
```python
# Synchronous Example
import novu_py
from novu_py import Novu
import os
with Novu(
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = novu.trigger_bulk(bulk_trigger_event_dto={
"events": [
novu_py.TriggerEventRequestDto(
workflow_id="workflow_identifier",
to={
"subscriber_id": "<id>",
},
payload={
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides={
"fcm": {
"data": {
"key": "value",
},
},
},
),
novu_py.TriggerEventRequestDto(
workflow_id="workflow_identifier",
to=[
{
"topic_key": "<value>",
"type": novu_py.TriggerRecipientsTypeEnum.SUBSCRIBER,
},
],
payload={
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides={
"fcm": {
"data": {
"key": "value",
},
},
},
),
novu_py.TriggerEventRequestDto(
workflow_id="workflow_identifier",
to=[
"SUBSCRIBER_ID",
"SUBSCRIBER_ID",
],
payload={
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides={
"fcm": {
"data": {
"key": "value",
},
},
},
),
],
})
# Handle response
print(res)
```
</br>
The same SDK client can also be used to make asychronous requests by importing asyncio.
```python
# Asynchronous Example
import asyncio
import novu_py
from novu_py import Novu
import os
async def main():
async with Novu(
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = await novu.trigger_bulk_async(bulk_trigger_event_dto={
"events": [
novu_py.TriggerEventRequestDto(
workflow_id="workflow_identifier",
to={
"subscriber_id": "<id>",
},
payload={
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides={
"fcm": {
"data": {
"key": "value",
},
},
},
),
novu_py.TriggerEventRequestDto(
workflow_id="workflow_identifier",
to=[
{
"topic_key": "<value>",
"type": novu_py.TriggerRecipientsTypeEnum.SUBSCRIBER,
},
],
payload={
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides={
"fcm": {
"data": {
"key": "value",
},
},
},
),
novu_py.TriggerEventRequestDto(
workflow_id="workflow_identifier",
to=[
"SUBSCRIBER_ID",
"SUBSCRIBER_ID",
],
payload={
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides={
"fcm": {
"data": {
"key": "value",
},
},
},
),
],
})
# Handle response
print(res)
asyncio.run(main())
```
### Broadcast Event to All
```python
# Synchronous Example
from novu_py import Novu
import os
with Novu(
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = novu.trigger_broadcast(trigger_event_to_all_request_dto={
"name": "<value>",
"payload": {
"comment_id": "string",
"post": {
"text": "string",
},
},
})
# Handle response
print(res)
```
</br>
The same SDK client can also be used to make asychronous requests by importing asyncio.
```python
# Asynchronous Example
import asyncio
from novu_py import Novu
import os
async def main():
async with Novu(
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = await novu.trigger_broadcast_async(trigger_event_to_all_request_dto={
"name": "<value>",
"payload": {
"comment_id": "string",
"post": {
"text": "string",
},
},
})
# Handle response
print(res)
asyncio.run(main())
```
### Cancel Triggered Event
```python
# Synchronous Example
from novu_py import Novu
import os
with Novu(
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = novu.cancel(transaction_id="<id>")
# Handle response
print(res)
```
</br>
The same SDK client can also be used to make asychronous requests by importing asyncio.
```python
# Asynchronous Example
import asyncio
from novu_py import Novu
import os
async def main():
async with Novu(
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = await novu.cancel_async(transaction_id="<id>")
# Handle response
print(res)
asyncio.run(main())
```
<!-- End SDK Example Usage [usage] -->
<!-- Start Available Resources and Operations [operations] -->
## Available Resources and Operations
<details open>
<summary>Available methods</summary>
### [integrations](https://github.com/novuhq/novu-py/blob/master/docs/sdks/integrations/README.md)
* [list](https://github.com/novuhq/novu-py/blob/master/docs/sdks/integrations/README.md#list) - Get integrations
* [create](https://github.com/novuhq/novu-py/blob/master/docs/sdks/integrations/README.md#create) - Create integration
* [list_active](https://github.com/novuhq/novu-py/blob/master/docs/sdks/integrations/README.md#list_active) - Get active integrations
* [update](https://github.com/novuhq/novu-py/blob/master/docs/sdks/integrations/README.md#update) - Update integration
* [delete](https://github.com/novuhq/novu-py/blob/master/docs/sdks/integrations/README.md#delete) - Delete integration
* [set_as_primary](https://github.com/novuhq/novu-py/blob/master/docs/sdks/integrations/README.md#set_as_primary) - Set integration as primary
#### [integrations.webhooks](https://github.com/novuhq/novu-py/blob/master/docs/sdks/webhooks/README.md)
* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/webhooks/README.md#retrieve) - Get webhook support status for provider
### [messages](https://github.com/novuhq/novu-py/blob/master/docs/sdks/messages/README.md)
* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/messages/README.md#retrieve) - Get messages
* [delete](https://github.com/novuhq/novu-py/blob/master/docs/sdks/messages/README.md#delete) - Delete message
* [delete_by_transaction_id](https://github.com/novuhq/novu-py/blob/master/docs/sdks/messages/README.md#delete_by_transaction_id) - Delete messages by transactionId
### [notifications](https://github.com/novuhq/novu-py/blob/master/docs/sdks/notifications/README.md)
* [list](https://github.com/novuhq/novu-py/blob/master/docs/sdks/notifications/README.md#list) - Get notifications
* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/notifications/README.md#retrieve) - Get notification
#### [notifications.stats](https://github.com/novuhq/novu-py/blob/master/docs/sdks/stats/README.md)
* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/stats/README.md#retrieve) - Get notification statistics
* [graph](https://github.com/novuhq/novu-py/blob/master/docs/sdks/stats/README.md#graph) - Get notification graph statistics
### [Novu SDK](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novu/README.md)
* [trigger](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novu/README.md#trigger) - Trigger event
* [trigger_bulk](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novu/README.md#trigger_bulk) - Bulk trigger event
* [trigger_broadcast](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novu/README.md#trigger_broadcast) - Broadcast event to all
* [cancel](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novu/README.md#cancel) - Cancel triggered event
### [subscribers](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md)
* [list](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#list) - Get subscribers
* [create](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#create) - Create subscriber
* [retrieve_legacy](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#retrieve_legacy) - Get subscriber
* [update](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#update) - Update subscriber
* [~~delete_legacy~~](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#delete_legacy) - Delete subscriber :warning: **Deprecated**
* [create_bulk](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#create_bulk) - Bulk create subscribers
* [search](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#search) - Search for subscribers
* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#retrieve) - Get subscriber
* [patch](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#patch) - Patch subscriber
* [delete](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#delete) - Delete subscriber
#### [subscribers.authentication](https://github.com/novuhq/novu-py/blob/master/docs/sdks/authentication/README.md)
* [chat_access_oauth_call_back](https://github.com/novuhq/novu-py/blob/master/docs/sdks/authentication/README.md#chat_access_oauth_call_back) - Handle providers oauth redirect
* [chat_access_oauth](https://github.com/novuhq/novu-py/blob/master/docs/sdks/authentication/README.md#chat_access_oauth) - Handle chat oauth
#### [subscribers.credentials](https://github.com/novuhq/novu-py/blob/master/docs/sdks/credentials/README.md)
* [update](https://github.com/novuhq/novu-py/blob/master/docs/sdks/credentials/README.md#update) - Update subscriber credentials
* [append](https://github.com/novuhq/novu-py/blob/master/docs/sdks/credentials/README.md#append) - Modify subscriber credentials
* [delete](https://github.com/novuhq/novu-py/blob/master/docs/sdks/credentials/README.md#delete) - Delete subscriber credentials by providerId
#### [subscribers.messages](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novumessages/README.md)
* [mark_all_as](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novumessages/README.md#mark_all_as) - Mark a subscriber messages as seen, read, unseen or unread
* [mark_all](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novumessages/README.md#mark_all) - Marks all the subscriber messages as read, unread, seen or unseen. Optionally you can pass feed id (or array) to mark messages of a particular feed.
* [update_as_seen](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novumessages/README.md#update_as_seen) - Mark message action as seen
#### [subscribers.notifications](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novunotifications/README.md)
* [feed](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novunotifications/README.md#feed) - Get in-app notification feed for a particular subscriber
* [unseen_count](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novunotifications/README.md#unseen_count) - Get the unseen in-app notifications count for subscribers feed
#### [subscribers.preferences](https://github.com/novuhq/novu-py/blob/master/docs/sdks/preferences/README.md)
* [list](https://github.com/novuhq/novu-py/blob/master/docs/sdks/preferences/README.md#list) - Get subscriber preferences
* [update_global](https://github.com/novuhq/novu-py/blob/master/docs/sdks/preferences/README.md#update_global) - Update subscriber global preferences
* [retrieve_by_level](https://github.com/novuhq/novu-py/blob/master/docs/sdks/preferences/README.md#retrieve_by_level) - Get subscriber preferences by level
* [update_legacy](https://github.com/novuhq/novu-py/blob/master/docs/sdks/preferences/README.md#update_legacy) - Update subscriber preference
* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/preferences/README.md#retrieve) - Get subscriber preferences
* [update](https://github.com/novuhq/novu-py/blob/master/docs/sdks/preferences/README.md#update) - Update subscriber global or workflow specific preferences
#### [subscribers.properties](https://github.com/novuhq/novu-py/blob/master/docs/sdks/properties/README.md)
* [update_online_flag](https://github.com/novuhq/novu-py/blob/master/docs/sdks/properties/README.md#update_online_flag) - Update subscriber online status
### [topics](https://github.com/novuhq/novu-py/blob/master/docs/sdks/topics/README.md)
* [create](https://github.com/novuhq/novu-py/blob/master/docs/sdks/topics/README.md#create) - Topic creation
* [list](https://github.com/novuhq/novu-py/blob/master/docs/sdks/topics/README.md#list) - Get topic list filtered
* [delete](https://github.com/novuhq/novu-py/blob/master/docs/sdks/topics/README.md#delete) - Delete topic
* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/topics/README.md#retrieve) - Get topic
* [rename](https://github.com/novuhq/novu-py/blob/master/docs/sdks/topics/README.md#rename) - Rename a topic
#### [topics.subscribers](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novusubscribers/README.md)
* [assign](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novusubscribers/README.md#assign) - Subscribers addition
* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novusubscribers/README.md#retrieve) - Check topic subscriber
* [remove](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novusubscribers/README.md#remove) - Subscribers removal
</details>
<!-- End Available Resources and Operations [operations] -->
<!-- Start Pagination [pagination] -->
## Pagination
Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the
returned response object will have a `Next` method that can be called to pull down the next group of results. If the
return value of `Next` is `None`, then there are no more pages to be fetched.
Here's an example of one such pagination call:
```python
from novu_py import Novu
import os
with Novu(
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = novu.subscribers.list()
while res is not None:
# Handle items
res = res.next()
```
<!-- End Pagination [pagination] -->
<!-- Start Retries [retries] -->
## Retries
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a `RetryConfig` object to the call:
```python
import novu_py
from novu_py import Novu
from novu_py.utils import BackoffStrategy, RetryConfig
import os
with Novu(
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = novu.trigger(trigger_event_request_dto=novu_py.TriggerEventRequestDto(
workflow_id="workflow_identifier",
to={
"subscriber_id": "<id>",
},
payload={
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides={
"fcm": {
"data": {
"key": "value",
},
},
},
),
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
# Handle response
print(res)
```
If you'd like to override the default retry strategy for all operations that support retries, you can use the `retry_config` optional parameter when initializing the SDK:
```python
import novu_py
from novu_py import Novu
from novu_py.utils import BackoffStrategy, RetryConfig
import os
with Novu(
retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False),
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = novu.trigger(trigger_event_request_dto=novu_py.TriggerEventRequestDto(
workflow_id="workflow_identifier",
to={
"subscriber_id": "<id>",
},
payload={
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides={
"fcm": {
"data": {
"key": "value",
},
},
},
))
# Handle response
print(res)
```
<!-- End Retries [retries] -->
<!-- Start Error Handling [errors] -->
## Error Handling
Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception.
By default, an API error will raise a models.APIError exception, which has the following properties:
| Property | Type | Description |
|-----------------|------------------|-----------------------|
| `.status_code` | *int* | The HTTP status code |
| `.message` | *str* | The error message |
| `.raw_response` | *httpx.Response* | The raw HTTP response |
| `.body` | *str* | The response content |
When custom error responses are specified for an operation, the SDK may also raise their associated exceptions. You can refer to respective *Errors* tables in SDK docs for more details on possible exception types for each operation. For example, the `trigger_async` method may raise the following exceptions:
| Error Type | Status Code | Content Type |
| ------------------------- | -------------------------------------- | ---------------- |
| models.ErrorDto | 414 | application/json |
| models.ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| models.ValidationErrorDto | 422 | application/json |
| models.ErrorDto | 500 | application/json |
| models.APIError | 4XX, 5XX | \*/\* |
### Example
```python
import novu_py
from novu_py import Novu, models
import os
with Novu(
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = None
try:
res = novu.trigger(trigger_event_request_dto=novu_py.TriggerEventRequestDto(
workflow_id="workflow_identifier",
to={
"subscriber_id": "<id>",
},
payload={
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides={
"fcm": {
"data": {
"key": "value",
},
},
},
))
# Handle response
print(res)
except models.ErrorDto as e:
# handle e.data: models.ErrorDtoData
raise(e)
except models.ErrorDto as e:
# handle e.data: models.ErrorDtoData
raise(e)
except models.ValidationErrorDto as e:
# handle e.data: models.ValidationErrorDtoData
raise(e)
except models.ErrorDto as e:
# handle e.data: models.ErrorDtoData
raise(e)
except models.APIError as e:
# handle exception
raise(e)
```
<!-- End Error Handling [errors] -->
<!-- Start Server Selection [server] -->
## Server Selection
### Select Server by Index
You can override the default server globally by passing a server index to the `server_idx: int` optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
| # | Server |
| --- | ------------------------ |
| 0 | `https://api.novu.co` |
| 1 | `https://eu.api.novu.co` |
#### Example
```python
import novu_py
from novu_py import Novu
import os
with Novu(
server_idx=1,
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = novu.trigger(trigger_event_request_dto=novu_py.TriggerEventRequestDto(
workflow_id="workflow_identifier",
to={
"subscriber_id": "<id>",
},
payload={
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides={
"fcm": {
"data": {
"key": "value",
},
},
},
))
# Handle response
print(res)
```
### Override Server URL Per-Client
The default server can also be overridden globally by passing a URL to the `server_url: str` optional parameter when initializing the SDK client instance. For example:
```python
import novu_py
from novu_py import Novu
import os
with Novu(
server_url="https://api.novu.co",
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = novu.trigger(trigger_event_request_dto=novu_py.TriggerEventRequestDto(
workflow_id="workflow_identifier",
to={
"subscriber_id": "<id>",
},
payload={
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides={
"fcm": {
"data": {
"key": "value",
},
},
},
))
# Handle response
print(res)
```
<!-- End Server Selection [server] -->
<!-- Start Custom HTTP Client [http-client] -->
## Custom HTTP Client
The Python SDK makes API calls using the [httpx](https://www.python-httpx.org/) HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with your own HTTP client instance.
Depending on whether you are using the sync or async version of the SDK, you can pass an instance of `HttpClient` or `AsyncHttpClient` respectively, which are Protocol's ensuring that the client has the necessary methods to make API calls.
This allows you to wrap the client with your own custom logic, such as adding custom headers, logging, or error handling, or you can just pass an instance of `httpx.Client` or `httpx.AsyncClient` directly.
For example, you could specify a header for every request that this sdk makes as follows:
```python
from novu_py import Novu
import httpx
http_client = httpx.Client(headers={"x-custom-header": "someValue"})
s = Novu(client=http_client)
```
or you could wrap the client with your own custom logic:
```python
from novu_py import Novu
from novu_py.httpclient import AsyncHttpClient
import httpx
class CustomClient(AsyncHttpClient):
client: AsyncHttpClient
def __init__(self, client: AsyncHttpClient):
self.client = client
async def send(
self,
request: httpx.Request,
*,
stream: bool = False,
auth: Union[
httpx._types.AuthTypes, httpx._client.UseClientDefault, None
] = httpx.USE_CLIENT_DEFAULT,
follow_redirects: Union[
bool, httpx._client.UseClientDefault
] = httpx.USE_CLIENT_DEFAULT,
) -> httpx.Response:
request.headers["Client-Level-Header"] = "added by client"
return await self.client.send(
request, stream=stream, auth=auth, follow_redirects=follow_redirects
)
def build_request(
self,
method: str,
url: httpx._types.URLTypes,
*,
content: Optional[httpx._types.RequestContent] = None,
data: Optional[httpx._types.RequestData] = None,
files: Optional[httpx._types.RequestFiles] = None,
json: Optional[Any] = None,
params: Optional[httpx._types.QueryParamTypes] = None,
headers: Optional[httpx._types.HeaderTypes] = None,
cookies: Optional[httpx._types.CookieTypes] = None,
timeout: Union[
httpx._types.TimeoutTypes, httpx._client.UseClientDefault
] = httpx.USE_CLIENT_DEFAULT,
extensions: Optional[httpx._types.RequestExtensions] = None,
) -> httpx.Request:
return self.client.build_request(
method,
url,
content=content,
data=data,
files=files,
json=json,
params=params,
headers=headers,
cookies=cookies,
timeout=timeout,
extensions=extensions,
)
s = Novu(async_client=CustomClient(httpx.AsyncClient()))
```
<!-- End Custom HTTP Client [http-client] -->
<!-- Start Authentication [security] -->
## Authentication
### Per-Client Security Schemes
This SDK supports the following security scheme globally:
| Name | Type | Scheme | Environment Variable |
| ------------ | ------ | ------- | -------------------- |
| `secret_key` | apiKey | API key | `NOVU_SECRET_KEY` |
To authenticate with the API the `secret_key` parameter must be set when initializing the SDK client instance. For example:
```python
import novu_py
from novu_py import Novu
import os
with Novu(
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
res = novu.trigger(trigger_event_request_dto=novu_py.TriggerEventRequestDto(
workflow_id="workflow_identifier",
to={
"subscriber_id": "<id>",
},
payload={
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides={
"fcm": {
"data": {
"key": "value",
},
},
},
))
# Handle response
print(res)
```
<!-- End Authentication [security] -->
<!-- Start Resource Management [resource-management] -->
## Resource Management
The `Novu` class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a [context manager][context-manager] and reuse it across the application.
[context-manager]: https://docs.python.org/3/reference/datamodel.html#context-managers
```python
from novu_py import Novu
import os
def main():
with Novu(
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
# Rest of application here...
# Or when using async:
async def amain():
async with Novu(
secret_key=os.getenv("NOVU_SECRET_KEY", ""),
) as novu:
# Rest of application here...
```
<!-- End Resource Management [resource-management] -->
<!-- Start Debugging [debug] -->
## Debugging
You can setup your SDK to emit debug logs for SDK requests and responses.
You can pass your own logger class directly into your SDK.
```python
from novu_py import Novu
import logging
logging.basicConfig(level=logging.DEBUG)
s = Novu(debug_logger=logging.getLogger("novu_py"))
```
You can also enable a default debug logger by setting an environment variable `NOVU_DEBUG` to true.
<!-- End Debugging [debug] -->
<!-- Placeholder for Future Speakeasy SDK Sections -->
# Development
## Maturity
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally
looking for the latest version.
## Contributions
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
### SDK Created by [Speakeasy](https://www.speakeasy.com/?utm_source=novu-py&utm_campaign=python)
Raw data
{
"_id": null,
"home_page": "https://github.com/novuhq/novu-py.git",
"name": "novu-py",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Speakeasy",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/6c/ea/8a62896b91e217d45f196f8e47133cf07a91c712a2d35752c39e6f72ff97/novu_py-0.3.3.tar.gz",
"platform": null,
"description": "# novu-py\n\nDeveloper-friendly & type-safe Python SDK specifically catered to leverage *novu-py* API.\n\n<div align=\"left\">\n <a href=\"https://www.speakeasy.com/?utm_source=novu-py&utm_campaign=python\"><img src=\"https://custom-icon-badges.demolab.com/badge/-Built%20By%20Speakeasy-212015?style=for-the-badge&logoColor=FBE331&logo=speakeasy&labelColor=545454\" /></a>\n <a href=\"https://opensource.org/licenses/MIT\">\n <img src=\"https://img.shields.io/badge/License-MIT-blue.svg\" style=\"width: 100px; height: 28px;\" />\n </a>\n</div>\n\n\n<br /><br />\n<!-- Start Summary [summary] -->\n## Summary\n\nNovu API: Novu REST API. Please see https://docs.novu.co/api-reference for more details.\n\nFor more information about the API: [Novu Documentation](https://docs.novu.co)\n<!-- End Summary [summary] -->\n\n<!-- Start Table of Contents [toc] -->\n## Table of Contents\n<!-- $toc-max-depth=2 -->\n* [novu-py](https://github.com/novuhq/novu-py/blob/master/#novu-py)\n * [SDK Installation](https://github.com/novuhq/novu-py/blob/master/#sdk-installation)\n * [IDE Support](https://github.com/novuhq/novu-py/blob/master/#ide-support)\n * [SDK Example Usage](https://github.com/novuhq/novu-py/blob/master/#sdk-example-usage)\n * [Available Resources and Operations](https://github.com/novuhq/novu-py/blob/master/#available-resources-and-operations)\n * [Pagination](https://github.com/novuhq/novu-py/blob/master/#pagination)\n * [Retries](https://github.com/novuhq/novu-py/blob/master/#retries)\n * [Error Handling](https://github.com/novuhq/novu-py/blob/master/#error-handling)\n * [Server Selection](https://github.com/novuhq/novu-py/blob/master/#server-selection)\n * [Custom HTTP Client](https://github.com/novuhq/novu-py/blob/master/#custom-http-client)\n * [Authentication](https://github.com/novuhq/novu-py/blob/master/#authentication)\n * [Resource Management](https://github.com/novuhq/novu-py/blob/master/#resource-management)\n * [Debugging](https://github.com/novuhq/novu-py/blob/master/#debugging)\n* [Development](https://github.com/novuhq/novu-py/blob/master/#development)\n * [Maturity](https://github.com/novuhq/novu-py/blob/master/#maturity)\n * [Contributions](https://github.com/novuhq/novu-py/blob/master/#contributions)\n\n<!-- End Table of Contents [toc] -->\n\n<!-- Start SDK Installation [installation] -->\n## SDK Installation\n\n> [!NOTE]\n> **Python version upgrade policy**\n>\n> Once a Python version reaches its [official end of life date](https://devguide.python.org/versions/), a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.\n\nThe SDK can be installed with either *pip* or *poetry* package managers.\n\n### PIP\n\n*PIP* is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.\n\n```bash\npip install novu-py\n```\n\n### Poetry\n\n*Poetry* is a modern tool that simplifies dependency management and package publishing by using a single `pyproject.toml` file to handle project metadata and dependencies.\n\n```bash\npoetry add novu-py\n```\n\n### Shell and script usage with `uv`\n\nYou can use this SDK in a Python shell with [uv](https://docs.astral.sh/uv/) and the `uvx` command that comes with it like so:\n\n```shell\nuvx --from novu-py python\n```\n\nIt's also possible to write a standalone Python script without needing to set up a whole project like so:\n\n```python\n#!/usr/bin/env -S uv run --script\n# /// script\n# requires-python = \">=3.9\"\n# dependencies = [\n# \"novu-py\",\n# ]\n# ///\n\nfrom novu_py import Novu\n\nsdk = Novu(\n # SDK arguments\n)\n\n# Rest of script here...\n```\n\nOnce that is saved to a file, you can run it with `uv run script.py` where\n`script.py` can be replaced with the actual file name.\n<!-- End SDK Installation [installation] -->\n\n<!-- Start IDE Support [idesupport] -->\n## IDE Support\n\n### PyCharm\n\nGenerally, the SDK will work well with most IDEs out of the box. However, when using PyCharm, you can enjoy much better integration with Pydantic by installing an additional plugin.\n\n- [PyCharm Pydantic Plugin](https://docs.pydantic.dev/latest/integrations/pycharm/)\n<!-- End IDE Support [idesupport] -->\n\n<!-- Start SDK Example Usage [usage] -->\n## SDK Example Usage\n\n### Trigger Notification Event\n\n```python\n# Synchronous Example\nimport novu_py\nfrom novu_py import Novu\nimport os\n\nwith Novu(\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n) as novu:\n\n res = novu.trigger(trigger_event_request_dto=novu_py.TriggerEventRequestDto(\n workflow_id=\"workflow_identifier\",\n to={\n \"subscriber_id\": \"<id>\",\n },\n payload={\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n overrides={\n \"fcm\": {\n \"data\": {\n \"key\": \"value\",\n },\n },\n },\n ))\n\n # Handle response\n print(res)\n```\n\n</br>\n\nThe same SDK client can also be used to make asychronous requests by importing asyncio.\n```python\n# Asynchronous Example\nimport asyncio\nimport novu_py\nfrom novu_py import Novu\nimport os\n\nasync def main():\n async with Novu(\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n ) as novu:\n\n res = await novu.trigger_async(trigger_event_request_dto=novu_py.TriggerEventRequestDto(\n workflow_id=\"workflow_identifier\",\n to={\n \"subscriber_id\": \"<id>\",\n },\n payload={\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n overrides={\n \"fcm\": {\n \"data\": {\n \"key\": \"value\",\n },\n },\n },\n ))\n\n # Handle response\n print(res)\n\nasyncio.run(main())\n```\n\n### Trigger Notification Events in Bulk\n\n```python\n# Synchronous Example\nimport novu_py\nfrom novu_py import Novu\nimport os\n\nwith Novu(\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n) as novu:\n\n res = novu.trigger_bulk(bulk_trigger_event_dto={\n \"events\": [\n novu_py.TriggerEventRequestDto(\n workflow_id=\"workflow_identifier\",\n to={\n \"subscriber_id\": \"<id>\",\n },\n payload={\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n overrides={\n \"fcm\": {\n \"data\": {\n \"key\": \"value\",\n },\n },\n },\n ),\n novu_py.TriggerEventRequestDto(\n workflow_id=\"workflow_identifier\",\n to=[\n {\n \"topic_key\": \"<value>\",\n \"type\": novu_py.TriggerRecipientsTypeEnum.SUBSCRIBER,\n },\n ],\n payload={\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n overrides={\n \"fcm\": {\n \"data\": {\n \"key\": \"value\",\n },\n },\n },\n ),\n novu_py.TriggerEventRequestDto(\n workflow_id=\"workflow_identifier\",\n to=[\n \"SUBSCRIBER_ID\",\n \"SUBSCRIBER_ID\",\n ],\n payload={\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n overrides={\n \"fcm\": {\n \"data\": {\n \"key\": \"value\",\n },\n },\n },\n ),\n ],\n })\n\n # Handle response\n print(res)\n```\n\n</br>\n\nThe same SDK client can also be used to make asychronous requests by importing asyncio.\n```python\n# Asynchronous Example\nimport asyncio\nimport novu_py\nfrom novu_py import Novu\nimport os\n\nasync def main():\n async with Novu(\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n ) as novu:\n\n res = await novu.trigger_bulk_async(bulk_trigger_event_dto={\n \"events\": [\n novu_py.TriggerEventRequestDto(\n workflow_id=\"workflow_identifier\",\n to={\n \"subscriber_id\": \"<id>\",\n },\n payload={\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n overrides={\n \"fcm\": {\n \"data\": {\n \"key\": \"value\",\n },\n },\n },\n ),\n novu_py.TriggerEventRequestDto(\n workflow_id=\"workflow_identifier\",\n to=[\n {\n \"topic_key\": \"<value>\",\n \"type\": novu_py.TriggerRecipientsTypeEnum.SUBSCRIBER,\n },\n ],\n payload={\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n overrides={\n \"fcm\": {\n \"data\": {\n \"key\": \"value\",\n },\n },\n },\n ),\n novu_py.TriggerEventRequestDto(\n workflow_id=\"workflow_identifier\",\n to=[\n \"SUBSCRIBER_ID\",\n \"SUBSCRIBER_ID\",\n ],\n payload={\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n overrides={\n \"fcm\": {\n \"data\": {\n \"key\": \"value\",\n },\n },\n },\n ),\n ],\n })\n\n # Handle response\n print(res)\n\nasyncio.run(main())\n```\n\n### Broadcast Event to All\n\n```python\n# Synchronous Example\nfrom novu_py import Novu\nimport os\n\nwith Novu(\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n) as novu:\n\n res = novu.trigger_broadcast(trigger_event_to_all_request_dto={\n \"name\": \"<value>\",\n \"payload\": {\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n })\n\n # Handle response\n print(res)\n```\n\n</br>\n\nThe same SDK client can also be used to make asychronous requests by importing asyncio.\n```python\n# Asynchronous Example\nimport asyncio\nfrom novu_py import Novu\nimport os\n\nasync def main():\n async with Novu(\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n ) as novu:\n\n res = await novu.trigger_broadcast_async(trigger_event_to_all_request_dto={\n \"name\": \"<value>\",\n \"payload\": {\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n })\n\n # Handle response\n print(res)\n\nasyncio.run(main())\n```\n\n### Cancel Triggered Event\n\n```python\n# Synchronous Example\nfrom novu_py import Novu\nimport os\n\nwith Novu(\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n) as novu:\n\n res = novu.cancel(transaction_id=\"<id>\")\n\n # Handle response\n print(res)\n```\n\n</br>\n\nThe same SDK client can also be used to make asychronous requests by importing asyncio.\n```python\n# Asynchronous Example\nimport asyncio\nfrom novu_py import Novu\nimport os\n\nasync def main():\n async with Novu(\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n ) as novu:\n\n res = await novu.cancel_async(transaction_id=\"<id>\")\n\n # Handle response\n print(res)\n\nasyncio.run(main())\n```\n<!-- End SDK Example Usage [usage] -->\n\n<!-- Start Available Resources and Operations [operations] -->\n## Available Resources and Operations\n\n<details open>\n<summary>Available methods</summary>\n\n### [integrations](https://github.com/novuhq/novu-py/blob/master/docs/sdks/integrations/README.md)\n\n* [list](https://github.com/novuhq/novu-py/blob/master/docs/sdks/integrations/README.md#list) - Get integrations\n* [create](https://github.com/novuhq/novu-py/blob/master/docs/sdks/integrations/README.md#create) - Create integration\n* [list_active](https://github.com/novuhq/novu-py/blob/master/docs/sdks/integrations/README.md#list_active) - Get active integrations\n* [update](https://github.com/novuhq/novu-py/blob/master/docs/sdks/integrations/README.md#update) - Update integration\n* [delete](https://github.com/novuhq/novu-py/blob/master/docs/sdks/integrations/README.md#delete) - Delete integration\n* [set_as_primary](https://github.com/novuhq/novu-py/blob/master/docs/sdks/integrations/README.md#set_as_primary) - Set integration as primary\n\n#### [integrations.webhooks](https://github.com/novuhq/novu-py/blob/master/docs/sdks/webhooks/README.md)\n\n* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/webhooks/README.md#retrieve) - Get webhook support status for provider\n\n### [messages](https://github.com/novuhq/novu-py/blob/master/docs/sdks/messages/README.md)\n\n* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/messages/README.md#retrieve) - Get messages\n* [delete](https://github.com/novuhq/novu-py/blob/master/docs/sdks/messages/README.md#delete) - Delete message\n* [delete_by_transaction_id](https://github.com/novuhq/novu-py/blob/master/docs/sdks/messages/README.md#delete_by_transaction_id) - Delete messages by transactionId\n\n### [notifications](https://github.com/novuhq/novu-py/blob/master/docs/sdks/notifications/README.md)\n\n* [list](https://github.com/novuhq/novu-py/blob/master/docs/sdks/notifications/README.md#list) - Get notifications\n* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/notifications/README.md#retrieve) - Get notification\n\n#### [notifications.stats](https://github.com/novuhq/novu-py/blob/master/docs/sdks/stats/README.md)\n\n* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/stats/README.md#retrieve) - Get notification statistics\n* [graph](https://github.com/novuhq/novu-py/blob/master/docs/sdks/stats/README.md#graph) - Get notification graph statistics\n\n### [Novu SDK](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novu/README.md)\n\n* [trigger](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novu/README.md#trigger) - Trigger event\n* [trigger_bulk](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novu/README.md#trigger_bulk) - Bulk trigger event\n* [trigger_broadcast](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novu/README.md#trigger_broadcast) - Broadcast event to all\n* [cancel](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novu/README.md#cancel) - Cancel triggered event\n\n### [subscribers](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md)\n\n* [list](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#list) - Get subscribers\n* [create](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#create) - Create subscriber\n* [retrieve_legacy](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#retrieve_legacy) - Get subscriber\n* [update](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#update) - Update subscriber\n* [~~delete_legacy~~](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#delete_legacy) - Delete subscriber :warning: **Deprecated**\n* [create_bulk](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#create_bulk) - Bulk create subscribers\n* [search](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#search) - Search for subscribers\n* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#retrieve) - Get subscriber\n* [patch](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#patch) - Patch subscriber\n* [delete](https://github.com/novuhq/novu-py/blob/master/docs/sdks/subscribers/README.md#delete) - Delete subscriber\n\n#### [subscribers.authentication](https://github.com/novuhq/novu-py/blob/master/docs/sdks/authentication/README.md)\n\n* [chat_access_oauth_call_back](https://github.com/novuhq/novu-py/blob/master/docs/sdks/authentication/README.md#chat_access_oauth_call_back) - Handle providers oauth redirect\n* [chat_access_oauth](https://github.com/novuhq/novu-py/blob/master/docs/sdks/authentication/README.md#chat_access_oauth) - Handle chat oauth\n\n#### [subscribers.credentials](https://github.com/novuhq/novu-py/blob/master/docs/sdks/credentials/README.md)\n\n* [update](https://github.com/novuhq/novu-py/blob/master/docs/sdks/credentials/README.md#update) - Update subscriber credentials\n* [append](https://github.com/novuhq/novu-py/blob/master/docs/sdks/credentials/README.md#append) - Modify subscriber credentials\n* [delete](https://github.com/novuhq/novu-py/blob/master/docs/sdks/credentials/README.md#delete) - Delete subscriber credentials by providerId\n\n#### [subscribers.messages](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novumessages/README.md)\n\n* [mark_all_as](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novumessages/README.md#mark_all_as) - Mark a subscriber messages as seen, read, unseen or unread\n* [mark_all](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novumessages/README.md#mark_all) - Marks all the subscriber messages as read, unread, seen or unseen. Optionally you can pass feed id (or array) to mark messages of a particular feed.\n* [update_as_seen](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novumessages/README.md#update_as_seen) - Mark message action as seen\n\n#### [subscribers.notifications](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novunotifications/README.md)\n\n* [feed](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novunotifications/README.md#feed) - Get in-app notification feed for a particular subscriber\n* [unseen_count](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novunotifications/README.md#unseen_count) - Get the unseen in-app notifications count for subscribers feed\n\n#### [subscribers.preferences](https://github.com/novuhq/novu-py/blob/master/docs/sdks/preferences/README.md)\n\n* [list](https://github.com/novuhq/novu-py/blob/master/docs/sdks/preferences/README.md#list) - Get subscriber preferences\n* [update_global](https://github.com/novuhq/novu-py/blob/master/docs/sdks/preferences/README.md#update_global) - Update subscriber global preferences\n* [retrieve_by_level](https://github.com/novuhq/novu-py/blob/master/docs/sdks/preferences/README.md#retrieve_by_level) - Get subscriber preferences by level\n* [update_legacy](https://github.com/novuhq/novu-py/blob/master/docs/sdks/preferences/README.md#update_legacy) - Update subscriber preference\n* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/preferences/README.md#retrieve) - Get subscriber preferences\n* [update](https://github.com/novuhq/novu-py/blob/master/docs/sdks/preferences/README.md#update) - Update subscriber global or workflow specific preferences\n\n#### [subscribers.properties](https://github.com/novuhq/novu-py/blob/master/docs/sdks/properties/README.md)\n\n* [update_online_flag](https://github.com/novuhq/novu-py/blob/master/docs/sdks/properties/README.md#update_online_flag) - Update subscriber online status\n\n### [topics](https://github.com/novuhq/novu-py/blob/master/docs/sdks/topics/README.md)\n\n* [create](https://github.com/novuhq/novu-py/blob/master/docs/sdks/topics/README.md#create) - Topic creation\n* [list](https://github.com/novuhq/novu-py/blob/master/docs/sdks/topics/README.md#list) - Get topic list filtered \n* [delete](https://github.com/novuhq/novu-py/blob/master/docs/sdks/topics/README.md#delete) - Delete topic\n* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/topics/README.md#retrieve) - Get topic\n* [rename](https://github.com/novuhq/novu-py/blob/master/docs/sdks/topics/README.md#rename) - Rename a topic\n\n#### [topics.subscribers](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novusubscribers/README.md)\n\n* [assign](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novusubscribers/README.md#assign) - Subscribers addition\n* [retrieve](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novusubscribers/README.md#retrieve) - Check topic subscriber\n* [remove](https://github.com/novuhq/novu-py/blob/master/docs/sdks/novusubscribers/README.md#remove) - Subscribers removal\n\n</details>\n<!-- End Available Resources and Operations [operations] -->\n\n<!-- Start Pagination [pagination] -->\n## Pagination\n\nSome of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the\nreturned response object will have a `Next` method that can be called to pull down the next group of results. If the\nreturn value of `Next` is `None`, then there are no more pages to be fetched.\n\nHere's an example of one such pagination call:\n```python\nfrom novu_py import Novu\nimport os\n\nwith Novu(\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n) as novu:\n\n res = novu.subscribers.list()\n\n while res is not None:\n # Handle items\n\n res = res.next()\n\n```\n<!-- End Pagination [pagination] -->\n\n<!-- Start Retries [retries] -->\n## Retries\n\nSome of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.\n\nTo change the default retry strategy for a single API call, simply provide a `RetryConfig` object to the call:\n```python\nimport novu_py\nfrom novu_py import Novu\nfrom novu_py.utils import BackoffStrategy, RetryConfig\nimport os\n\nwith Novu(\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n) as novu:\n\n res = novu.trigger(trigger_event_request_dto=novu_py.TriggerEventRequestDto(\n workflow_id=\"workflow_identifier\",\n to={\n \"subscriber_id\": \"<id>\",\n },\n payload={\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n overrides={\n \"fcm\": {\n \"data\": {\n \"key\": \"value\",\n },\n },\n },\n ),\n RetryConfig(\"backoff\", BackoffStrategy(1, 50, 1.1, 100), False))\n\n # Handle response\n print(res)\n\n```\n\nIf you'd like to override the default retry strategy for all operations that support retries, you can use the `retry_config` optional parameter when initializing the SDK:\n```python\nimport novu_py\nfrom novu_py import Novu\nfrom novu_py.utils import BackoffStrategy, RetryConfig\nimport os\n\nwith Novu(\n retry_config=RetryConfig(\"backoff\", BackoffStrategy(1, 50, 1.1, 100), False),\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n) as novu:\n\n res = novu.trigger(trigger_event_request_dto=novu_py.TriggerEventRequestDto(\n workflow_id=\"workflow_identifier\",\n to={\n \"subscriber_id\": \"<id>\",\n },\n payload={\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n overrides={\n \"fcm\": {\n \"data\": {\n \"key\": \"value\",\n },\n },\n },\n ))\n\n # Handle response\n print(res)\n\n```\n<!-- End Retries [retries] -->\n\n<!-- Start Error Handling [errors] -->\n## Error Handling\n\nHandling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception.\n\nBy default, an API error will raise a models.APIError exception, which has the following properties:\n\n| Property | Type | Description |\n|-----------------|------------------|-----------------------|\n| `.status_code` | *int* | The HTTP status code |\n| `.message` | *str* | The error message |\n| `.raw_response` | *httpx.Response* | The raw HTTP response |\n| `.body` | *str* | The response content |\n\nWhen custom error responses are specified for an operation, the SDK may also raise their associated exceptions. You can refer to respective *Errors* tables in SDK docs for more details on possible exception types for each operation. For example, the `trigger_async` method may raise the following exceptions:\n\n| Error Type | Status Code | Content Type |\n| ------------------------- | -------------------------------------- | ---------------- |\n| models.ErrorDto | 414 | application/json |\n| models.ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |\n| models.ValidationErrorDto | 422 | application/json |\n| models.ErrorDto | 500 | application/json |\n| models.APIError | 4XX, 5XX | \\*/\\* |\n\n### Example\n\n```python\nimport novu_py\nfrom novu_py import Novu, models\nimport os\n\nwith Novu(\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n) as novu:\n res = None\n try:\n\n res = novu.trigger(trigger_event_request_dto=novu_py.TriggerEventRequestDto(\n workflow_id=\"workflow_identifier\",\n to={\n \"subscriber_id\": \"<id>\",\n },\n payload={\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n overrides={\n \"fcm\": {\n \"data\": {\n \"key\": \"value\",\n },\n },\n },\n ))\n\n # Handle response\n print(res)\n\n except models.ErrorDto as e:\n # handle e.data: models.ErrorDtoData\n raise(e)\n except models.ErrorDto as e:\n # handle e.data: models.ErrorDtoData\n raise(e)\n except models.ValidationErrorDto as e:\n # handle e.data: models.ValidationErrorDtoData\n raise(e)\n except models.ErrorDto as e:\n # handle e.data: models.ErrorDtoData\n raise(e)\n except models.APIError as e:\n # handle exception\n raise(e)\n```\n<!-- End Error Handling [errors] -->\n\n<!-- Start Server Selection [server] -->\n## Server Selection\n\n### Select Server by Index\n\nYou can override the default server globally by passing a server index to the `server_idx: int` optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:\n\n| # | Server |\n| --- | ------------------------ |\n| 0 | `https://api.novu.co` |\n| 1 | `https://eu.api.novu.co` |\n\n#### Example\n\n```python\nimport novu_py\nfrom novu_py import Novu\nimport os\n\nwith Novu(\n server_idx=1,\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n) as novu:\n\n res = novu.trigger(trigger_event_request_dto=novu_py.TriggerEventRequestDto(\n workflow_id=\"workflow_identifier\",\n to={\n \"subscriber_id\": \"<id>\",\n },\n payload={\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n overrides={\n \"fcm\": {\n \"data\": {\n \"key\": \"value\",\n },\n },\n },\n ))\n\n # Handle response\n print(res)\n\n```\n\n### Override Server URL Per-Client\n\nThe default server can also be overridden globally by passing a URL to the `server_url: str` optional parameter when initializing the SDK client instance. For example:\n```python\nimport novu_py\nfrom novu_py import Novu\nimport os\n\nwith Novu(\n server_url=\"https://api.novu.co\",\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n) as novu:\n\n res = novu.trigger(trigger_event_request_dto=novu_py.TriggerEventRequestDto(\n workflow_id=\"workflow_identifier\",\n to={\n \"subscriber_id\": \"<id>\",\n },\n payload={\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n overrides={\n \"fcm\": {\n \"data\": {\n \"key\": \"value\",\n },\n },\n },\n ))\n\n # Handle response\n print(res)\n\n```\n<!-- End Server Selection [server] -->\n\n<!-- Start Custom HTTP Client [http-client] -->\n## Custom HTTP Client\n\nThe Python SDK makes API calls using the [httpx](https://www.python-httpx.org/) HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with your own HTTP client instance.\nDepending on whether you are using the sync or async version of the SDK, you can pass an instance of `HttpClient` or `AsyncHttpClient` respectively, which are Protocol's ensuring that the client has the necessary methods to make API calls.\nThis allows you to wrap the client with your own custom logic, such as adding custom headers, logging, or error handling, or you can just pass an instance of `httpx.Client` or `httpx.AsyncClient` directly.\n\nFor example, you could specify a header for every request that this sdk makes as follows:\n```python\nfrom novu_py import Novu\nimport httpx\n\nhttp_client = httpx.Client(headers={\"x-custom-header\": \"someValue\"})\ns = Novu(client=http_client)\n```\n\nor you could wrap the client with your own custom logic:\n```python\nfrom novu_py import Novu\nfrom novu_py.httpclient import AsyncHttpClient\nimport httpx\n\nclass CustomClient(AsyncHttpClient):\n client: AsyncHttpClient\n\n def __init__(self, client: AsyncHttpClient):\n self.client = client\n\n async def send(\n self,\n request: httpx.Request,\n *,\n stream: bool = False,\n auth: Union[\n httpx._types.AuthTypes, httpx._client.UseClientDefault, None\n ] = httpx.USE_CLIENT_DEFAULT,\n follow_redirects: Union[\n bool, httpx._client.UseClientDefault\n ] = httpx.USE_CLIENT_DEFAULT,\n ) -> httpx.Response:\n request.headers[\"Client-Level-Header\"] = \"added by client\"\n\n return await self.client.send(\n request, stream=stream, auth=auth, follow_redirects=follow_redirects\n )\n\n def build_request(\n self,\n method: str,\n url: httpx._types.URLTypes,\n *,\n content: Optional[httpx._types.RequestContent] = None,\n data: Optional[httpx._types.RequestData] = None,\n files: Optional[httpx._types.RequestFiles] = None,\n json: Optional[Any] = None,\n params: Optional[httpx._types.QueryParamTypes] = None,\n headers: Optional[httpx._types.HeaderTypes] = None,\n cookies: Optional[httpx._types.CookieTypes] = None,\n timeout: Union[\n httpx._types.TimeoutTypes, httpx._client.UseClientDefault\n ] = httpx.USE_CLIENT_DEFAULT,\n extensions: Optional[httpx._types.RequestExtensions] = None,\n ) -> httpx.Request:\n return self.client.build_request(\n method,\n url,\n content=content,\n data=data,\n files=files,\n json=json,\n params=params,\n headers=headers,\n cookies=cookies,\n timeout=timeout,\n extensions=extensions,\n )\n\ns = Novu(async_client=CustomClient(httpx.AsyncClient()))\n```\n<!-- End Custom HTTP Client [http-client] -->\n\n<!-- Start Authentication [security] -->\n## Authentication\n\n### Per-Client Security Schemes\n\nThis SDK supports the following security scheme globally:\n\n| Name | Type | Scheme | Environment Variable |\n| ------------ | ------ | ------- | -------------------- |\n| `secret_key` | apiKey | API key | `NOVU_SECRET_KEY` |\n\nTo authenticate with the API the `secret_key` parameter must be set when initializing the SDK client instance. For example:\n```python\nimport novu_py\nfrom novu_py import Novu\nimport os\n\nwith Novu(\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n) as novu:\n\n res = novu.trigger(trigger_event_request_dto=novu_py.TriggerEventRequestDto(\n workflow_id=\"workflow_identifier\",\n to={\n \"subscriber_id\": \"<id>\",\n },\n payload={\n \"comment_id\": \"string\",\n \"post\": {\n \"text\": \"string\",\n },\n },\n overrides={\n \"fcm\": {\n \"data\": {\n \"key\": \"value\",\n },\n },\n },\n ))\n\n # Handle response\n print(res)\n\n```\n<!-- End Authentication [security] -->\n\n<!-- Start Resource Management [resource-management] -->\n## Resource Management\n\nThe `Novu` class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a [context manager][context-manager] and reuse it across the application.\n\n[context-manager]: https://docs.python.org/3/reference/datamodel.html#context-managers\n\n```python\nfrom novu_py import Novu\nimport os\ndef main():\n with Novu(\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n ) as novu:\n # Rest of application here...\n\n\n# Or when using async:\nasync def amain():\n async with Novu(\n secret_key=os.getenv(\"NOVU_SECRET_KEY\", \"\"),\n ) as novu:\n # Rest of application here...\n```\n<!-- End Resource Management [resource-management] -->\n\n<!-- Start Debugging [debug] -->\n## Debugging\n\nYou can setup your SDK to emit debug logs for SDK requests and responses.\n\nYou can pass your own logger class directly into your SDK.\n```python\nfrom novu_py import Novu\nimport logging\n\nlogging.basicConfig(level=logging.DEBUG)\ns = Novu(debug_logger=logging.getLogger(\"novu_py\"))\n```\n\nYou can also enable a default debug logger by setting an environment variable `NOVU_DEBUG` to true.\n<!-- End Debugging [debug] -->\n\n<!-- Placeholder for Future Speakeasy SDK Sections -->\n\n# Development\n\n## Maturity\n\nThis SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage\nto a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally\nlooking for the latest version.\n\n## Contributions\n\nWhile we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. \nWe look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release. \n\n### SDK Created by [Speakeasy](https://www.speakeasy.com/?utm_source=novu-py&utm_campaign=python)\n",
"bugtrack_url": null,
"license": null,
"summary": "Python Client SDK Generated by Speakeasy.",
"version": "0.3.3",
"project_urls": {
"Homepage": "https://github.com/novuhq/novu-py.git",
"Repository": "https://github.com/novuhq/novu-py.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cda3a25ada10198ee8b1e311199ffce2390da31b3edbbae1bcba1d4e273cb670",
"md5": "a5f97abc407d69f9bb470460461aee75",
"sha256": "57caf13556533fb9a088d8d19f8e180209c1302f2da922bae7a1918ca39c8fb8"
},
"downloads": -1,
"filename": "novu_py-0.3.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a5f97abc407d69f9bb470460461aee75",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 210621,
"upload_time": "2025-02-05T06:10:37",
"upload_time_iso_8601": "2025-02-05T06:10:37.404498Z",
"url": "https://files.pythonhosted.org/packages/cd/a3/a25ada10198ee8b1e311199ffce2390da31b3edbbae1bcba1d4e273cb670/novu_py-0.3.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6cea8a62896b91e217d45f196f8e47133cf07a91c712a2d35752c39e6f72ff97",
"md5": "3502a9eb34ec73b523cbaa859f720e07",
"sha256": "008f94d2fc7ccd22e2424fc443a40a9a5448ce4bb86d054ff870ff9afb130bfb"
},
"downloads": -1,
"filename": "novu_py-0.3.3.tar.gz",
"has_sig": false,
"md5_digest": "3502a9eb34ec73b523cbaa859f720e07",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 97958,
"upload_time": "2025-02-05T06:10:39",
"upload_time_iso_8601": "2025-02-05T06:10:39.503577Z",
"url": "https://files.pythonhosted.org/packages/6c/ea/8a62896b91e217d45f196f8e47133cf07a91c712a2d35752c39e6f72ff97/novu_py-0.3.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-05 06:10:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "novuhq",
"github_project": "novu-py",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "novu-py"
}