posthoganalytics 6.7.4__tar.gz → 6.7.5__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 (62) hide show
  1. {posthoganalytics-6.7.4/posthoganalytics.egg-info → posthoganalytics-6.7.5}/PKG-INFO +1 -1
  2. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/integrations/django.py +53 -14
  3. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/version.py +1 -1
  4. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5/posthoganalytics.egg-info}/PKG-INFO +1 -1
  5. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/LICENSE +0 -0
  6. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/MANIFEST.in +0 -0
  7. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/README.md +0 -0
  8. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/__init__.py +0 -0
  9. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/__init__.py +0 -0
  10. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/anthropic/__init__.py +0 -0
  11. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/anthropic/anthropic.py +0 -0
  12. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/anthropic/anthropic_async.py +0 -0
  13. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/anthropic/anthropic_converter.py +0 -0
  14. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/anthropic/anthropic_providers.py +0 -0
  15. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/gemini/__init__.py +0 -0
  16. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/gemini/gemini.py +0 -0
  17. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/gemini/gemini_converter.py +0 -0
  18. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/langchain/__init__.py +0 -0
  19. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/langchain/callbacks.py +0 -0
  20. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/openai/__init__.py +0 -0
  21. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/openai/openai.py +0 -0
  22. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/openai/openai_async.py +0 -0
  23. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/openai/openai_converter.py +0 -0
  24. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/openai/openai_providers.py +0 -0
  25. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/sanitization.py +0 -0
  26. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/types.py +0 -0
  27. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/ai/utils.py +0 -0
  28. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/args.py +0 -0
  29. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/client.py +0 -0
  30. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/consumer.py +0 -0
  31. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/contexts.py +0 -0
  32. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/exception_capture.py +0 -0
  33. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/exception_utils.py +0 -0
  34. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/feature_flags.py +0 -0
  35. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/integrations/__init__.py +0 -0
  36. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/poller.py +0 -0
  37. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/py.typed +0 -0
  38. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/request.py +0 -0
  39. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/__init__.py +0 -0
  40. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_before_send.py +0 -0
  41. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_client.py +0 -0
  42. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_consumer.py +0 -0
  43. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_contexts.py +0 -0
  44. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_exception_capture.py +0 -0
  45. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_feature_flag.py +0 -0
  46. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_feature_flag_result.py +0 -0
  47. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_feature_flags.py +0 -0
  48. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_module.py +0 -0
  49. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_request.py +0 -0
  50. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_size_limited_dict.py +0 -0
  51. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_types.py +0 -0
  52. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/test/test_utils.py +0 -0
  53. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/types.py +0 -0
  54. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics/utils.py +0 -0
  55. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics.egg-info/SOURCES.txt +0 -0
  56. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics.egg-info/dependency_links.txt +0 -0
  57. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics.egg-info/requires.txt +0 -0
  58. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/posthoganalytics.egg-info/top_level.txt +0 -0
  59. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/pyproject.toml +0 -0
  60. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/setup.cfg +0 -0
  61. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/setup.py +0 -0
  62. {posthoganalytics-6.7.4 → posthoganalytics-6.7.5}/setup_analytics.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: posthoganalytics
3
- Version: 6.7.4
3
+ Version: 6.7.5
4
4
  Summary: Integrate PostHog into any python application.
5
5
  Home-page: https://github.com/posthog/posthog-python
6
6
  Author: Posthog
@@ -1,10 +1,18 @@
1
1
  from typing import TYPE_CHECKING, cast
2
- from posthoganalytics import contexts, capture_exception
2
+ from posthoganalytics import contexts
3
3
  from posthoganalytics.client import Client
4
4
 
5
+ try:
6
+ from asgiref.sync import iscoroutinefunction
7
+ except ImportError:
8
+ # Fallback for older Django versions
9
+ import asyncio
10
+
11
+ iscoroutinefunction = asyncio.iscoroutinefunction
12
+
5
13
  if TYPE_CHECKING:
6
14
  from django.http import HttpRequest, HttpResponse # noqa: F401
