Create libraries of code you want to reuse across views and jobs.
A Library in Databutton, works pretty much the same way as a local Python file does when you code on your laptop. You import the name of the library in the View of Job where you want to use it.
For example, say you have created a Library called slack, then you can import and use that as follows:
# Import the slack library
import slack
slack.send_to_slack(message="Hello, Databutton!")
# Import parts of the slack library
from slack import send_to_slack
send_to_slack(message="Hello, Databutton!")
For completeness, here is the corresponding Library code.
# Library called 'slack'
import requests
import databutton as db
WEBHOOK_URL = db.secrets.get("WEBHOOK_URL")
def send_to_slack(message: str):
Sends a message to Slack
"blocks": [
"type": "section",
"text": {
"type": "mrkdwn",
"text": message
Changes to the library will automatically be reflected in your views and jobs. For scheduled jobs and published views, changes will be applied the next time you publish your view or schedule your job.