Create libraries of code you want to reuse across your app
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 Page or 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 parts of the slack library
from slack import send_to_slack
For completeness, here is the corresponding Library code.
# Library called 'slack'
import databutton as db
WEBHOOK_URL = db.secrets.get("WEBHOOK_URL")
def send_to_slack(message: str):
Sends a message to Slack
Changes to the library will automatically be reflected in your Pages and Jobs. For scheduled jobs or deployed Pages, changes will be applied the next time you deploy.