https://github.com/novuhq/novu-python-legacy
Python SDK for Novu - The open-source notification infrastructure for engineers. 🚀
https://github.com/novuhq/novu-python-legacy
hacktoberfest novu novu-api python python3
Last synced: about 1 year ago
JSON representation
Python SDK for Novu - The open-source notification infrastructure for engineers. 🚀
- Host: GitHub
- URL: https://github.com/novuhq/novu-python-legacy
- Owner: novuhq
- License: mit
- Created: 2023-02-06T12:50:30.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-04T14:10:40.000Z (over 1 year ago)
- Last Synced: 2025-03-31T03:36:18.326Z (about 1 year ago)
- Topics: hacktoberfest, novu, novu-api, python, python3
- Language: Python
- Homepage: https://novu-python.readthedocs.io
- Size: 690 KB
- Stars: 80
- Watchers: 4
- Forks: 31
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.rst
- License: LICENSE
Awesome Lists containing this project
README
# Python Novu SDK
[](https://pypi.org/project/novu/)

[](https://codecov.io/gh/novuhq/novu-python)
[](https://github.com/pre-commit/pre-commit)
[](https://github.com/psf/black)
[](http://mypy-lang.org/)


[](https://github.com/semantic-release/semantic-release)
---
The [Python Novu](https://novu.co) SDK and package provides a fluent and expressive interface for interacting with [Novu's API](https://api.novu.co/api) and managing notifications.
## Install
To install this package
```shell
# Via pip
pip install novu
# Via poetry
poetry add novu
```
## Contents
- [Install](#install)
- [Quick start](#quick-start)
- [Code Snippet Examples](#code-snippet-examples)
- [Events](#events)
- [Subscribers](#subscribers)
- [Topics](#topics)
- [Feeds](#feeds)
- [Environments](#environments)
- [Go further](#go-further)
- [Development](#development)
## Quick start
This package is a wrapper of all the resources offered by Novu, we will just start by triggering an event on Novu.
To do this, you will need to:
1. Create your first notification workflow and keep in mind the identifier to trigger the workflow: https://docs.novu.co/overview/quickstart/general-quickstart#create-a-workflow
2. Retrieve your API key from the Novu dashboard directly in the settings section: https://web.novu.co/settings
3. Write code to trigger your first event:
```python
from novu.api import EventApi
event_api = EventApi("https://api.novu.co", "")
event_api.trigger(
name="", # The workflow ID is the slug of the workflow name. It can be found on the workflow page.
recipients="",
payload={}, # Your Novu payload goes here
)
```
This will trigger a notification to the subscribers.
## Code Snippet Examples
### Events
Firstly, make imports and declare the needed variables this way:
```python
from novu.api import EventApi
url = "https://api.novu.co"
api_key = ""
# You can sign up on https://web.novu.co to get your API key from https://web.novu.co/settings
```
**Trigger an event** - Send notification to subscribers:
```python
from novu.api import EventApi
novu = EventApi(url, api_key).trigger(
name="digest-workflow-example", # This is the Workflow ID. It can be found on the workflow page.
recipients="", # The subscriber ID can be gotten from the dashboard.
payload={}, # Your custom Novu payload goes here
)
```
**Bulk Trigger events** - Trigger multiple events at once:
```python
from novu.dto.event import InputEventDto
from novu.api import EventApi
url = "https://api.novu.co"
api_key = ""
event_1 = InputEventDto(
name="digest-workflow-example", # The workflow ID is the slug of the workflow name. It can be found on the workflow page.
recipients="",
payload={}, # Your custom Novu payload goes here
)
event_2 = InputEventDto(
name="digest-workflow-example",
recipients="",
payload={},
)
novu = EventApi("https://api.novu.co", api_key).trigger_bulk(events=[event1, event2])
```
**Include actor field:**
```python
from novu.api import EventApi
novu = EventApi(url, api_key).trigger(
name="workflow_trigger_identifier",
recipients="subscriber_id",
actor={
"subscriberId": "subscriber_id_actor"
},
payload={
"key":"value"
},
)
```
**Broadcast to all current subscribers:**
```python
novu = EventApi(url, api_key).broadcast(
name="digest-workflow-example",
payload={"customVariable": "value"}, # Optional
)
```
### Subscribers
```python
from novu.dto.subscriber import SubscriberDto
from novu.api.subscriber import SubscriberApi
url = "https://api.novu.co"
api_key = ""
# Define a subscriber instance
subscriber = SubscriberDto(
email="novu_user@mail.com",
subscriber_id="82a48af6ac82b3cc2157b57f", #This is what the subscriber_id looks like
first_name="", # Optional
last_name="", # Optional
phone="", # Optional
avatar="", # Optional
)
# Create a subscriber
novu = SubscriberApi(url, api_key).create(subscriber)
# Get a subscriber
novu = SubscriberApi(url, api_key).get(subscriber_id)
# Get list of subscribers
novu = SubscriberApi(url, api_key).list()
```
### Topics
```python
from novu.api import TopicApi
url = ""
api_key = ""
# Create a topic
novu = TopicApi(url, api_key).create(
key="new-customers", name="New business customers"
)
# Get a topic
novu = TopicApi(url, api_key).get(key="new-customers")
# List topics
novu = TopicApi(url, api_key).list()
# Rename a topic
novu = TopicApi(url, api_key).rename(key="new-customers", name="New business customers")
# Subscribe a list of subscribers to a topic
novu = TopicApi(url, api_key).subscribe(key="old-customers", subscribers="")
# Unsubscribe a list of subscribers from a topic
novu = TopicApi(url, api_key).unsubscribe(key="old-customers", subscribers="")
```
### Feeds
```python
from novu.api.feed import FeedApi
url = ""
api_key = ""
# Create a Feed
novu = FeedApi(url, api_key).create(name="")
# Delete a Feed
FeedApi(url, api_key).delete(feed_id="")
# List feeds
novu = FeedApi(url, api_key).list()
```
### Environments
```python
from novu.api.environment import EnvironmentApi
url = ""
api_key = ""
# Create an Environment
novu = EnvironmentApi(url, api_key).create(
name="",
parent_id="" # Optional. Defaults to None
)
# # List existing environments
novu = EnvironmentApi(url, api_key).list()
# # Get the current environment
novu = EnvironmentApi(url, api_key).current()
# # Retrieve an environment's API_KEY
novu = EnvironmentApi(url, api_key).api_keys()
```
### Tenants
```python
from novu.api.tenant import TenantApi
url = ""
api_key = ""
# Create an Environment
tenant = TenantApi(url, api_key).create(
identifier="",
name="",
data={} # Optional. Defaults to {}
)
# List existing tenants
tenants = TenantApi(url, api_key).list()
tenants = TenantApi(url, api_key).list(page=1, limit=10)
# Get a tenant
tenant = TenantApi(url, api_key).get("")
# Patch some field of a tenant
tenant = TenantApi(url, api_key).patch(
"",
identifier="",
name="",
data=""
)
# Delete a tenant
TenantApi(url, api_key).delete("")
```
## Go further
After a quick start with the SDK, you'll quickly get to grips with the advanced use of the SDK and the other APIs available.
For this purpose, documentation is available here: https://novu-python.readthedocs.io/
## Development
```bash
# install deps
poetry install
# pre-commit
poetry run pre-commit install --install-hook
poetry run pre-commit install --install-hooks --hook-type commit-msg
```
## Contributing
Feature requests, bug reports and pull requests are welcome. Please create an [issue](https://github.com/novuhq/novu-python/issues).
## Support and Feedback
Be sure to visit the Novu official [documentation website](https://docs.novu.co/docs) for additional information about our SDK.
If you need additional assistance, join our Discord server [here](https://discord.novu.co).
## License
Novu Python SDK is licensed under the MIT License - see the [LICENSE](https://github.com/novuhq/novu-python/blob/main/LICENSE) file for details.