django-webhook-outbox 1.0.0__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.
Files changed (73) hide show
  1. django_webhook_outbox-1.0.0/.gitignore +229 -0
  2. django_webhook_outbox-1.0.0/CHANGELOG.md +46 -0
  3. django_webhook_outbox-1.0.0/CONTRIBUTING.md +47 -0
  4. django_webhook_outbox-1.0.0/LICENSE +21 -0
  5. django_webhook_outbox-1.0.0/PKG-INFO +195 -0
  6. django_webhook_outbox-1.0.0/README.md +154 -0
  7. django_webhook_outbox-1.0.0/docs/channels.md +94 -0
  8. django_webhook_outbox-1.0.0/docs/concepts.md +83 -0
  9. django_webhook_outbox-1.0.0/docs/envelope.md +81 -0
  10. django_webhook_outbox-1.0.0/docs/index.md +11 -0
  11. django_webhook_outbox-1.0.0/docs/runners.md +139 -0
  12. django_webhook_outbox-1.0.0/docs/security.md +70 -0
  13. django_webhook_outbox-1.0.0/docs/semantics.md +140 -0
  14. django_webhook_outbox-1.0.0/docs/settings.md +62 -0
  15. django_webhook_outbox-1.0.0/docs/upgrading.md +140 -0
  16. django_webhook_outbox-1.0.0/docs/without-celery.md +63 -0
  17. django_webhook_outbox-1.0.0/pyproject.toml +118 -0
  18. django_webhook_outbox-1.0.0/src/webhook_outbox/__init__.py +11 -0
  19. django_webhook_outbox-1.0.0/src/webhook_outbox/admin.py +390 -0
  20. django_webhook_outbox-1.0.0/src/webhook_outbox/apps.py +12 -0
  21. django_webhook_outbox-1.0.0/src/webhook_outbox/checks.py +237 -0
  22. django_webhook_outbox-1.0.0/src/webhook_outbox/conf.py +110 -0
  23. django_webhook_outbox-1.0.0/src/webhook_outbox/contrib/__init__.py +0 -0
  24. django_webhook_outbox-1.0.0/src/webhook_outbox/contrib/celery/__init__.py +17 -0
  25. django_webhook_outbox-1.0.0/src/webhook_outbox/contrib/celery/apps.py +7 -0
  26. django_webhook_outbox-1.0.0/src/webhook_outbox/contrib/celery/schedule.py +42 -0
  27. django_webhook_outbox-1.0.0/src/webhook_outbox/contrib/celery/tasks.py +66 -0
  28. django_webhook_outbox-1.0.0/src/webhook_outbox/locale/ru/LC_MESSAGES/django.mo +0 -0
  29. django_webhook_outbox-1.0.0/src/webhook_outbox/locale/ru/LC_MESSAGES/django.po +188 -0
  30. django_webhook_outbox-1.0.0/src/webhook_outbox/management/__init__.py +0 -0
  31. django_webhook_outbox-1.0.0/src/webhook_outbox/management/commands/__init__.py +0 -0
  32. django_webhook_outbox-1.0.0/src/webhook_outbox/management/commands/webhook_outbox_deliver.py +42 -0
  33. django_webhook_outbox-1.0.0/src/webhook_outbox/management/commands/webhook_outbox_poll.py +11 -0
  34. django_webhook_outbox-1.0.0/src/webhook_outbox/management/commands/webhook_outbox_worker.py +58 -0
  35. django_webhook_outbox-1.0.0/src/webhook_outbox/migrations/0001_initial.py +239 -0
  36. django_webhook_outbox-1.0.0/src/webhook_outbox/migrations/__init__.py +0 -0
  37. django_webhook_outbox-1.0.0/src/webhook_outbox/models.py +230 -0
  38. django_webhook_outbox-1.0.0/src/webhook_outbox/py.typed +0 -0
  39. django_webhook_outbox-1.0.0/src/webhook_outbox/runner.py +147 -0
  40. django_webhook_outbox-1.0.0/src/webhook_outbox/services/__init__.py +11 -0
  41. django_webhook_outbox-1.0.0/src/webhook_outbox/services/channels/__init__.py +86 -0
  42. django_webhook_outbox-1.0.0/src/webhook_outbox/services/channels/base.py +95 -0
  43. django_webhook_outbox-1.0.0/src/webhook_outbox/services/channels/webhook.py +123 -0
  44. django_webhook_outbox-1.0.0/src/webhook_outbox/services/delivery.py +164 -0
  45. django_webhook_outbox-1.0.0/src/webhook_outbox/services/poller.py +255 -0
  46. django_webhook_outbox-1.0.0/src/webhook_outbox/services/template.py +196 -0
  47. django_webhook_outbox-1.0.0/tests/__init__.py +0 -0
  48. django_webhook_outbox-1.0.0/tests/channels.py +28 -0
  49. django_webhook_outbox-1.0.0/tests/conftest.py +49 -0
  50. django_webhook_outbox-1.0.0/tests/factories.py +76 -0
  51. django_webhook_outbox-1.0.0/tests/settings.py +81 -0
  52. django_webhook_outbox-1.0.0/tests/test_admin.py +280 -0
  53. django_webhook_outbox-1.0.0/tests/test_celery.py +97 -0
  54. django_webhook_outbox-1.0.0/tests/test_channels.py +255 -0
  55. django_webhook_outbox-1.0.0/tests/test_checks.py +167 -0
  56. django_webhook_outbox-1.0.0/tests/test_conf.py +71 -0
  57. django_webhook_outbox-1.0.0/tests/test_delivery.py +469 -0
  58. django_webhook_outbox-1.0.0/tests/test_envelope_golden.py +161 -0
  59. django_webhook_outbox-1.0.0/tests/test_locale.py +34 -0
  60. django_webhook_outbox-1.0.0/tests/test_migrations.py +21 -0
  61. django_webhook_outbox-1.0.0/tests/test_models.py +246 -0
  62. django_webhook_outbox-1.0.0/tests/test_poller.py +361 -0
  63. django_webhook_outbox-1.0.0/tests/test_retry_transitions.py +214 -0
  64. django_webhook_outbox-1.0.0/tests/test_runner.py +241 -0
  65. django_webhook_outbox-1.0.0/tests/test_semantics.py +453 -0
  66. django_webhook_outbox-1.0.0/tests/test_template.py +208 -0
  67. django_webhook_outbox-1.0.0/tests/testapp/__init__.py +0 -0
  68. django_webhook_outbox-1.0.0/tests/testapp/admin.py +8 -0
  69. django_webhook_outbox-1.0.0/tests/testapp/apps.py +7 -0
  70. django_webhook_outbox-1.0.0/tests/testapp/migrations/0001_initial.py +238 -0
  71. django_webhook_outbox-1.0.0/tests/testapp/migrations/__init__.py +0 -0
  72. django_webhook_outbox-1.0.0/tests/testapp/models.py +97 -0
  73. django_webhook_outbox-1.0.0/tests/urls.py +6 -0
