dbos 0.5.0a7__tar.gz → 0.5.0a12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dbos might be problematic. Click here for more details.

Files changed (65) hide show
  1. dbos-0.5.0a12/PKG-INFO +130 -0
  2. dbos-0.5.0a12/README.md +107 -0
  3. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/admin_sever.py +2 -2
  4. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/cli.py +19 -6
  5. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/context.py +1 -4
  6. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/dbos.py +14 -6
  7. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/fastapi.py +13 -26
  8. dbos-0.5.0a12/dbos/request.py +32 -0
  9. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/system_database.py +1 -1
  10. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/templates/hello/__package/main.py +1 -1
  11. {dbos-0.5.0a7 → dbos-0.5.0a12}/pyproject.toml +2 -2
  12. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/conftest.py +12 -3
  13. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/test_concurrency.py +14 -24
  14. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/test_dbos.py +2 -2
  15. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/test_schema_migration.py +1 -1
  16. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/test_singleton.py +5 -5
  17. dbos-0.5.0a7/PKG-INFO +0 -78
  18. dbos-0.5.0a7/README.md +0 -55
  19. {dbos-0.5.0a7 → dbos-0.5.0a12}/LICENSE +0 -0
  20. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/__init__.py +0 -0
  21. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/application_database.py +0 -0
  22. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/core.py +0 -0
  23. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/dbos-config.schema.json +0 -0
  24. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/dbos_config.py +0 -0
  25. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/decorators.py +0 -0
  26. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/error.py +0 -0
  27. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/logger.py +0 -0
  28. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/migrations/env.py +0 -0
  29. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/migrations/script.py.mako +0 -0
  30. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/migrations/versions/5c361fc04708_added_system_tables.py +0 -0
  31. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/migrations/versions/a3b18ad34abe_added_triggers.py +0 -0
  32. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/py.typed +0 -0
  33. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/recovery.py +0 -0
  34. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/registrations.py +0 -0
  35. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/roles.py +0 -0
  36. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/scheduler/croniter.py +0 -0
  37. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/scheduler/scheduler.py +0 -0
  38. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/schemas/__init__.py +0 -0
  39. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/schemas/application_database.py +0 -0
  40. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/schemas/system_database.py +0 -0
  41. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/templates/hello/README.md +0 -0
  42. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/templates/hello/__package/__init__.py +0 -0
  43. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/templates/hello/__package/schema.py +0 -0
  44. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/templates/hello/alembic.ini +0 -0
  45. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/templates/hello/dbos-config.yaml.dbos +0 -0
  46. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/templates/hello/migrations/env.py.dbos +0 -0
  47. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/templates/hello/migrations/script.py.mako +0 -0
  48. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/templates/hello/migrations/versions/2024_07_31_180642_init.py +0 -0
  49. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/templates/hello/start_postgres_docker.py +0 -0
  50. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/tracer.py +0 -0
  51. {dbos-0.5.0a7 → dbos-0.5.0a12}/dbos/utils.py +0 -0
  52. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/__init__.py +0 -0
  53. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/atexit_no_ctor.py +0 -0
  54. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/atexit_no_launch.py +0 -0
  55. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/classdefs.py +0 -0
  56. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/more_classdefs.py +0 -0
  57. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/scheduler/test_croniter.py +0 -0
  58. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/scheduler/test_scheduler.py +0 -0
  59. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/test_admin_server.py +0 -0
  60. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/test_classdecorators.py +0 -0
  61. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/test_config.py +0 -0
  62. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/test_failures.py +0 -0
  63. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/test_fastapi.py +0 -0
  64. {dbos-0.5.0a7 → dbos-0.5.0a12}/tests/test_package.py +0 -0
  65. {dbos-0.5.0a7 → dbos-0.5.0a12}/version/__init__.py +0 -0
