Skip to content

Latest commit

 

History

History
84 lines (72 loc) · 2.89 KB

README.md

File metadata and controls

84 lines (72 loc) · 2.89 KB

sentry-api-python

PyPI Python License

This project aims to simplify communication with Sentry REST API.

It is in quite early stage, our approach is simple. We cover first endpoints that we use for our tools. But new PRs are more than welcome.

Installation

pip install sentry-api-python

Example of use

Create project

from sentry_api.api import SentryApi

sentry_api = SentryApi(
    organization_slug="my-org",
    token="<Your Auth Token https://docs.sentry.io/api/auth/>",
)
response = sentry_api.projects.create(
    team_slug="backend",
    project=dict(name="My first project")
)

Create alert with Slack + Linear integration

from sentry_api.api import SentryApi

sentry_api = SentryApi(
    organization_slug="my-org",
    token="<Your Auth Token https://docs.sentry.io/api/auth/>",
    endpoint_url="https://sentry.io/api/0/",
)

response = sentry_api.project_rules.create(
    project_slug="my-first-project",
    rule={
        "name": "Prod issues",
        "owner": "team:<id of team>",
        "environment": "prod",
        "actionMatch": "any",
        "filterMatch": "all",
        "frequency": 10080,  # One week
        "conditions": [
            {"id": "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition"},
            {"id": "sentry.rules.conditions.regression_event.RegressionEventCondition"},
        ],
        "actions": [
            {
                "workspace": "<slack workspace>",
                "id": "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
                "channel": "#alerts-production",
                "channel_id": "<https://docs.sentry.io/product/integrations/notification-incidents/slack/#rate-limiting-error>",
            },
            {
                "id": "sentry.rules.actions.notify_event_sentry_app.NotifyEventSentryAppAction",
                "sentryAppInstallationUuid": "<app installation here>",
                "settings": [
                    {"name": "teamId", "value": "<linear team id>"},
                    {"name": "assigneeId", "value": ""},
                    {"name": "labelId", "value": "<label id>"},
                    {"name": "projectId", "value": ""},
                    {"name": "stateId", "value": "<state id>"},
                    {"name": "priority", "value": "1"},
                ],
                "hasSchemaFormConfig": True,
            },
        ],
    },
)
print(response.json())