Skip to content

Commit

Permalink
Merge branch 'master' into package-rename
Browse files Browse the repository at this point in the history
  • Loading branch information
n0str committed Jan 10, 2025
2 parents c2e0d67 + 09a3f19 commit 8989246
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Parameters:

## Requirements

- Python \>= 3.9
- Python \>= 3.10
- requests

## Links
Expand Down
11 changes: 6 additions & 5 deletions docs/fastapi.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Flask integration
# FastAPI integration

This extension adds support for the [FastAPI](https://fastapi.tiangolo.com/) web framework.

Expand All @@ -12,15 +12,16 @@ import Catcher module to your project.

```python
from hawk_python_sdk.modules.fastapi import HawkFastapi
from hawk_python_sdk.modules.fastapi import HawkFastapi
```

```python
app = FastAPI()

hawk = HawkFastapi(
hawk = HawkFastapi({
'app_instance': app,
'token': '1234567-abcd-8901-efgh-123456789012'
)
})
```

Now all global fastapi errors would be sent to Hawk.
Expand Down Expand Up @@ -60,10 +61,10 @@ To init Hawk Catcher just pass a project token and FastAPI app instance.
```python
app = FastAPI()

hawk = HawkFastapi(
hawk = HawkFastapi({
'app_instance': app,
'token': '1234567-abcd-8901-efgh-123456789012'
)
})
```

### Additional params
Expand Down
1 change: 1 addition & 0 deletions docs/flask.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Catcher module to your project.

```python
from hawk_python_sdk.modules.flask import HawkFlask
from hawk_python_sdk.modules.flask import HawkFlask
```

```python
Expand Down
15 changes: 15 additions & 0 deletions example/example3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import hawk_python_sdk


hawk_python_sdk.init({
'token':'eyJpbnRlZ3JhdGlvbklkIjoiY2YxYzVhZGEtNzllOC00YWQ1LWFmYTQtNGMzZjI3Y2UzNWRiIiwic2VjcmV0IjoiZjk4NTc5ZTMtNGZmMy00YmVlLThjYzEtOWVlMDY0ZjU4YTRjIn0=',
'release': '3.12.4'
})
hawk_python_sdk.send(
event=Exception("Something went wrong"),
context={
'ip': '192.168.1.1'
},
user={'id': 2, 'name': 'Bob'}
)
print('Event sent successfully')
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ name = "hawk-python-sdk"
authors = [{ name = "CodeX Team", email = "[email protected]" }]
description = "Python errors Catcher module for Hawk."
readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.10"
classifiers = [
"Intended Audience :: Developers",
"Topic :: Software Development :: Bug Tracking",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.10",
"Environment :: Console",
"Environment :: Web Environment",
]
[project.optional-dependencies]
flask = ["flask"]
fastapi = ["starlette"]
fastapi = ["fastapi"]
[tool.hatch.version]
path = "src/hawk_python_sdk/__init__.py"
[project.urls]
Expand Down
2 changes: 1 addition & 1 deletion src/hawk_python_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "3.5.1"
__version__ = "3.5.2"

from .core import Hawk
from .types import HawkCatcherSettings
Expand Down
28 changes: 23 additions & 5 deletions src/hawk_python_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,34 @@ class User(TypedDict):
image: str # User's public picture
url: str # URL for user's details page

class HawkCatcherSettings(TypedDict, Generic[T]):
"""Settings for Hawk catcher for errors tracking"""

class HawkCatcherSettings(Generic[T]):
"""Base settings for Hawk catcher for errors tracking"""
token: str # Hawk integration token
collector_endpoint: str # Collector endpoint for sending event to
release: str # Release name for Suspected Commits feature
before_send: Callable[[dict], None] # This hook allows you to filter any data you don't want sending to Hawk
context: dict # Additional context to be send with event
with_addons: bool = True # This parameter points if you want to send framework data with error (cookies, headers, params, form, json)
set_user: Callable[[T], User] # This hook allows you to set user information, this hook is useful for frameworks
with_addons: bool # This parameter points if you want to send framework data with error (cookies, headers, params, form, json)

def __init__(
self,
*,
token: str,
collector_endpoint: str,
release: str,
before_send: Callable[[dict], None],
context: dict,
with_addons: bool,
set_user: Callable[[T], User]
):
self.token = token
self.collector_endpoint = collector_endpoint
self.release = release
self.before_send = before_send
self.context = context
self.with_addons = with_addons
self.set_user = set_user


class Addons(TypedDict):
"""Additional data to be send with event due to frameworks"""
Expand Down

0 comments on commit 8989246

Please sign in to comment.