Package: novu
Python Novu SDKThePython NovuSDK and package provides a fluent and expressive interface for interacting withNovu's APIand managing notifications.InstallTo install this package# Via pippipinstallnovu# Via poetrypoetryaddnovuContentsInstallQuick startCode Snippet ExamplesEventsSubscribersTopicsFeedsEnvironmentsGo furtherDevelopmentQuick startThis 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: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-workflowRetrieve your API key from the Novu dashboard directly in the settings section:https://web.novu.co/settingsWrite code to trigger your first event:fromnovu.apiimportEventApievent_api=EventApi("https://api.novu.co","<NOVU_API_KEY>")event_api.trigger(name="<YOUR_WORKFLOW_ID>",# The workflow ID is the slug of the workflow name. It can be found on the workflow page.recipients="<YOUR_SUBSCRIBER_ID>",payload={},# Your Novu payload goes here)This will trigger a notification to the subscribers.Code Snippet ExamplesEventsFirstly, make imports and declare the needed variables this way:fromnovu.apiimportEventApiurl="https://api.novu.co"api_key="<NOVU_API_KEY>"# You can sign up on https://web.novu.co to get your API key from https://web.novu.co/settingsTrigger an event- Send notification to subscribers:fromnovu.apiimportEventApinovu=EventApi(url,api_key).trigger(name="digest-workflow-example",# This is the Workflow ID. It can be found on the workflow page.recipients="<SUBSCRIBER_IDENTIFIER>",# The subscriber ID can be gotten from the dashboard.payload={},# Your custom Novu payload goes here)Bulk Trigger events- Trigger multiple events at once:fromnovu.dto.eventimportInputEventDtofromnovu.apiimportEventApiurl="https://api.novu.co"api_key="<NOVU_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="<SUBSCRIBER_IDENTIFIER>",payload={},# Your custom Novu payload goes here)event_2=InputEventDto(name="digest-workflow-example",recipients="<SUBSCRIBER_IDENTIFIER>",payload={},)novu=EventApi("https://api.novu.co",api_key).trigger_bulk(events=[event1,event2])Include actor field:fromnovu.apiimportEventApinovu=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:novu=EventApi(url,api_key).broadcast(name="digest-workflow-example",payload={"customVariable":"value"},# Optional)Subscribersfromnovu.dto.subscriberimportSubscriberDtofromnovu.api.subscriberimportSubscriberApiurl="https://api.novu.co"api_key="<NOVU_API_KEY>"# Define a subscriber instancesubscriber=SubscriberDto(email="novu_user@mail.com",subscriber_id="82a48af6ac82b3cc2157b57f",#This is what the subscriber_id looks likefirst_name="",# Optionallast_name="",# Optionalphone="",# Optionalavatar="",# Optional)# Create a subscribernovu=SubscriberApi(url,api_key).create(subscriber)# Get a subscribernovu=SubscriberApi(url,api_key).get(subscriber_id)# Get list of subscribersnovu=SubscriberApi(url,api_key).list()Topicsfromnovu.apiimportTopicApiurl="<NOVU_URL>"api_key="<NOVU_API_KEY>"# Create a topicnovu=TopicApi(url,api_key).create(key="new-customers",name="New business customers")# Get a topicnovu=TopicApi(url,api_key).get(key="new-customers")# List topicsnovu=TopicApi(url,api_key).list()# Rename a topicnovu=TopicApi(url,api_key).rename(key="new-customers",name="New business customers")# Subscribe a list of subscribers to a topicnovu=TopicApi(url,api_key).subscribe(key="old-customers",subscribers="<LIST_OF_SUBSCRIBER_IDs>")# Unsubscribe a list of subscribers from a topicnovu=TopicApi(url,api_key).unsubscribe(key="old-customers",subscribers="<LIST_OF_SUBSCRIBER_IDs>")Feedsfromnovu.api.feedimportFeedApiurl="<NOVU_URL>"api_key="<NOVU_API_KEY>"# Create a Feednovu=FeedApi(url,api_key).create(name="<SUPPLY_NAME_FOR_FEED>")# Delete a FeedFeedApi(url,api_key).delete(feed_id="<FEED_NOVU_INTERNAL_ID>")# List feedsnovu=FeedApi(url,api_key).list()Environmentsfromnovu.api.environmentimportEnvironmentApiurl="<NOVU_URL>"api_key="<NOVU_API_KEY>"# Create an Environmentnovu=EnvironmentApi(url,api_key).create(name="<INSERT_NAME>",parent_id="<INSERT_PARENT_ID>"# Optional. Defaults to None)# # List existing environmentsnovu=EnvironmentApi(url,api_key).list()# # Get the current environmentnovu=EnvironmentApi(url,api_key).current()# # Retrieve an environment's API_KEYnovu=EnvironmentApi(url,api_key).api_keys()Tenantsfromnovu.api.tenantimportTenantApiurl="<NOVU_URL>"api_key="<NOVU_API_KEY>"# Create an Environmenttenant=TenantApi(url,api_key).create(identifier="<INSERT_UNIQUE_TENANT_ID>",name="<INSERT_NAME>",data={}# Optional. Defaults to {})# List existing tenantstenants=TenantApi(url,api_key).list()tenants=TenantApi(url,api_key).list(page=1,limit=10)# Get a tenanttenant=TenantApi(url,api_key).get("<TENANT-IDENTIFIER>")# Patch some field of a tenanttenant=TenantApi(url,api_key).patch("<CURRENT-TENANT-IDENTIFIER>",identifier="<NEW-IDENTIFIER>",name="<NEW-NAME>",data="<NEW-DATA>")# Delete a tenantTenantApi(url,api_key).delete("<TENANT-IDENTIFIER>")Go furtherAfter 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# install depspoetryinstall# pre-commitpoetryrunpre-commitinstall--install-hook
poetryrunpre-commitinstall--install-hooks--hook-typecommit-msgContributingFeature requests, bug reports and pull requests are welcome. Please create anissue.Support and FeedbackBe sure to visit the Novu officialdocumentation websitefor additional information about our SDK.
If you need additional assistance, join our Discord serverhere.LicenseNovu Python SDK is licensed under the MIT License - see theLICENSEfile for details.