7
- from typing import Callable, Dict, Any, Optional # noqa: F401
15
+ from typing import Callable, Dict, Any, Optional, Union, Awaitable # noqa: F401
8
16
 
9
17
 
10
18
  class PosthogContextMiddleware:
@@ -33,9 +41,24 @@ class PosthogContextMiddleware:
33
41
  frontend. See the documentation for `set_context_session` and `identify_context` for more details.
34
42
  """
35
43
 
44
+ # Django middleware capability flags
45
+ sync_capable = True
46
+ async_capable = True
47
+
36
48
  def __init__(self, get_response):
37
- # type: (Callable[[HttpRequest], HttpResponse]) -> None
38
- self.get_response = get_response
49
+ # type: (Union[Callable[[HttpRequest], HttpResponse], Callable[[HttpRequest], Awaitable[HttpResponse]]]) -> None
50
+ self._is_coroutine = iscoroutinefunction(get_response)
51
+ self._async_get_response = None # type: Optional[Callable[[HttpRequest], Awaitable[HttpResponse]]]
52
+ self._sync_get_response = None # type: Optional[Callable[[HttpRequest], HttpResponse]]
53
+
54
+ if self._is_coroutine:
55
+ self._async_get_response = cast(
56
+ "Callable[[HttpRequest], Awaitable[HttpResponse]]", get_response
57
+ )
58
+ else:
59
+ self._sync_get_response = cast(
60
+ "Callable[[HttpRequest], HttpResponse]", get_response
61
+ )
39
62
 
40
63
  from django.conf import settings
41
64
 
@@ -159,23 +182,39 @@ class PosthogContextMiddleware:
159
182
 
160
183
  def __call__(self, request):
161
184
  # type: (HttpRequest) -> HttpResponse
185
+ # Purely defensive around django's internal sync/async handling - this should be unreachable, but if it's reached, we may
186
+ # as well return something semi-meaningful
187
+ if self._is_coroutine:
188
+ raise RuntimeError(
189
+ "PosthogContextMiddleware received sync call but get_response is async"
190
+ )
191
+
162
192
  if self.request_filter and not self.request_filter(request):
163
- return self.get_response(request)
193
+ assert self._sync_get_response is not None
194
+ return self._sync_get_response(request)
164
195
 
165
196
  with contexts.new_context(self.capture_exceptions, client=self.client):
166
197
  for k, v in self.extract_tags(request).items():
167
198
  contexts.tag(k, v)
168
199
 
169
- return self.get_response(request)
200
+ assert self._sync_get_response is not None
201
+ return self._sync_get_response(request)
170
202
 
171
- def process_exception(self, request, exception):
203
+ async def __acall__(self, request):
204
+ # type: (HttpRequest) -> HttpResponse
172
205
  if self.request_filter and not self.request_filter(request):
173
- return
206
+ if self._async_get_response is not None:
207
+ return await self._async_get_response(request)
208
+ else:
209
+ assert self._sync_get_response is not None
210
+ return self._sync_get_response(request)
174
211
 
175
- if not self.capture_exceptions:
176
- return
212
+ with contexts.new_context(self.capture_exceptions, client=self.client):
213
+ for k, v in self.extract_tags(request).items():
214
+ contexts.tag(k, v)
177
215
 
178
- if self.client:
179
- self.client.capture_exception(exception)
180
- else:
181
- capture_exception(exception)
216
+ if self._async_get_response is not None:
217
+ return await self._async_get_response(request)
218
+ else:
219
+ assert self._sync_get_response is not None
220
+ return self._sync_get_response(request)
@@ -1,4 +1,4 @@
1
- VERSION = "6.7.4"
1
+ VERSION = "6.7.5"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  print(VERSION, end="") # noqa: T201
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: posthoganalytics
3
- Version: 6.7.4
3
+ Version: 6.7.5
4
4
  Summary: Integrate PostHog into any python application.
5
5
  Home-page: https://github.com/posthog/posthog-python
6
6
  Author: Posthog