@@ -0,0 +1,229 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ *.lcov
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ # Pipfile.lock
97
+
98
+ # uv
99
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # uv.lock
103
+
104
+ # poetry
105
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
106
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
107
+ # commonly ignored for libraries.
108
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
109
+ # poetry.lock
110
+ # poetry.toml
111
+
112
+ # pdm
113
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
114
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
115
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
116
+ # pdm.lock
117
+ # pdm.toml
118
+ .pdm-python
119
+ .pdm-build/
120
+
121
+ # pixi
122
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
123
+ # pixi.lock
124
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
125
+ # in the .venv directory. It is recommended not to include this directory in version control.
126
+ .pixi/*
127
+ !.pixi/config.toml
128
+
129
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
130
+ __pypackages__/
131
+
132
+ # Celery stuff
133
+ celerybeat-schedule*
134
+ celerybeat.pid
135
+
136
+ # Redis
137
+ *.rdb
138
+ *.aof
139
+ *.pid
140
+
141
+ # RabbitMQ
142
+ mnesia/
143
+ rabbitmq/
144
+ rabbitmq-data/
145
+
146
+ # ActiveMQ
147
+ activemq-data/
148
+
149
+ # SageMath parsed files
150
+ *.sage.py
151
+
152
+ # Environments
153
+ .env
154
+ .envrc
155
+ .venv
156
+ env/
157
+ venv/
158
+ ENV/
159
+ env.bak/
160
+ venv.bak/
161
+
162
+ # Conda environments
163
+ conda-meta/
164
+
165
+ # Spyder project settings
166
+ .spyderproject
167
+ .spyproject
168
+
169
+ # Rope project settings
170
+ .ropeproject
171
+
172
+ # mkdocs/Zensical documentation
173
+ /site
174
+
175
+ # mypy
176
+ .mypy_cache/
177
+ .dmypy.json
178
+ dmypy.json
179
+
180
+ # Pyre type checker
181
+ .pyre/
182
+
183
+ # pytype static type analyzer
184
+ .pytype/
185
+
186
+ # Cython debug symbols
187
+ cython_debug/
188
+
189
+ # PyCharm
190
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
191
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
192
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
193
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
194
+ # .idea/
195
+
196
+ # Abstra
197
+ # Abstra is an AI-powered process automation framework.
198
+ # Ignore directories containing user credentials, local state, and settings.
199
+ # Learn more at https://abstra.io/docs
200
+ .abstra/
201
+
202
+ # Visual Studio Code
203
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
204
+ # can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
205
+ # and can be added to the global gitignore or merged into this file. However, if you prefer, you
206
+ # could uncomment the following to ignore the entire vscode folder
207
+ # .vscode/
208
+ # Temporary file for partial code execution
209
+ tempCodeRunnerFile.py
210
+
211
+ # Ruff stuff:
212
+ .ruff_cache/
213
+
214
+ # PyPI configuration file
215
+ .pypirc
216
+
217
+ # Marimo
218
+ marimo/_static/
219
+ marimo/_lsp/
220
+ __marimo__/
221
+
222
+ # Streamlit
223
+ .streamlit/secrets.toml
224
+
225
+ # django-webhook-outbox: compiled translations are shipped in the package
226
+ !src/webhook_outbox/locale/*/LC_MESSAGES/django.mo
227
+
228
+ # local tooling
229
+ .ruff_cache/
@@ -0,0 +1,46 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project
5
+ uses [semantic versioning](https://semver.org/). Versions come from git tags.
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [1.0.0] - unreleased (published when the `1.0.0` tag is pushed)
10
+
11
+ First public release. A 1:1 behavioural port of the outgoing webhook
12
+ pipeline of an in-house Django `notifications` app.
13
+
14
+ ### Added
15
+
16
+ - Models `NotificationChannel`, `TrackedTable` and `NotificationOutbox`
17
+ (app label `webhook_outbox`), with field names, verbose names and
18
+ constraints unchanged, and the abstract `TimeStampedModel`. A single
19
+ `0001_initial` migration equals the original final schema.
20
+ - Timestamp poller (`TablePoller`, `poll_all_tables`, `poll_table`) and the
21
+ `{dotted.path}` / `{admin_link}` template renderer, ported unchanged.
22
+ - Envelope v1 (`event`, `source_model`, `source_pk`, `tracked_table`,
23
+ `message`, `occurred_at`), `BaseChannel`, `WebhookChannel` (httpx) and a
24
+ settings-driven channel registry.
25
+ - Delivery as plain functions (`process_outbox`, `send_single_notification`).
26
+ Runners `poll_once`, `deliver_once`, `deliver_entry` and `run_forever`,
27
+ with graceful SIGTERM/SIGINT handling. Management commands
28
+ `webhook_outbox_worker`, `webhook_outbox_poll` and `webhook_outbox_deliver`.
29
+ - Optional Celery integration, `webhook_outbox.contrib.celery` (tasks and
30
+ `beat_schedule()`).
31
+ - One `WEBHOOK_OUTBOX` setting dict, with fallbacks to
32
+ `NOTIFICATION_MAX_RETRIES`, `NOTIFICATION_WEBHOOK_TIMEOUT` and `SITE_URL`.
33
+ - Admin without Celery: `retry_failed` with an optional `ADMIN_RETRY_HOOK`,
34
+ `mark_as_sent`, and a self-tracking guard for the trackable models.
35
+ - System checks for settings, unknown channel types, tracked models without
36
+ timestamps and self-tracking.
37
+ - Russian translation.
38
+
39
+ ### Behaviour differences from the original code
40
+
41
+ See [docs/upgrading.md](docs/upgrading.md#behaviour-differences). The known
42
+ limitations of the original code are kept on purpose and documented in
43
+ [docs/semantics.md](docs/semantics.md#known-limitations).
44
+
45
+ [Unreleased]: https://github.com/omnichem/django-webhook-outbox/compare/1.0.0...HEAD
46
+ [1.0.0]: https://github.com/omnichem/django-webhook-outbox/releases/tag/1.0.0
@@ -0,0 +1,47 @@
1
+ # Contributing
2
+
3
+ Issues and pull requests are welcome at
4
+ <https://github.com/omnichem/django-webhook-outbox>.
5
+
6
+ ## Development setup
7
+
8
+ The project uses [uv](https://docs.astral.sh/uv/).
9
+
10
+ ```console
11
+ uv sync --group dev # Python 3.12 by default (.python-version)
12
+ uv run pytest # SQLite, a few seconds
13
+ uv run ruff check . && uv run black --check .
14
+ uv run python -m django makemigrations --check --dry-run --settings=tests.settings --pythonpath=.
15
+ ```
16
+
17
+ To run the tests against PostgreSQL, as CI does:
18
+
19
+ ```console
20
+ uv sync --group dev --group postgres
21
+ DB_ENGINE=postgres POSTGRES_HOST=localhost POSTGRES_USER=postgres \
22
+ POSTGRES_PASSWORD=postgres POSTGRES_DB=webhook_outbox uv run pytest
23
+ ```
24
+
25
+ To try another Django version, run `uv pip install "django~=4.2.0"` and then
26
+ `uv run --no-sync pytest`.
27
+
28
+ ## Ground rules
29
+
30
+ - **Behaviour is pinned.** 1.x keeps the semantics in
31
+ [docs/semantics.md](docs/semantics.md). A change to detection, delivery or
32
+ the envelope needs a discussion first, an entry in `CHANGELOG.md`, and an
33
+ update to the `test_limitation_*` / golden tests that pin it.
34
+ - Model changes need a migration (`makemigrations webhook_outbox`). CI fails
35
+ on missing migrations.
36
+ - New user-facing strings must be translatable. Update
37
+ `src/webhook_outbox/locale/ru/LC_MESSAGES/django.po` and compile it
38
+ (`django-admin compilemessages`, run from `src/webhook_outbox`).
39
+ - Do not put real URLs, hostnames, credentials or production data in code,
40
+ tests or docs. Use `example.com`.
41
+ - Do not change the version anywhere. It comes from the git tag.
42
+
43
+ ## Releasing (maintainers)
44
+
45
+ Push a tag `X.Y.Z` (numeric, no `v` prefix) on `master`. The `release`
46
+ workflow runs the tests, builds the sdist and wheel, and publishes to PyPI
47
+ through Trusted Publishing (environment `pypi`).
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 omnichem
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,195 @@
1
+ Metadata-Version: 2.5
2
+ Name: django-webhook-outbox
3
+ Version: 1.0.0
4
+ Summary: Outgoing webhooks for Django models: timestamp polling, a transactional outbox and retrying delivery.
5
+ Project-URL: Homepage, https://github.com/omnichem/django-webhook-outbox
6
+ Project-URL: Documentation, https://github.com/omnichem/django-webhook-outbox/tree/master/docs
7
+ Project-URL: Changelog, https://github.com/omnichem/django-webhook-outbox/blob/master/CHANGELOG.md
8
+ Project-URL: Issues, https://github.com/omnichem/django-webhook-outbox/issues
9
+ Project-URL: Source, https://github.com/omnichem/django-webhook-outbox
10
+ Author: OmniChem
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: django,notifications,outbox,polling,webhook,webhooks
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Environment :: Web Environment
16
+ Classifier: Framework :: Django
17
+ Classifier: Framework :: Django :: 4.2
18
+ Classifier: Framework :: Django :: 5.0
19
+ Classifier: Framework :: Django :: 5.1
20
+ Classifier: Framework :: Django :: 5.2
21
+ Classifier: Intended Audience :: Developers
22
+ Classifier: Natural Language :: English
23
+ Classifier: Natural Language :: Russian
24
+ Classifier: Operating System :: OS Independent
25
+ Classifier: Programming Language :: Python
26
+ Classifier: Programming Language :: Python :: 3
27
+ Classifier: Programming Language :: Python :: 3 :: Only
28
+ Classifier: Programming Language :: Python :: 3.10
29
+ Classifier: Programming Language :: Python :: 3.11
30
+ Classifier: Programming Language :: Python :: 3.12
31
+ Classifier: Programming Language :: Python :: 3.13
32
+ Classifier: Topic :: Internet :: WWW/HTTP
33
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
34
+ Classifier: Typing :: Typed
35
+ Requires-Python: >=3.10
36
+ Requires-Dist: django<6,>=4.2
37
+ Requires-Dist: httpx>=0.27
38
+ Provides-Extra: celery
39
+ Requires-Dist: celery>=5.3; extra == 'celery'
40
+ Description-Content-Type: text/markdown
41
+
42
+ # django-webhook-outbox
43
+
44
+ Outgoing webhooks for Django models, configured in the Django admin.
45
+
46
+ You pick a model and an event (`insert` or `update`) in the admin and write
47
+ a message template. A poller finds new and changed rows by their
48
+ `created_at` / `updated_at` timestamps and writes them to an outbox table.
49
+ A delivery pass then POSTs each outbox entry as JSON to the channel's URL and
50
+ retries failures.
51
+
52
+ - No database triggers and no signals: any model with `created_at` /
53
+ `updated_at` fields can be tracked, including models of third-party apps.
54
+ - Delivery goes through an outbox table: pending, sent and failed entries are
55
+ visible in the admin, and failed ones can be retried from there.
56
+ - Celery is optional. The core runs from a management command
57
+ (`webhook_outbox_worker`), cron, or any scheduler; `webhook_outbox.contrib.celery`
58
+ provides ready-made tasks if you already use Celery.
59
+ - English and Russian admin.
60
+
61
+ The package was extracted from a production Django service. Release 1.0.0
62
+ keeps that code's behaviour exactly, known limitations included. They are
63
+ listed in [docs/semantics.md](docs/semantics.md); read that page before you
64
+ rely on the package for anything that must not lose or duplicate events.
65
+
66
+ ## Requirements
67
+
68
+ - Python 3.10+
69
+ - Django 4.2, 5.0, 5.1 or 5.2 (CI runs 4.2, 5.0 and 5.2 on PostgreSQL)
70
+ - httpx 0.27+
71
+ - Celery 5.3+ (optional, `[celery]` extra)
72
+
73
+ ## Installation
74
+
75
+ ```console
76
+ pip install django-webhook-outbox
77
+ # or, with the Celery tasks:
78
+ pip install "django-webhook-outbox[celery]"
79
+ ```
80
+
81
+ ```python
82
+ # settings.py
83
+ INSTALLED_APPS = [
84
+ # ...
85
+ "django.contrib.admin",
86
+ "django.contrib.contenttypes",
87
+ "webhook_outbox",
88
+ ]
89
+
90
+ WEBHOOK_OUTBOX = {
91
+ "SITE_URL": "https://shop.example.com", # used by {admin_link}
92
+ }
93
+ ```
94
+
95
+ ```console
96
+ python manage.py migrate webhook_outbox
97
+ ```
98
+
99
+ ## Quick start
100
+
101
+ 1. Make sure the model you want to track has `created_at` (insert events)
102
+ and `updated_at` (update events) fields. The easiest way is to inherit the
103
+ bundled base class:
104
+
105
+ ```python
106
+ from webhook_outbox.models import TimeStampedModel
107
+
108
+ class Order(TimeStampedModel):
109
+ number = models.CharField(max_length=20)
110
+ customer = models.ForeignKey(Customer, on_delete=models.PROTECT)
111
+ ```
112
+
113
+ 2. In the admin, add a **Notification Channel**, type *Webhook*, with this
114
+ config:
115
+
116
+ ```json
117
+ {"url": "https://receiver.example.com/hooks/orders",
118
+ "headers": {"Authorization": "Bearer <token>"},
119
+ "timeout": 10}
120
+ ```
121
+
122
+ 3. Add a **Tracked Table**: model *orders*, event *Insert*, the channel from
123
+ step 2, and a message template:
124
+
125
+ ```text
126
+ New order {number} from {customer.name}
127
+ {admin_link}
128
+ ```
129
+
130
+ 4. Run a worker (see below). The first poll of a tracked table only stores
131
+ its starting point and does not backfill. Orders created after that are
132
+ POSTed to the receiver:
133
+
134
+ ```json
135
+ {
136
+ "event": "insert",
137
+ "source_model": "shop.order",
138
+ "source_pk": "1042",
139
+ "tracked_table": "New orders",
140
+ "message": "New order A-1042 from Acme Corp\nhttps://shop.example.com/admin/shop/order/1042/change/",
141
+ "occurred_at": "2026-08-03T10:00:00.123456+00:00"
142
+ }
143
+ ```
144
+
145
+ A 2xx response marks the entry *sent*. Any other response, a timeout or
146
+ a connection error counts as a failed attempt. After `MAX_RETRIES` (3)
147
+ failed attempts the entry becomes *failed*.
148
+
149
+ ### Running without Celery
150
+
151
+ ```console
152
+ python manage.py webhook_outbox_worker # poll every 30s, deliver every 10s
153
+ python manage.py webhook_outbox_worker --once # one pass, e.g. from cron
154
+ ```
155
+
156
+ Run **one** worker process per database (see
157
+ [limitations](docs/semantics.md#known-limitations)). It stops cleanly on
158
+ SIGTERM/SIGINT. Systemd, Kubernetes and cron examples are in
159
+ [docs/runners.md](docs/runners.md).
160
+
161
+ ### Running with Celery
162
+
163
+ ```python
164
+ # settings.py
165
+ from webhook_outbox.contrib.celery.schedule import beat_schedule
166
+
167
+ INSTALLED_APPS += ["webhook_outbox.contrib.celery"]
168
+
169
+ CELERY_BEAT_SCHEDULE = {
170
+ **beat_schedule(), # poll every 30s, deliver every 10s
171
+ # ... your other entries
172
+ }
173
+
174
+ WEBHOOK_OUTBOX = {
175
+ # "Retry" in the admin pushes the entry to Celery immediately
176
+ "ADMIN_RETRY_HOOK": "webhook_outbox.contrib.celery.tasks.enqueue_single_notification",
177
+ }
178
+ ```
179
+
180
+ ## Documentation
181
+
182
+ - [Concepts](docs/concepts.md): channels, tracked tables, the outbox, the data flow
183
+ - [Semantics and known limitations](docs/semantics.md)
184
+ - [Settings reference](docs/settings.md)
185
+ - [Envelope v1](docs/envelope.md): the JSON document receivers get
186
+ - [Channels](docs/channels.md): webhook config, writing your own channel
187
+ - [Security notes](docs/security.md)
188
+ - [Runners](docs/runners.md): worker loop, cron, Celery
189
+ - [Adopting the app in a service without Celery](docs/without-celery.md)
190
+ - [Upgrade notes](docs/upgrading.md), including migrating from the original in-house app
191
+ - [Changelog](CHANGELOG.md), [Contributing](CONTRIBUTING.md)
192
+
193
+ ## License
194
+
195
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,154 @@
1
+ # django-webhook-outbox
2
+
3
+ Outgoing webhooks for Django models, configured in the Django admin.
4
+
5
+ You pick a model and an event (`insert` or `update`) in the admin and write
6
+ a message template. A poller finds new and changed rows by their
7
+ `created_at` / `updated_at` timestamps and writes them to an outbox table.
8
+ A delivery pass then POSTs each outbox entry as JSON to the channel's URL and
9
+ retries failures.
10
+
11
+ - No database triggers and no signals: any model with `created_at` /
12
+ `updated_at` fields can be tracked, including models of third-party apps.
13
+ - Delivery goes through an outbox table: pending, sent and failed entries are
14
+ visible in the admin, and failed ones can be retried from there.
15
+ - Celery is optional. The core runs from a management command
16
+ (`webhook_outbox_worker`), cron, or any scheduler; `webhook_outbox.contrib.celery`
17
+ provides ready-made tasks if you already use Celery.
18
+ - English and Russian admin.
19
+
20
+ The package was extracted from a production Django service. Release 1.0.0
21
+ keeps that code's behaviour exactly, known limitations included. They are
22
+ listed in [docs/semantics.md](docs/semantics.md); read that page before you
23
+ rely on the package for anything that must not lose or duplicate events.
24
+
25
+ ## Requirements
26
+
27
+ - Python 3.10+
28
+ - Django 4.2, 5.0, 5.1 or 5.2 (CI runs 4.2, 5.0 and 5.2 on PostgreSQL)
29
+ - httpx 0.27+
30
+ - Celery 5.3+ (optional, `[celery]` extra)
31
+
32
+ ## Installation
33
+
34
+ ```console
35
+ pip install django-webhook-outbox
36
+ # or, with the Celery tasks:
37
+ pip install "django-webhook-outbox[celery]"
38
+ ```
39
+
40
+ ```python
41
+ # settings.py
42
+ INSTALLED_APPS = [
43
+ # ...
44
+ "django.contrib.admin",
45
+ "django.contrib.contenttypes",
46
+ "webhook_outbox",
47
+ ]
48
+
49
+ WEBHOOK_OUTBOX = {
50
+ "SITE_URL": "https://shop.example.com", # used by {admin_link}
51
+ }
52
+ ```
53
+
54
+ ```console
55
+ python manage.py migrate webhook_outbox
56
+ ```
57
+
58
+ ## Quick start
59
+
60
+ 1. Make sure the model you want to track has `created_at` (insert events)
61
+ and `updated_at` (update events) fields. The easiest way is to inherit the
62
+ bundled base class:
63
+
64
+ ```python
65
+ from webhook_outbox.models import TimeStampedModel
66
+
67
+ class Order(TimeStampedModel):
68
+ number = models.CharField(max_length=20)
69
+ customer = models.ForeignKey(Customer, on_delete=models.PROTECT)
70
+ ```
71
+
72
+ 2. In the admin, add a **Notification Channel**, type *Webhook*, with this
73
+ config:
74
+
75
+ ```json
76
+ {"url": "https://receiver.example.com/hooks/orders",
77
+ "headers": {"Authorization": "Bearer <token>"},
78
+ "timeout": 10}
79
+ ```
80
+
81
+ 3. Add a **Tracked Table**: model *orders*, event *Insert*, the channel from
82
+ step 2, and a message template:
83
+
84
+ ```text
85
+ New order {number} from {customer.name}
86
+ {admin_link}
87
+ ```
88
+
89
+ 4. Run a worker (see below). The first poll of a tracked table only stores
90
+ its starting point and does not backfill. Orders created after that are
91
+ POSTed to the receiver:
92
+
93
+ ```json
94
+ {
95
+ "event": "insert",
96
+ "source_model": "shop.order",
97
+ "source_pk": "1042",
98
+ "tracked_table": "New orders",
99
+ "message": "New order A-1042 from Acme Corp\nhttps://shop.example.com/admin/shop/order/1042/change/",
100
+ "occurred_at": "2026-08-03T10:00:00.123456+00:00"
101
+ }
102
+ ```
103
+
104
+ A 2xx response marks the entry *sent*. Any other response, a timeout or
105
+ a connection error counts as a failed attempt. After `MAX_RETRIES` (3)
106
+ failed attempts the entry becomes *failed*.
107
+
108
+ ### Running without Celery
109
+
110
+ ```console
111
+ python manage.py webhook_outbox_worker # poll every 30s, deliver every 10s
112
+ python manage.py webhook_outbox_worker --once # one pass, e.g. from cron
113
+ ```
114
+
115
+ Run **one** worker process per database (see
116
+ [limitations](docs/semantics.md#known-limitations)). It stops cleanly on
117
+ SIGTERM/SIGINT. Systemd, Kubernetes and cron examples are in
118
+ [docs/runners.md](docs/runners.md).
119
+
120
+ ### Running with Celery
121
+
122
+ ```python
123
+ # settings.py
124
+ from webhook_outbox.contrib.celery.schedule import beat_schedule
125
+
126
+ INSTALLED_APPS += ["webhook_outbox.contrib.celery"]
127
+
128
+ CELERY_BEAT_SCHEDULE = {
129
+ **beat_schedule(), # poll every 30s, deliver every 10s
130
+ # ... your other entries
131
+ }
132
+
133
+ WEBHOOK_OUTBOX = {
134
+ # "Retry" in the admin pushes the entry to Celery immediately
135
+ "ADMIN_RETRY_HOOK": "webhook_outbox.contrib.celery.tasks.enqueue_single_notification",
136
+ }
137
+ ```
138
+
139
+ ## Documentation
140
+
141
+ - [Concepts](docs/concepts.md): channels, tracked tables, the outbox, the data flow
142
+ - [Semantics and known limitations](docs/semantics.md)
143
+ - [Settings reference](docs/settings.md)
144
+ - [Envelope v1](docs/envelope.md): the JSON document receivers get
145
+ - [Channels](docs/channels.md): webhook config, writing your own channel
146
+ - [Security notes](docs/security.md)
147
+ - [Runners](docs/runners.md): worker loop, cron, Celery
148
+ - [Adopting the app in a service without Celery](docs/without-celery.md)
149
+ - [Upgrade notes](docs/upgrading.md), including migrating from the original in-house app
150
+ - [Changelog](CHANGELOG.md), [Contributing](CONTRIBUTING.md)
151
+
152
+ ## License
153
+
154
+ MIT, see [LICENSE](LICENSE).