GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Docs
  • Quickstart
  • Examples
  • AI Agents
  • DBOS Console
  • Why DBOS?
  • DBOS Architecture
  • Develop with Python
  • Add DBOS To Your App
  • AI-Assisted Development
  • Tutorials
  • Steps
  • Transactions & Datasources
  • Queues & Concurrency

This view

  • Original page
  • New address

GeezerVison is showing docs.dbos.dev — Working With Python Classes | DBOS Docs

You can add DBOS decorators to your Python class instance methods. You can add step decorators to any class methods, but to add a workflow decorator to a class method, its class must inherit from DBOSConfiguredInstance and must be decorated with @DBOS.dbos_class. For example:

@DBOS.dbos_class()
class URLFetcher(DBOSConfiguredInstance):
def __init__(self, url: str):
self.url = url
super().__init__(config_name=url)

@DBOS.workflow()
def fetch_workflow(self):
return self.fetch_url()

@DBOS.step()
def fetch_url(self):
return requests.get(self.url).text

example_fetcher = URLFetcher("https://example.com")
print(example_fetcher.fetch_workflow())

When you create a new instance of a DBOS class, DBOSConfiguredInstance must be instantiated with a config_name. This config_name should be a unique identifier of the instance. Additionally, all DBOS-decorated classes must be instantiated before DBOS.launch() is called.

The reason for these requirements is to enable workflow recovery. When you create a new instance of a DBOS class, DBOS stores it in a global registry indexed by its class name and config_name. When DBOS needs to recover a workflow belonging to that class, it looks up the class instance using config_name so it can run the workflow using the right instance of its class. If DBOS classes are dynamically instantiated after DBOS.launch(), then DBOS may not find the class instance it needs to recover a workflow.

Static Methods and Class Methods​

You can add DBOS decorators to static methods and class methods of any class, even if it does not inherit from DBOSConfiguredInstance, because such methods do not access class instance variables. If the class contains a DBOS workflow, it must be decorated with @DBOS.dbos_class(). For example:

@DBOS.dbos_class()
class ExampleClass():
@staticmethod
@DBOS.workflow()
def staticmethod_workflow():
return

@classmethod
@DBOS.workflow()
def classmethod_workflow(cls):
return
  • Static Methods and Class Methods
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.