Name | pydantic-gitlab-webhooks JSON |
Version |
0.3.26
JSON |
| download |
home_page | None |
Summary | Pydantic models for GitLab webhook payloads |
upload_time | 2025-01-30 19:11:29 |
maintainer | None |
docs_url | None |
author | Rich Wareham |
requires_python | <4.0,>=3.10 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Pydantic models for GitLab Webhooks
[![PyPI - Version](https://img.shields.io/pypi/v/pydantic-gitlab-webhooks)](https://pypi.org/p/pydantic-gitlab-webhooks/)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pydantic-gitlab-webhooks)
[![GitHub Release](https://img.shields.io/github/v/release/rjw57/pydantic-gitlab-webhooks)](https://github.com/rjw57/pydantic-gitlab-webhooks/releases)
[![Test suite status](https://github.com/rjw57/pydantic-gitlab-webhooks/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/rjw57/pydantic-gitlab-webhooks/actions/workflows/main.yml?query=branch%3Amain)
Module containing Pydantic models for validating bodies from [GitLab webhook
requests](https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html).
## Documentation
The project documentation including an API reference can be found at
[https://rjw57.github.io/pydantic-gitlab-webhooks/](https://rjw57.github.io/pydantic-gitlab-webhooks/).
## Usage example
Intended usage is via a single `validate_event_header_and_body` function which will
validate an incoming webhook's `X-Gitlab-Event` header and the body after being parsed
into a Python dict.
```py
from pydantic import ValidationError
from pydantic_gitlab_webhooks import (
validate_event_body_dict,
validate_event_header_and_body_dict,
)
event_body = {
"object_kind": "access_token",
"group": {
"group_name": "Twitter",
"group_path": "twitter",
"group_id": 35,
"full_path": "twitter"
},
"object_attributes": {
"user_id": 90,
"created_at": "2024-01-24 16:27:40 UTC",
"id": 25,
"name": "acd",
"expires_at": "2024-01-26"
},
"event_name": "expiring_access_token"
}
# Use the value of the "X-Gitlab-Event" header and event body to validate
# the incoming event.
parsed_event = validate_event_header_and_body_dict(
"Resource Access Token Hook",
event_body
)
assert parsed_event.group.full_path == "twitter"
# Invalid event bodies or hook headers raise Pydantic validation errors
try:
validate_event_header_and_body_dict("invalid hook", event_body)
except ValidationError:
pass # ok - expected error raised
else:
assert False, "ValidationError was not raised"
# Event bodies can be parsed without the header hook if necessary although using
# the hook header is more efficient.
parsed_event = validate_event_body_dict(event_body)
assert parsed_event.group.full_path == "twitter"
# Event models may be imported individually. For example:
from pydantic_gitlab_webhooks.events import GroupAccessTokenEvent
parsed_event = GroupAccessTokenEvent.model_validate(event_body)
```
Raw data
{
"_id": null,
"home_page": null,
"name": "pydantic-gitlab-webhooks",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Rich Wareham",
"author_email": "rich.pydantic-gitlab-webhooks@richwareham.com",
"download_url": "https://files.pythonhosted.org/packages/f9/98/807118f51c43ed12d4f733d6a3b155d59b3fe37f98252d9259b3e32eaf15/pydantic_gitlab_webhooks-0.3.26.tar.gz",
"platform": null,
"description": "# Pydantic models for GitLab Webhooks\n\n[![PyPI - Version](https://img.shields.io/pypi/v/pydantic-gitlab-webhooks)](https://pypi.org/p/pydantic-gitlab-webhooks/)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pydantic-gitlab-webhooks)\n[![GitHub Release](https://img.shields.io/github/v/release/rjw57/pydantic-gitlab-webhooks)](https://github.com/rjw57/pydantic-gitlab-webhooks/releases)\n[![Test suite status](https://github.com/rjw57/pydantic-gitlab-webhooks/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/rjw57/pydantic-gitlab-webhooks/actions/workflows/main.yml?query=branch%3Amain)\n\nModule containing Pydantic models for validating bodies from [GitLab webhook\nrequests](https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html).\n\n## Documentation\n\nThe project documentation including an API reference can be found at\n[https://rjw57.github.io/pydantic-gitlab-webhooks/](https://rjw57.github.io/pydantic-gitlab-webhooks/).\n\n## Usage example\n\nIntended usage is via a single `validate_event_header_and_body` function which will\nvalidate an incoming webhook's `X-Gitlab-Event` header and the body after being parsed\ninto a Python dict.\n\n```py\nfrom pydantic import ValidationError\nfrom pydantic_gitlab_webhooks import (\n validate_event_body_dict,\n validate_event_header_and_body_dict,\n)\n\nevent_body = {\n \"object_kind\": \"access_token\",\n \"group\": {\n \"group_name\": \"Twitter\",\n \"group_path\": \"twitter\",\n \"group_id\": 35,\n \"full_path\": \"twitter\"\n },\n \"object_attributes\": {\n \"user_id\": 90,\n \"created_at\": \"2024-01-24 16:27:40 UTC\",\n \"id\": 25,\n \"name\": \"acd\",\n \"expires_at\": \"2024-01-26\"\n },\n \"event_name\": \"expiring_access_token\"\n}\n\n# Use the value of the \"X-Gitlab-Event\" header and event body to validate\n# the incoming event.\nparsed_event = validate_event_header_and_body_dict(\n \"Resource Access Token Hook\",\n event_body\n)\nassert parsed_event.group.full_path == \"twitter\"\n\n# Invalid event bodies or hook headers raise Pydantic validation errors\ntry:\n validate_event_header_and_body_dict(\"invalid hook\", event_body)\nexcept ValidationError:\n pass # ok - expected error raised\nelse:\n assert False, \"ValidationError was not raised\"\n\n# Event bodies can be parsed without the header hook if necessary although using\n# the hook header is more efficient.\nparsed_event = validate_event_body_dict(event_body)\nassert parsed_event.group.full_path == \"twitter\"\n\n# Event models may be imported individually. For example:\nfrom pydantic_gitlab_webhooks.events import GroupAccessTokenEvent\n\nparsed_event = GroupAccessTokenEvent.model_validate(event_body)\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Pydantic models for GitLab webhook payloads",
"version": "0.3.26",
"project_urls": {
"Changelog": "https://github.com/rjw57/pydantic-gitlab-webhooks/blob/main/CHANGELOG.md",
"Documentation": "https://rjw57.github.io/pydantic-gitlab-webhooks",
"Homepage": "https://github.com/rjw57/pydantic-gitlab-webhooks",
"Issues": "https://github.com/rjw57/pydantic-gitlab-webhooks/issues",
"Repository": "https://github.com/rjw57/pydantic-gitlab-webhooks.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "1ccf9b102dd9c54c50925ee008259bc9070cb5dde0e1f6e8ed0a3dd13860be27",
"md5": "9f180f040129edacc62db958ef404409",
"sha256": "812509bfe9c96b651940c0c4b7c12e8643d9451e39858cdda6c7258179f8078c"
},
"downloads": -1,
"filename": "pydantic_gitlab_webhooks-0.3.26-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9f180f040129edacc62db958ef404409",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 12436,
"upload_time": "2025-01-30T19:11:27",
"upload_time_iso_8601": "2025-01-30T19:11:27.137466Z",
"url": "https://files.pythonhosted.org/packages/1c/cf/9b102dd9c54c50925ee008259bc9070cb5dde0e1f6e8ed0a3dd13860be27/pydantic_gitlab_webhooks-0.3.26-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "f998807118f51c43ed12d4f733d6a3b155d59b3fe37f98252d9259b3e32eaf15",
"md5": "2f6f10a3e5d793ddabde2e88d692983e",
"sha256": "51c8c64ced389e6962343e2000f67dc4c5e158c5b48396cb5f07badb0b499d45"
},
"downloads": -1,
"filename": "pydantic_gitlab_webhooks-0.3.26.tar.gz",
"has_sig": false,
"md5_digest": "2f6f10a3e5d793ddabde2e88d692983e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 8974,
"upload_time": "2025-01-30T19:11:29",
"upload_time_iso_8601": "2025-01-30T19:11:29.035418Z",
"url": "https://files.pythonhosted.org/packages/f9/98/807118f51c43ed12d4f733d6a3b155d59b3fe37f98252d9259b3e32eaf15/pydantic_gitlab_webhooks-0.3.26.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-30 19:11:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "rjw57",
"github_project": "pydantic-gitlab-webhooks",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pydantic-gitlab-webhooks"
}