dbos-0.5.0a12/PKG-INFO ADDED
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.1
2
+ Name: dbos
3
+ Version: 0.5.0a12
4
+ Summary: Ultra-lightweight durable execution in Python
5
+ Author-Email: "DBOS, Inc." <contact@dbos.dev>
6
+ License: MIT
7
+ Requires-Python: >=3.9
8
+ Requires-Dist: pyyaml>=6.0.2
9
+ Requires-Dist: jsonschema>=4.23.0
10
+ Requires-Dist: alembic>=1.13.2
11
+ Requires-Dist: psycopg2-binary>=2.9.9
12
+ Requires-Dist: typing-extensions>=4.12.2; python_version < "3.10"
13
+ Requires-Dist: typer>=0.12.3
14
+ Requires-Dist: jsonpickle>=3.2.2
15
+ Requires-Dist: opentelemetry-api>=1.26.0
16
+ Requires-Dist: opentelemetry-sdk>=1.26.0
17
+ Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.26.0
18
+ Requires-Dist: python-dateutil>=2.9.0.post0
19
+ Requires-Dist: fastapi[standard]>=0.112.1
20
+ Requires-Dist: psutil>=6.0.0
21
+ Requires-Dist: tomlkit>=0.13.2
22
+ Description-Content-Type: text/markdown
23
+
24
+ ## 🚀 DBOS Transact - Ultra-Lightweight Durable Execution in Python 🚀
25
+
26
+ ---
27
+
28
+ 📚 **Documentation**: Under Construction 🚧
29
+
30
+ 💬 **Join the Discussion**: [Discord Community](https://discord.gg/fMwQjeW5zg)
31
+
32
+ ---
33
+
34
+
35
+ **DBOS Python is under construction! 🚧🚧🚧 Check back regularly for updates, release coming in mid-September!**
36
+
37
+ DBOS Transact is a **Python library** providing ultra-lightweight durable execution.
38
+ For example:
39
+
40
+ ```python
41
+ @DBOS.step()
42
+ def step_one():
43
+ ...
44
+
45
+ @DBOS.step()
46
+ def step_two():
47
+ ...
48
+
49
+ @DBOS.workflow()
50
+ def workflow()
51
+ step_one()
52
+ step_two()
53
+ ```
54
+
55
+ Durable execution means your program is **resilient to any failure**.
56
+ If it is ever interrupted or crashes, all your workflows will automatically resume from the last completed step.
57
+ If you want to see durable execution in action, check out [this demo app](https://demo-widget-store.cloud.dbos.dev/) (source code [here](https://github.com/dbos-inc/dbos-demo-apps/tree/main/python/widget-store)).
58
+ No matter how many times you try to crash it, it always resumes from exactly where it left off!
59
+
60
+ Under the hood, DBOS Transact works by storing your program's execution state (which workflows are currently executing and which steps they've completed) in a Postgres database.
61
+ So all you need to use it is a Postgres database to connect to&mdash;there's no need for a "workflow server."
62
+ This approach is also incredibly fast, for example [25x faster than AWS Step Functions](https://www.dbos.dev/blog/dbos-vs-aws-step-functions-benchmark).
63
+
64
+ Some more cool features include:
65
+
66
+ - Scheduled jobs&mdash;run your workflows exactly-once per time interval.
67
+ - Exactly-once event processing&mdash;use workflows to process incoming events (for example, from a Kafka topic) exactly-once.
68
+ - Observability&mdash;all workflows automatically emit [OpenTelemetry](https://opentelemetry.io/) traces.
69
+
70
+ ## Getting Started
71
+
72
+ To try out the latest pre-release version, install and configure with:
73
+
74
+ ```shell
75
+ pip install --pre dbos
76
+ dbos init --config
77
+ ```
78
+
79
+ Try it out with this simple program (requires Postgres):
80
+
81
+ ```python
82
+ from fastapi import FastAPI
83
+ from dbos import DBOS
84
+
85
+ app = FastAPI()
86
+ DBOS(fastapi=app)
87
+
88
+ @DBOS.step()
89
+ def step_one():
90
+ print("Step one completed!")
91
+
92
+ @DBOS.step()
93
+ def step_two():
94
+ print("Step two completed!")
95
+
96
+ @DBOS.workflow()
97
+ def workflow():
98
+ step_one()
99
+ for _ in range(5):
100
+ print("Press Control + \ to stop the app...")
101
+ DBOS.sleep(1)
102
+ step_two()
103
+
104
+ @app.get("/")
105
+ def endpoint():
106
+ workflow()
107
+ ```
108
+
109
+ Save the program into `main.py`, tell it your local Postgres password via `export PGPASSWORD=<your password>` and start it with `fastapi run`.
110
+ Visit `localhost:8000` in your browser (or curl it) to start the workflow.
111
+ When prompted, press `Control + \` to force quit your application.
112
+ It should crash midway through the workflow, having completed step one but not step two.
113
+ Then, restart your app with `fastapi run`.
114
+ It should resume the workflow from where it left off, completing step two without re-executing step one.
115
+
116
+ To learn how to build more complex examples, see our programming guide (coming soon).
117
+
118
+ ## Documentation
119
+
120
+ Coming soon! 🚧
121
+
122
+ ## Examples
123
+
124
+ Check out some cool demo apps here: [https://github.com/dbos-inc/dbos-demo-apps/tree/main/python](https://github.com/dbos-inc/dbos-demo-apps/tree/main/python)
125
+
126
+ ## Community
127
+
128
+ If you're interested in building with us, please star our repository and join our community on [Discord](https://discord.gg/fMwQjeW5zg)!
129
+ If you see a bug or have a feature request, don't hesitate to open an issue here on GitHub.
130
+ If you're interested in contributing, check out our [contributions guide](./CONTRIBUTING.md).
@@ -0,0 +1,107 @@
1
+ ## 🚀 DBOS Transact - Ultra-Lightweight Durable Execution in Python 🚀
2
+
3
+ ---
4
+
5
+ 📚 **Documentation**: Under Construction 🚧
6
+
7
+ 💬 **Join the Discussion**: [Discord Community](https://discord.gg/fMwQjeW5zg)
8
+
9
+ ---
10
+
11
+
12
+ **DBOS Python is under construction! 🚧🚧🚧 Check back regularly for updates, release coming in mid-September!**
13
+
14
+ DBOS Transact is a **Python library** providing ultra-lightweight durable execution.
15
+ For example:
16
+
17
+ ```python
18
+ @DBOS.step()
19
+ def step_one():
20
+ ...
21
+
22
+ @DBOS.step()
23
+ def step_two():
24
+ ...
25
+
26
+ @DBOS.workflow()
27
+ def workflow()
28
+ step_one()
29
+ step_two()
30
+ ```
31
+
32
+ Durable execution means your program is **resilient to any failure**.
33
+ If it is ever interrupted or crashes, all your workflows will automatically resume from the last completed step.
34
+ If you want to see durable execution in action, check out [this demo app](https://demo-widget-store.cloud.dbos.dev/) (source code [here](https://github.com/dbos-inc/dbos-demo-apps/tree/main/python/widget-store)).
35
+ No matter how many times you try to crash it, it always resumes from exactly where it left off!
36
+
37
+ Under the hood, DBOS Transact works by storing your program's execution state (which workflows are currently executing and which steps they've completed) in a Postgres database.
38
+ So all you need to use it is a Postgres database to connect to&mdash;there's no need for a "workflow server."
39
+ This approach is also incredibly fast, for example [25x faster than AWS Step Functions](https://www.dbos.dev/blog/dbos-vs-aws-step-functions-benchmark).
40
+
41
+ Some more cool features include:
42
+
43
+ - Scheduled jobs&mdash;run your workflows exactly-once per time interval.
44
+ - Exactly-once event processing&mdash;use workflows to process incoming events (for example, from a Kafka topic) exactly-once.
45
+ - Observability&mdash;all workflows automatically emit [OpenTelemetry](https://opentelemetry.io/) traces.
46
+
47
+ ## Getting Started
48
+
49
+ To try out the latest pre-release version, install and configure with:
50
+
51
+ ```shell
52
+ pip install --pre dbos
53
+ dbos init --config
54
+ ```
55
+
56
+ Try it out with this simple program (requires Postgres):
57
+
58
+ ```python
59
+ from fastapi import FastAPI
60
+ from dbos import DBOS
61
+
62
+ app = FastAPI()
63
+ DBOS(fastapi=app)
64
+
65
+ @DBOS.step()
66
+ def step_one():
67
+ print("Step one completed!")
68
+
69
+ @DBOS.step()
70
+ def step_two():
71
+ print("Step two completed!")
72
+
73
+ @DBOS.workflow()
74
+ def workflow():
75
+ step_one()
76
+ for _ in range(5):
77
+ print("Press Control + \ to stop the app...")
78
+ DBOS.sleep(1)
79
+ step_two()
80
+
81
+ @app.get("/")
82
+ def endpoint():
83
+ workflow()
84
+ ```
85
+
86
+ Save the program into `main.py`, tell it your local Postgres password via `export PGPASSWORD=<your password>` and start it with `fastapi run`.
87
+ Visit `localhost:8000` in your browser (or curl it) to start the workflow.
88
+ When prompted, press `Control + \` to force quit your application.
89
+ It should crash midway through the workflow, having completed step one but not step two.
90
+ Then, restart your app with `fastapi run`.
91
+ It should resume the workflow from where it left off, completing step two without re-executing step one.
92
+
93
+ To learn how to build more complex examples, see our programming guide (coming soon).
94
+
95
+ ## Documentation
96
+
97
+ Coming soon! 🚧
98
+
99
+ ## Examples
100
+
101
+ Check out some cool demo apps here: [https://github.com/dbos-inc/dbos-demo-apps/tree/main/python](https://github.com/dbos-inc/dbos-demo-apps/tree/main/python)
102
+
103
+ ## Community
104
+
105
+ If you're interested in building with us, please star our repository and join our community on [Discord](https://discord.gg/fMwQjeW5zg)!
106
+ If you see a bug or have a feature request, don't hesitate to open an issue here on GitHub.
107
+ If you're interested in contributing, check out our [contributions guide](./CONTRIBUTING.md).
@@ -28,11 +28,11 @@ class AdminServer:
28
28
  self.server_thread = threading.Thread(target=self.server.serve_forever)
29
29
  self.server_thread.daemon = True
30
30
 
31
- dbos_logger.info("Starting DBOS admin server on port %d", self.port)
31
+ dbos_logger.debug("Starting DBOS admin server on port %d", self.port)
32
32
  self.server_thread.start()
33
33
 
34
34
  def stop(self) -> None:
35
- dbos_logger.info("Stopping DBOS admin server")
35
+ dbos_logger.debug("Stopping DBOS admin server")
36
36
  self.server.shutdown()
37
37
  self.server.server_close()
38
38
  self.server_thread.join()
@@ -119,7 +119,7 @@ def copy_template_dir(src_dir: str, dst_dir: str, ctx: dict[str, str]) -> None:
119
119
  shutil.copy(src, dst)
120
120
 
121
121
 
122
- def copy_template(src_dir: str, project_name: str) -> None:
122
+ def copy_template(src_dir: str, project_name: str, config_mode: bool) -> None:
123
123
 
124
124
  dst_dir = path.abspath(".")
125
125
 
@@ -131,10 +131,17 @@ def copy_template(src_dir: str, project_name: str) -> None:
131
131
  "db_name": db_name,
132
132
  }
133
133
 
134
- copy_template_dir(src_dir, dst_dir, ctx)
135
- copy_template_dir(
136
- path.join(src_dir, "__package"), path.join(dst_dir, package_name), ctx
137
- )
134
+ if config_mode:
135
+ copy_dbos_template(
136
+ os.path.join(src_dir, "dbos-config.yaml.dbos"),
137
+ os.path.join(dst_dir, "dbos-config.yaml"),
138
+ ctx,
139
+ )
140
+ else:
141
+ copy_template_dir(src_dir, dst_dir, ctx)
142
+ copy_template_dir(
143
+ path.join(src_dir, "__package"), path.join(dst_dir, package_name), ctx
144
+ )
138
145
 
139
146
 
140
147
  def get_project_name() -> typing.Union[str, None]:
@@ -173,6 +180,10 @@ def init(
173
180
  typing.Optional[str],
174
181
  typer.Option("--template", "-t", help="Specify template to use"),
175
182
  ] = None,
183
+ config: Annotated[
184
+ bool,
185
+ typer.Option("--config", "-c", help="Only add dbos-config.yaml"),
186
+ ] = False,
176
187
  ) -> None:
177
188
  try:
178
189
  if project_name is None:
@@ -199,7 +210,9 @@ def init(
199
210
  if template not in templates:
200
211
  raise Exception(f"template {template} not found in {templates_dir}")
201
212
 
202
- copy_template(path.join(templates_dir, template), project_name)
213
+ copy_template(
214
+ path.join(templates_dir, template), project_name, config_mode=config
215
+ )
203
216
  except Exception as e:
204
217
  print(f"[red]{e}[/red]")
205
218
 
@@ -8,13 +8,10 @@ from types import TracebackType
8
8
  from typing import TYPE_CHECKING, List, Literal, Optional, Type, TypedDict
9
9
 
10
10
  from opentelemetry.trace import Span, Status, StatusCode
11
-
12
- if TYPE_CHECKING:
13
- from .fastapi import Request
14
-
15
11
  from sqlalchemy.orm import Session
16
12
 
17
13
  from .logger import dbos_logger
14
+ from .request import Request
18
15
  from .tracer import dbos_tracer
19
16
 
20
17
 
@@ -52,7 +52,7 @@ from .tracer import dbos_tracer
52
52
 
53
53
  if TYPE_CHECKING:
54
54
  from fastapi import FastAPI
55
- from .fastapi import Request
55
+ from .request import Request
56
56
 
57
57
  from sqlalchemy.orm import Session
58
58
 
@@ -202,8 +202,9 @@ class DBOS:
202
202
 
203
203
  def __new__(
204
204
  cls: Type[DBOS],
205
- fastapi: Optional["FastAPI"] = None,
205
+ *,
206
206
  config: Optional[ConfigFile] = None,
207
+ fastapi: Optional["FastAPI"] = None,
207
208
  ) -> DBOS:
208
209
  global _dbos_global_instance
209
210
  global _dbos_global_registry
@@ -239,8 +240,9 @@ class DBOS:
239
240
 
240
241
  def __init__(
241
242
  self,
242
- fastapi: Optional["FastAPI"] = None,
243
+ *,
243
244
  config: Optional[ConfigFile] = None,
245
+ fastapi: Optional["FastAPI"] = None,
244
246
  ) -> None:
245
247
  if hasattr(self, "_initialized") and self._initialized:
246
248
  return
@@ -267,7 +269,8 @@ class DBOS:
267
269
  from dbos.fastapi import setup_fastapi_middleware
268
270
 
269
271
  setup_fastapi_middleware(self.fastapi)
270
- self.fastapi.on_event("startup")(self.launch)
272
+ self.fastapi.on_event("startup")(self._launch)
273
+ self.fastapi.on_event("shutdown")(self._destroy)
271
274
 
272
275
  # Register send_stub as a workflow
273
276
  def send_temp_workflow(
@@ -313,7 +316,12 @@ class DBOS:
313
316
  rv: AdminServer = self._admin_server
314
317
  return rv
315
318
 
316
- def launch(self) -> None:
319
+ @classmethod
320
+ def launch(cls) -> None:
321
+ if _dbos_global_instance is not None:
322
+ _dbos_global_instance._launch()
323
+
324
+ def _launch(self) -> None:
317
325
  if self._launched:
318
326
  dbos_logger.warning(f"DBOS was already launched")
319
327
  return
@@ -651,7 +659,7 @@ class DBOS:
651
659
 
652
660
  @classproperty
653
661
  def request(cls) -> Optional["Request"]:
654
- """Return the FastAPI `Request`, if any, associated with the current context."""
662
+ """Return the HTTP `Request`, if any, associated with the current context."""
655
663
  ctx = assert_current_dbos_context()
656
664
  return ctx.request
657
665
 
@@ -11,6 +11,7 @@ from .context import (
11
11
  TracedAttributes,
12
12
  assert_current_dbos_context,
13
13
  )
14
+ from .request import Address, Request
14
15
 
15
16
  request_id_header = "x-request-id"
16
17
 
@@ -23,31 +24,17 @@ def get_or_generate_request_id(request: FastAPIRequest) -> str:
23
24
  return str(uuid.uuid4())
24
25
 
25
26
 
26
- class Request:
27
- """
28
- Serializable subset of the FastAPI Request object.
29
-
30
- Attributes:
31
- base_url(URL): Base of URL requested, as in application code
32
- client(Address): HTTP Client
33
- cookies(Dict[str, str]): HTTP Cookies
34
- headers(Headers): HTTP headers
35
- method(str): HTTP verb
36
- path_params(Dict[str,Any]): Parameters extracted from URL path sections
37
- query_params(QueryParams): URL query string parameters
38
- url(URL): Full URL accessed
39
-
40
- """
41
-
42
- def __init__(self, req: FastAPIRequest):
43
- self.headers = req.headers
44
- self.path_params = req.path_params
45
- self.query_params = req.query_params
46
- self.url = req.url
47
- self.base_url = req.base_url
48
- self.client = req.client
49
- self.cookies = req.cookies
50
- self.method = req.method
27
+ def make_request(request: FastAPIRequest) -> Request:
28
+ return Request(
29
+ headers=request.headers,
30
+ path_params=request.path_params,
31
+ query_params=request.query_params,
32
+ url=str(request.url),
33
+ base_url=str(request.base_url),
34
+ client=Address(*request.client) if request.client is not None else None,
35
+ cookies=request.cookies,
36
+ method=request.method,
37
+ )
51
38
 
52
39
 
53
40
  def setup_fastapi_middleware(app: FastAPI) -> None:
@@ -65,7 +52,7 @@ def setup_fastapi_middleware(app: FastAPI) -> None:
65
52
  }
66
53
  with EnterDBOSHandler(attributes):
67
54
  ctx = assert_current_dbos_context()
68
- ctx.request = Request(request)
55
+ ctx.request = make_request(request)
69
56
  workflow_id = request.headers.get("dbos-idempotency-key", "")
70
57
  with SetWorkflowID(workflow_id):
71
58
  response = await call_next(request)
@@ -0,0 +1,32 @@
1
+ from dataclasses import dataclass
2
+ from typing import Any, Mapping, NamedTuple, Optional
3
+
4
+
5
+ class Address(NamedTuple):
6
+ hostname: str
7
+ port: int
8
+
9
+
10
+ @dataclass
11
+ class Request:
12
+ """
13
+ Serializable HTTP Request object.
14
+ Attributes:
15
+ base_url(str): Base of URL requested, as in application code
16
+ client(Optional[Address]): HTTP Client
17
+ cookies(Mapping[str, str]): HTTP Cookies
18
+ headers(Mapping[str, str]): HTTP headers
19
+ method(str): HTTP verb
20
+ path_params(Mapping[str, Any]): Parameters extracted from URL path sections
21
+ query_params(Mapping[str, str]): URL query string parameters
22
+ url(str): Full URL accessed
23
+ """
24
+
25
+ headers: Mapping[str, str]
26
+ path_params: Mapping[str, Any]
27
+ query_params: Mapping[str, str]
28
+ url: str
29
+ base_url: str
30
+ client: Optional[Address]
31
+ cookies: Mapping[str, str]
32
+ method: str
@@ -230,7 +230,7 @@ class SystemDatabase:
230
230
  def wait_for_buffer_flush(self) -> None:
231
231
  # Wait until the buffers are flushed.
232
232
  while self._is_flushing_status_buffer or not self._is_buffers_empty:
233
- dbos_logger.info("Waiting for system buffers to be exported")
233
+ dbos_logger.debug("Waiting for system buffers to be exported")
234
234
  time.sleep(1)
235
235
 
236
236
  def update_workflow_status(
@@ -15,7 +15,7 @@ from dbos import DBOS
15
15
  from .schema import dbos_hello
16
16
 
17
17
  app = FastAPI()
18
- DBOS(app)
18
+ DBOS(fastapi=app)
19
19
 
20
20
  # Next, let's write a function that greets visitors.
21
21
  # To make it more interesting, we'll keep track of how
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "dbos"
3
3
  dynamic = []
4
- description = "A Python framework for backends that scale"
4
+ description = "Ultra-lightweight durable execution in Python"
5
5
  authors = [
6
6
  { name = "DBOS, Inc.", email = "contact@dbos.dev" },
7
7
  ]
@@ -23,7 +23,7 @@ dependencies = [
23
23
  ]
24
24
  requires-python = ">=3.9"
25
25
  readme = "README.md"
26
- version = "0.5.0a7"
26
+ version = "0.5.0a12"
27
27
 
28
28
  [project.license]
29
29
  text = "MIT"
@@ -1,6 +1,7 @@
1
1
  import glob
2
2
  import os
3
3
  import subprocess
4
+ import warnings
4
5
  from typing import Any, Generator, Tuple
5
6
 
6
7
  import pytest
@@ -104,7 +105,7 @@ def dbos(
104
105
  # If your test is tricky and has a problem with this, use a different
105
106
  # fixture that does not launch.
106
107
  dbos = DBOS(config=config)
107
- dbos.launch()
108
+ DBOS.launch()
108
109
 
109
110
  yield dbos
110
111
  DBOS.destroy()
@@ -116,11 +117,19 @@ def dbos_fastapi(
116
117
  ) -> Generator[Tuple[DBOS, FastAPI], Any, None]:
117
118
  DBOS.destroy()
118
119
  app = FastAPI()
119
- dbos = DBOS(fastapi=app, config=config)
120
+
121
+ # ignore the on_event deprecation warnings
122
+ with warnings.catch_warnings():
123
+ warnings.filterwarnings(
124
+ "ignore",
125
+ category=DeprecationWarning,
126
+ message="\s*on_event is deprecated, use lifespan event handlers instead\.",
127
+ )
128
+ dbos = DBOS(fastapi=app, config=config)
120
129
 
121
130
  # This is for test convenience.
122
131
  # Usually fastapi itself does launch, but we are not completing the fastapi lifecycle
123
- dbos.launch()
132
+ DBOS.launch()
124
133
 
125
134
  yield dbos, app
126
135
  DBOS.destroy()
@@ -34,24 +34,20 @@ def test_concurrent_conflict_uuid(dbos: DBOS) -> None:
34
34
  condition = threading.Condition()
35
35
  step_count = 0
36
36
  txn_count = 0
37
- notified = False
38
37
 
39
38
  @DBOS.step()
40
39
  def test_step() -> str:
41
- nonlocal step_count, notified
40
+ nonlocal step_count
41
+ condition.acquire()
42
42
  step_count += 1
43
- if step_count == 1:
43
+ if step_count % 2 == 1:
44
44
  # Wait for the other one to notify
45
- condition.acquire()
46
45
  condition.wait()
47
- notified = True
48
- condition.release()
49
46
  else:
50
- while not notified:
51
- condition.acquire()
52
- condition.notify()
53
- condition.release()
54
- time.sleep(0.1)
47
+ # Notify the other one
48
+ condition.notify()
49
+ condition.release()
50
+
55
51
  return DBOS.workflow_id
56
52
 
57
53
  @DBOS.workflow()
@@ -67,20 +63,17 @@ def test_concurrent_conflict_uuid(dbos: DBOS) -> None:
67
63
  @DBOS.transaction(isolation_level="REPEATABLE READ")
68
64
  def test_transaction() -> str:
69
65
  DBOS.sql_session.execute(text("SELECT 1")).fetchall()
70
- nonlocal txn_count, notified
66
+ nonlocal txn_count
67
+ condition.acquire()
71
68
  txn_count += 1
72
- if txn_count == 1:
69
+ if txn_count % 2 == 1:
73
70
  # Wait for the other one to notify
74
- condition.acquire()
75
71
  condition.wait()
76
- notified = True
77
- condition.release()
78
72
  else:
79
- while not notified:
80
- condition.acquire()
81
- condition.notify()
82
- condition.release()
83
- time.sleep(0.1)
73
+ # Notify the other one
74
+ condition.notify()
75
+ condition.release()
76
+
84
77
  return DBOS.workflow_id
85
78
 
86
79
  def test_txn_thread(id: str) -> str:
@@ -99,8 +92,6 @@ def test_concurrent_conflict_uuid(dbos: DBOS) -> None:
99
92
  assert wf_handle2.get_result() == wfuuid
100
93
 
101
94
  # Make sure temp workflows can handle conflicts as well.
102
- step_count = 0
103
- notified = False
104
95
  wfuuid = str(uuid.uuid4())
105
96
  with ThreadPoolExecutor(max_workers=2) as executor:
106
97
  future1 = executor.submit(test_comm_thread, wfuuid)
@@ -111,7 +102,6 @@ def test_concurrent_conflict_uuid(dbos: DBOS) -> None:
111
102
 
112
103
  # Make sure temp transactions can handle conflicts as well.
113
104
  wfuuid = str(uuid.uuid4())
114
- notified = False
115
105
  with ThreadPoolExecutor(max_workers=2) as executor:
116
106
  future1 = executor.submit(test_txn_thread, wfuuid)
117
107
  future2 = executor.submit(test_txn_thread, wfuuid)
@@ -481,7 +481,7 @@ def test_recovery_thread(config: ConfigFile, dbos: DBOS) -> None:
481
481
  wf_counter += 1
482
482
  return var
483
483
 
484
- dbos.launch() # Usually the framework does this but we destroyed it above
484
+ DBOS.launch() # Usually the framework does this but we destroyed it above
485
485
 
486
486
  # Upon re-initialization, the background thread should recover the workflow safely.
487
487
  max_retries = 10
@@ -685,7 +685,7 @@ def test_without_fastapi() -> None:
685
685
  sys.meta_path.remove(blocker)
686
686
 
687
687
  dbos = DBOS(config=config)
688
- dbos.launch()
688
+ DBOS.launch()
689
689
 
690
690
  try:
691
691
 
@@ -65,7 +65,7 @@ def test_custom_sysdb_name_migration(
65
65
  # Test migrating up
66
66
  DBOS.destroy() # In case of other tests leaving it
67
67
  dbos = DBOS(config=config)
68
- dbos.launch()
68
+ DBOS.launch()
69
69
 
70
70
  # Make sure all tables exist
71
71
  with dbos.sys_db.engine.connect() as connection:
@@ -22,11 +22,11 @@ def test_dbos_singleton(cleanup_test_databases: None) -> None:
22
22
  # then imports more
23
23
  from tests.classdefs import DBOSSendRecv, DBOSTestClass, DBOSTestRoles
24
24
 
25
- dbos: DBOS = DBOS(None, default_config())
25
+ dbos: DBOS = DBOS(config=default_config())
26
26
 
27
27
  from tests.more_classdefs import DBOSWFEvents, wfFunc
28
28
 
29
- dbos.launch() # Usually framework (fastapi) does this via lifecycle event
29
+ DBOS.launch() # Usually framework (fastapi) does this via lifecycle event
30
30
 
31
31
  # Basics
32
32
  with SetWorkflowID("wfid"):
@@ -120,11 +120,11 @@ def test_dbos_singleton_negative(cleanup_test_databases: None) -> None:
120
120
  # then imports more
121
121
  from tests.classdefs import DBOSTestClass
122
122
 
123
- dbos: DBOS = DBOS(None, default_config())
123
+ dbos: DBOS = DBOS(config=default_config())
124
124
 
125
125
  # Don't initialize DBOS twice
126
126
  with pytest.raises(Exception) as exc_info:
127
- DBOS(None, default_config())
127
+ DBOS(config=default_config())
128
128
  assert "conflicting configuration" in str(exc_info.value)
129
129
 
130
130
  # Something should have launched
@@ -188,7 +188,7 @@ def test_config_before_singleton_negative(cleanup_test_databases: None) -> None:
188
188
 
189
189
  # Not OK, config already loaded in the default way
190
190
  with pytest.raises(Exception) as exc_info:
191
- DBOS(None, config=default_config())
191
+ DBOS(config=default_config())
192
192
  assert "configured multiple" in str(exc_info.value)
193
193
  finally:
194
194
  DBOS.destroy()
dbos-0.5.0a7/PKG-INFO DELETED
@@ -1,78 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: dbos
3
- Version: 0.5.0a7
4
- Summary: A Python framework for backends that scale
5
- Author-Email: "DBOS, Inc." <contact@dbos.dev>
6
- License: MIT
7
- Requires-Python: >=3.9
8
- Requires-Dist: pyyaml>=6.0.2
9
- Requires-Dist: jsonschema>=4.23.0
10
- Requires-Dist: alembic>=1.13.2
11
- Requires-Dist: psycopg2-binary>=2.9.9
12
- Requires-Dist: typing-extensions>=4.12.2; python_version < "3.10"
13
- Requires-Dist: typer>=0.12.3
14
- Requires-Dist: jsonpickle>=3.2.2
15
- Requires-Dist: opentelemetry-api>=1.26.0
16
- Requires-Dist: opentelemetry-sdk>=1.26.0
17
- Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.26.0
18
- Requires-Dist: python-dateutil>=2.9.0.post0
19
- Requires-Dist: fastapi[standard]>=0.112.1
20
- Requires-Dist: psutil>=6.0.0
21
- Requires-Dist: tomlkit>=0.13.2
22
- Description-Content-Type: text/markdown
23
-
24
- # DBOS Transact Python
25
-
26
- **DBOS Python is under construction! 🚧🚧🚧 Check back regularly for updates, release coming in mid-September!**
27
-
28
- DBOS Transact is a **Python library** for building durable and scalable applications.
29
-
30
- You want to use DBOS Transact in your application because you need:
31
-
32
- - **Resilience to any failure**. If your app is interrupted for any reason, it automatically resumes from where it left off. Reliable message delivery is built in. Idempotency is built in.
33
- - **Reliable event processing**. Need to consume Kafka events exactly-once? Just add one line of code to your app. Need to run a task exactly once per hour, day, or month? Just one more line of code.
34
- - **Built-in observability**. Automatically emit [OpenTelemetry](https://opentelemetry.io/)-compatible logs and traces from any application. Query your app's history from the command line or with SQL.
35
- - **Blazing-fast, developer-friendly serverless**. Develop your project locally and run it anywhere. When you're ready, [deploy it for free to DBOS Cloud](https://docs.dbos.dev/getting-started/quickstart#deploying-to-dbos-cloud) and we'll host it for you, [25x faster](https://www.dbos.dev/blog/dbos-vs-aws-step-functions-benchmark) and [15x cheaper](https://www.dbos.dev/blog/dbos-vs-lambda-cost) than AWS Lambda.
36
-
37
- ## Getting Started
38
-
39
- To try out the latest pre-release version, install with:
40
-
41
- ```shell
42
- pip install --pre dbos
43
- ```
44
-
45
- ## Documentation
46
-
47
- Coming soon! 🚧
48
-
49
- But we have some cool demo apps for you to check out: [https://github.com/dbos-inc/dbos-demo-apps/tree/main/python](https://github.com/dbos-inc/dbos-demo-apps/tree/main/python)
50
-
51
- ## Main Features
52
-
53
- Here are some of the core features of DBOS Transact:
54
-
55
- | Feature | Description
56
- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
57
- | [Transactions](https://www.dbos.dev/dbos-transact-python) | Easily and safely query your application database using [SQLAlchemy](https://www.sqlalchemy.org/) or raw SQL.
58
- | [Workflows](https://www.dbos.dev/dbos-transact-python) | Reliable workflow orchestration&#8212;resume your program after any failure.
59
- | [Idempotency](https://www.dbos.dev/dbos-transact-python) | Automatically make any request idempotent, so your requests happen exactly once.
60
- | [Authentication and Authorization](https://www.dbos.dev/dbos-transact-python) | Secure your HTTP endpoints so only authorized users can access them.
61
- | [Kafka Integration](https://www.dbos.dev/dbos-transact-python) | Consume Kafka messages exactly-once with transactions or workflows.
62
- | [Scheduled Workflows](https://www.dbos.dev/dbos-transact-python) | Schedule your workflows to run exactly-once per time interval with cron-like syntax.
63
- | [Self-Hosting](https://www.dbos.dev/dbos-transact-python) | Host your applications anywhere, as long as they have a Postgres database to connect to.
64
-
65
- And DBOS Cloud:
66
-
67
- | Feature | Description
68
- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
69
- | [Serverless App Deployment](https://docs.dbos.dev/cloud-tutorials/application-management) | Deploy apps to DBOS Cloud in minutes.
70
- | [Interactive Time Travel](https://docs.dbos.dev/cloud-tutorials/interactive-timetravel) | Query your application database as of any past point in time.
71
- | [Cloud Database Management](https://docs.dbos.dev/cloud-tutorials/database-management) | Provision cloud Postgres instances for your applications. Alternatively, [bring your own database](https://docs.dbos.dev/cloud-tutorials/byod-management).
72
- | [Built-in Observability](https://docs.dbos.dev/cloud-tutorials/monitoring-dashboard) | Built-in log capture, request tracing, and dashboards.
73
-
74
- ## Community
75
-
76
- If you're interested in building with us, please star our repository and join our community on [Discord](https://discord.gg/fMwQjeW5zg)!
77
- If you see a bug or have a feature request, don't hesitate to open an issue here on GitHub.
78
- If you're interested in contributing, check out our [contributions guide](./CONTRIBUTING.md).
dbos-0.5.0a7/README.md DELETED
@@ -1,55 +0,0 @@
1
- # DBOS Transact Python
2
-
3
- **DBOS Python is under construction! 🚧🚧🚧 Check back regularly for updates, release coming in mid-September!**
4
-
5
- DBOS Transact is a **Python library** for building durable and scalable applications.
6
-
7
- You want to use DBOS Transact in your application because you need:
8
-
9
- - **Resilience to any failure**. If your app is interrupted for any reason, it automatically resumes from where it left off. Reliable message delivery is built in. Idempotency is built in.
10
- - **Reliable event processing**. Need to consume Kafka events exactly-once? Just add one line of code to your app. Need to run a task exactly once per hour, day, or month? Just one more line of code.
11
- - **Built-in observability**. Automatically emit [OpenTelemetry](https://opentelemetry.io/)-compatible logs and traces from any application. Query your app's history from the command line or with SQL.
12
- - **Blazing-fast, developer-friendly serverless**. Develop your project locally and run it anywhere. When you're ready, [deploy it for free to DBOS Cloud](https://docs.dbos.dev/getting-started/quickstart#deploying-to-dbos-cloud) and we'll host it for you, [25x faster](https://www.dbos.dev/blog/dbos-vs-aws-step-functions-benchmark) and [15x cheaper](https://www.dbos.dev/blog/dbos-vs-lambda-cost) than AWS Lambda.
13
-
14
- ## Getting Started
15
-
16
- To try out the latest pre-release version, install with:
17
-
18
- ```shell
19
- pip install --pre dbos
20
- ```
21
-
22
- ## Documentation
23
-
24
- Coming soon! 🚧
25
-
26
- But we have some cool demo apps for you to check out: [https://github.com/dbos-inc/dbos-demo-apps/tree/main/python](https://github.com/dbos-inc/dbos-demo-apps/tree/main/python)
27
-
28
- ## Main Features
29
-
30
- Here are some of the core features of DBOS Transact:
31
-
32
- | Feature | Description
33
- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
34
- | [Transactions](https://www.dbos.dev/dbos-transact-python) | Easily and safely query your application database using [SQLAlchemy](https://www.sqlalchemy.org/) or raw SQL.
35
- | [Workflows](https://www.dbos.dev/dbos-transact-python) | Reliable workflow orchestration&#8212;resume your program after any failure.
36
- | [Idempotency](https://www.dbos.dev/dbos-transact-python) | Automatically make any request idempotent, so your requests happen exactly once.
37
- | [Authentication and Authorization](https://www.dbos.dev/dbos-transact-python) | Secure your HTTP endpoints so only authorized users can access them.
38
- | [Kafka Integration](https://www.dbos.dev/dbos-transact-python) | Consume Kafka messages exactly-once with transactions or workflows.
39
- | [Scheduled Workflows](https://www.dbos.dev/dbos-transact-python) | Schedule your workflows to run exactly-once per time interval with cron-like syntax.
40
- | [Self-Hosting](https://www.dbos.dev/dbos-transact-python) | Host your applications anywhere, as long as they have a Postgres database to connect to.
41
-
42
- And DBOS Cloud:
43
-
44
- | Feature | Description
45
- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
46
- | [Serverless App Deployment](https://docs.dbos.dev/cloud-tutorials/application-management) | Deploy apps to DBOS Cloud in minutes.
47
- | [Interactive Time Travel](https://docs.dbos.dev/cloud-tutorials/interactive-timetravel) | Query your application database as of any past point in time.
48
- | [Cloud Database Management](https://docs.dbos.dev/cloud-tutorials/database-management) | Provision cloud Postgres instances for your applications. Alternatively, [bring your own database](https://docs.dbos.dev/cloud-tutorials/byod-management).
49
- | [Built-in Observability](https://docs.dbos.dev/cloud-tutorials/monitoring-dashboard) | Built-in log capture, request tracing, and dashboards.
50
-
51
- ## Community
52
-
53
- If you're interested in building with us, please star our repository and join our community on [Discord](https://discord.gg/fMwQjeW5zg)!
54
- If you see a bug or have a feature request, don't hesitate to open an issue here on GitHub.
55
- If you're interested in contributing, check out our [contributions guide](./CONTRIBUTING.md).
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes