posthoganalytics 6.9.3__py3-none-any.whl → 7.0.1__py3-none-any.whl

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.
@@ -1,8 +1,8 @@
1
1
  try:
2
- import langchain # noqa: F401
2
+ import langchain_core # noqa: F401
3
3
  except ImportError:
4
4
  raise ModuleNotFoundError(
5
- "Please install LangChain to use this feature: 'pip install langchain'"
5
+ "Please install LangChain to use this feature: 'pip install langchain-core'"
6
6
  )
7
7
 
8
8
  import json
@@ -295,8 +295,9 @@ class Client(object):
295
295
  # to call flush().
296
296
  if send:
297
297
  atexit.register(self.join)
298
- for n in range(thread):
299
- self.consumers = []
298
+
299
+ self.consumers = []
300
+ for _ in range(thread):
300
301
  consumer = Consumer(
301
302
  self.queue,
302
303
  self.api_key,
@@ -969,19 +969,30 @@ def _serialize_variable_value(value, limiter, max_length=1024):
969
969
  return result
970
970
  except Exception:
971
971
  try:
972
- fallback = f"<{type(value).__name__}>"
973
- fallback_size = len(fallback)
974
- if not limiter.can_add(fallback_size):
972
+ result = repr(value)
973
+ if len(result) > max_length:
974
+ result = result[: max_length - 3] + "..."
975
+
976
+ result_size = len(result)
977
+ if not limiter.can_add(result_size):
975
978
  return None
976
- limiter.add(fallback_size)
977
- return fallback
979
+ limiter.add(result_size)
980
+ return result
978
981
  except Exception:
979
- fallback = "<unserializable object>"
980
- fallback_size = len(fallback)
981
- if not limiter.can_add(fallback_size):
982
- return None
983
- limiter.add(fallback_size)
984
- return fallback
982
+ try:
983
+ fallback = f"<{type(value).__name__}>"
984
+ fallback_size = len(fallback)
985
+ if not limiter.can_add(fallback_size):
986
+ return None
987
+ limiter.add(fallback_size)
988
+ return fallback
989
+ except Exception:
990
+ fallback = "<unserializable object>"
991
+ fallback_size = len(fallback)
992
+ if not limiter.can_add(fallback_size):
993
+ return None
994
+ limiter.add(fallback_size)
995
+ return fallback
985
996
 
986
997
 
987
998
  def _is_simple_type(value):
@@ -96,7 +96,7 @@ def test_code_variables_capture(tmpdir):
96
96
  assert b"'my_number': 42" in output
97
97
  assert b"'my_bool': 'True'" in output
98
98
  assert b'"my_dict": "{\\"name\\": \\"test\\", \\"value\\": 123}"' in output
99
- assert b'"my_obj": "<UnserializableObject>"' in output
99
+ assert b"<__main__.UnserializableObject object at" in output
100
100
  assert b"'my_password': '$$_posthog_redacted_based_on_masking_rules_$$'" in output
101
101
  assert b"'__should_be_ignored':" not in output
102
102
 
@@ -332,3 +332,77 @@ def test_code_variables_enabled_then_disabled_in_context(tmpdir):
332
332
  assert '"code_variables":' not in output
333
333
  assert "'my_var'" not in output
334
334
  assert "'important_value'" not in output
335
+
336
+
337
+ def test_code_variables_repr_fallback(tmpdir):
338
+ app = tmpdir.join("app.py")
339
+ app.write(
340
+ dedent(
341
+ """
342
+ import os
343
+ import re
344
+ from datetime import datetime, timedelta
345
+ from decimal import Decimal
346
+ from fractions import Fraction
347
+ from posthoganalytics import Posthog
348
+
349
+ class CustomReprClass:
350
+ def __repr__(self):
351
+ return '<CustomReprClass: custom representation>'
352
+
353
+ posthog = Posthog(
354
+ 'phc_x',
355
+ host='https://eu.i.posthog.com',
356
+ debug=True,
357
+ enable_exception_autocapture=True,
358
+ capture_exception_code_variables=True,
359
+ project_root=os.path.dirname(os.path.abspath(__file__))
360
+ )
361
+
362
+ def trigger_error():
363
+ my_regex = re.compile(r'\\d+')
364
+ my_datetime = datetime(2024, 1, 15, 10, 30, 45)
365
+ my_timedelta = timedelta(days=5, hours=3)
366
+ my_decimal = Decimal('123.456')
367
+ my_fraction = Fraction(3, 4)
368
+ my_set = {1, 2, 3}
369
+ my_frozenset = frozenset([4, 5, 6])
370
+ my_bytes = b'hello bytes'
371
+ my_bytearray = bytearray(b'mutable bytes')
372
+ my_memoryview = memoryview(b'memory view')
373
+ my_complex = complex(3, 4)
374
+ my_range = range(10)
375
+ my_custom = CustomReprClass()
376
+ my_lambda = lambda x: x * 2
377
+ my_function = trigger_error
378
+
379
+ 1/0
380
+
381
+ trigger_error()
382
+ """
383
+ )
384
+ )
385
+
386
+ with pytest.raises(subprocess.CalledProcessError) as excinfo:
387
+ subprocess.check_output([sys.executable, str(app)], stderr=subprocess.STDOUT)
388
+
389
+ output = excinfo.value.output.decode("utf-8")
390
+
391
+ assert "ZeroDivisionError" in output
392
+ assert "code_variables" in output
393
+
394
+ assert "re.compile(" in output and "\\\\d+" in output
395
+ assert "datetime.datetime(2024, 1, 15, 10, 30, 45)" in output
396
+ assert "datetime.timedelta(days=5, seconds=10800)" in output
397
+ assert "Decimal('123.456')" in output
398
+ assert "Fraction(3, 4)" in output
399
+ assert "{1, 2, 3}" in output
400
+ assert "frozenset({4, 5, 6})" in output
401
+ assert "b'hello bytes'" in output
402
+ assert "bytearray(b'mutable bytes')" in output
403
+ assert "<memory at" in output
404
+ assert "(3+4j)" in output
405
+ assert "range(0, 10)" in output
406
+ assert "<CustomReprClass: custom representation>" in output
407
+ assert "<lambda>" in output
408
+ assert "<function trigger_error at" in output
@@ -1,4 +1,4 @@
1
- VERSION = "6.9.3"
1
+ VERSION = "7.0.1"
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.9.3
3
+ Version: 7.0.1
4
4
  Summary: Integrate PostHog into any python application.
5
5
  Home-page: https://github.com/posthog/posthog-python
6
6
  Author: Posthog
@@ -15,12 +15,11 @@ Classifier: Intended Audience :: Developers
15
15
  Classifier: Operating System :: OS Independent
16
16
  Classifier: License :: OSI Approved :: MIT License
17
17
  Classifier: Programming Language :: Python
18
- Classifier: Programming Language :: Python :: 3.9
19
18
  Classifier: Programming Language :: Python :: 3.10
20
19
  Classifier: Programming Language :: Python :: 3.11
21
20
  Classifier: Programming Language :: Python :: 3.12
22
21
  Classifier: Programming Language :: Python :: 3.13
23
- Requires-Python: >=3.9
22
+ Requires-Python: >=3.10
24
23
  Description-Content-Type: text/markdown
25
24
  License-File: LICENSE
26
25
  Requires-Dist: requests<3.0,>=2.7
@@ -58,13 +57,13 @@ Requires-Dist: pytest; extra == "test"
58
57
  Requires-Dist: pytest-timeout; extra == "test"
59
58
  Requires-Dist: pytest-asyncio; extra == "test"
60
59
  Requires-Dist: django; extra == "test"
61
- Requires-Dist: openai; extra == "test"
62
- Requires-Dist: anthropic; extra == "test"
63
- Requires-Dist: langgraph>=0.4.8; extra == "test"
64
- Requires-Dist: langchain-core>=0.3.65; extra == "test"
65
- Requires-Dist: langchain-community>=0.3.25; extra == "test"
66
- Requires-Dist: langchain-openai>=0.3.22; extra == "test"
67
- Requires-Dist: langchain-anthropic>=0.3.15; extra == "test"
60
+ Requires-Dist: openai>=2.0; extra == "test"
61
+ Requires-Dist: anthropic>=0.72; extra == "test"
62
+ Requires-Dist: langgraph>=1.0; extra == "test"
63
+ Requires-Dist: langchain-core>=1.0; extra == "test"
64
+ Requires-Dist: langchain-community>=0.4; extra == "test"
65
+ Requires-Dist: langchain-openai>=1.0; extra == "test"
66
+ Requires-Dist: langchain-anthropic>=1.0; extra == "test"
68
67
  Requires-Dist: google-genai; extra == "test"
69
68
  Requires-Dist: pydantic; extra == "test"
70
69
  Requires-Dist: parameterized>=0.8.1; extra == "test"
@@ -105,8 +104,8 @@ We recommend using [uv](https://docs.astral.sh/uv/). It's super fast.
105
104
  ## PostHog recommends `uv` so...
106
105
 
107
106
  ```bash
108
- uv python install 3.9.19
109
- uv python pin 3.9.19
107
+ uv python install 3.12
108
+ uv python pin 3.12
110
109
  uv venv
111
110
  source env/bin/activate
112
111
  uv sync --extra dev --extra test
@@ -1,17 +1,17 @@
1
1
  posthoganalytics/__init__.py,sha256=cEfWzFRmhHhtQs4Tl3yZoV0um7Wr-pkQzzfttuh4nYQ,27903
2
2
  posthoganalytics/args.py,sha256=iZ2JWeANiAREJKhS-Qls9tIngjJOSfAVR8C4xFT5sHw,3307
3
- posthoganalytics/client.py,sha256=BrVlQWWqh7h-9MtIFFeHvDGWx5X4wVk5vkzkqsTWnHU,74202
3
+ posthoganalytics/client.py,sha256=Ms2gpeP8iJV19nsfqqMpMs47lEM8ULf-NPGiGyAHfg8,74199
4
4
  posthoganalytics/consumer.py,sha256=CiNbJBdyW9jER3ZYCKbX-JFmEDXlE1lbDy1MSl43-a0,4617
5
5
  posthoganalytics/contexts.py,sha256=Qj8eprL71IVGo4nMtHCs7kIEhezOmxfkYpiPTg-rWjU,12618
6
6
  posthoganalytics/exception_capture.py,sha256=1VHBfffrXXrkK0PT8iVgKPpj_R1pGAzG5f3Qw0WF79w,1783
7
- posthoganalytics/exception_utils.py,sha256=uBSm03agMQW0fr4v5CXvcGTkc-QFOHK-cuIrlE4ClJ4,31867
7
+ posthoganalytics/exception_utils.py,sha256=Hs9lrixYPe8nKW8I7SUjNFUkkJh0C09cunKcXW0evCg,32273
8
8
  posthoganalytics/feature_flags.py,sha256=yHjiH6LSvhQgurbsPCHUdGakZKvkzOLdqB8vL3iyhmw,22544
9
9
  posthoganalytics/poller.py,sha256=jBz5rfH_kn_bBz7wCB46Fpvso4ttx4uzqIZWvXBCFmQ,595
10
10
  posthoganalytics/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  posthoganalytics/request.py,sha256=Bsl2c5WwONKPQzwWMmKPX5VgOlwSiIcSNfhXgoz62Y8,6186
12
12
  posthoganalytics/types.py,sha256=Dl3aFGX9XUR0wMmK12r2s5Hjan9jL4HpQ9GHpVcEq5U,10207
13
13
  posthoganalytics/utils.py,sha256=-0w-OLcCaoldkbBebPzQyBzLJSo9G9yBOg8NDVz7La8,16088
14
- posthoganalytics/version.py,sha256=5rEsdm1qsSDo24xnSDirThtR5UCUG8ArSvCHK4-Nk3c,87
14
+ posthoganalytics/version.py,sha256=ZfiYBXIQYezxNQNk7A-r-5eweGxqiibXq2GrABvtV2Y,87
15
15
  posthoganalytics/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  posthoganalytics/ai/sanitization.py,sha256=owipZ4eJYtd4JTI-CM_klatclXaeaIec3XJBOUfsOnQ,5770
17
17
  posthoganalytics/ai/types.py,sha256=arX98hR1PIPeJ3vFikxTlACIh1xPp6aEUw1gBLcKoB0,3273
@@ -25,7 +25,7 @@ posthoganalytics/ai/gemini/__init__.py,sha256=JV_9-gBR87leHgZW4XAYZP7LSl4YaXeuhq
25
25
  posthoganalytics/ai/gemini/gemini.py,sha256=A2acjT_m8ru2YwgIk15aN21CRVEl2jh8pbqjmHplMC8,15035
26
26
  posthoganalytics/ai/gemini/gemini_converter.py,sha256=lfd-AqBYdM3_OJtuvkFb9AlSba1gQt4K5TpKqzXykdk,18749
27
27
  posthoganalytics/ai/langchain/__init__.py,sha256=9CqAwLynTGj3ASAR80C3PmdTdrYGmu99tz0JL-HPFgI,70
28
- posthoganalytics/ai/langchain/callbacks.py,sha256=Mzqmb9kC6v-ZAy5KkguIgfs-2xzQqYE2YJsVmBnH_3M,31393
28
+ posthoganalytics/ai/langchain/callbacks.py,sha256=IXd7-fqc9qojAN2VcMNFsSn7iDNigKa6M4wqqesNUOM,31403
29
29
  posthoganalytics/ai/openai/__init__.py,sha256=u4OuUT7k1NgFj0TrxjuyegOg7a_UA8nAU6a-Hszr0OM,490
30
30
  posthoganalytics/ai/openai/openai.py,sha256=I05NruE9grWezM_EgOZBiG5Ej_gABsDcYKN0pRQWvzU,20235
31
31
  posthoganalytics/ai/openai/openai_async.py,sha256=mIxFZykDgMi3ws_fNWikEhwvkZmKqfYgeeB2yhxlZjQ,22490
@@ -38,7 +38,7 @@ posthoganalytics/test/test_before_send.py,sha256=A1_UVMewhHAvO39rZDWfS606vG_X-q0
38
38
  posthoganalytics/test/test_client.py,sha256=e1dD9bFplZWROiP35fuyBDguGXC6ZmG5j79Iw2t_NBw,96363
39
39
  posthoganalytics/test/test_consumer.py,sha256=HGMfU9PzQ5ZAe_R3kHnZNsMvD7jUjHL-gie0isrvMMk,7107
40
40
  posthoganalytics/test/test_contexts.py,sha256=c--hNUIEf6SHQ7H9vdPhU1oLCN0SnD4wDbFr-eLPHDo,7013
41
- posthoganalytics/test/test_exception_capture.py,sha256=i-979ZHfi1KGndhyEkKLRrYVtpUI7OfpE9U8VsNinmU,8993
41
+ posthoganalytics/test/test_exception_capture.py,sha256=K_uynP4U4gEhsDzASyb9kpSwghTO_BPIUirPYCFKeKs,11368
42
42
  posthoganalytics/test/test_feature_flag.py,sha256=9RQwB5eCvVAGrrO7UnR3Z1OidP_YoL4iBl3A83fuAig,6824
43
43
  posthoganalytics/test/test_feature_flag_result.py,sha256=z2OgD97r85LKMqCnoCqAs74WjUMucayAtC3qWaITGCA,15898
44
44
  posthoganalytics/test/test_feature_flags.py,sha256=b0CcW2JyBRhOxlWX9KOBncqL7OG_VHFX3Z4J6VOlPNs,217352
@@ -47,8 +47,8 @@ posthoganalytics/test/test_request.py,sha256=Zc0VbkjpVmj8mKokQm9rzdgTr0b1U44vvMY
47
47
  posthoganalytics/test/test_size_limited_dict.py,sha256=-5IQjIEr_-Dql24M0HusdR_XroOMrtgiT0v6ZQCRvzo,774
48
48
  posthoganalytics/test/test_types.py,sha256=bRPHdwVpP7hu7emsplU8UVyzSQptv6PaG5lAoOD_BtM,7595
49
49
  posthoganalytics/test/test_utils.py,sha256=sqUTbfweVcxxFRd3WDMFXqPMyU6DvzOBeAOc68Py9aw,9620
50
- posthoganalytics-6.9.3.dist-info/licenses/LICENSE,sha256=wGf9JBotDkSygFj43m49oiKlFnpMnn97keiZKF-40vE,2450
51
- posthoganalytics-6.9.3.dist-info/METADATA,sha256=CUD6Yt6SFR-tuLWgpPrb0N9kAkdWg7-7sCIO5U9aWAY,6024
52
- posthoganalytics-6.9.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
53
- posthoganalytics-6.9.3.dist-info/top_level.txt,sha256=8QsNIqIkBh1p2TXvKp0Em9ZLZKwe3uIqCETyW4s1GOE,17
54
- posthoganalytics-6.9.3.dist-info/RECORD,,
50
+ posthoganalytics-7.0.1.dist-info/licenses/LICENSE,sha256=wGf9JBotDkSygFj43m49oiKlFnpMnn97keiZKF-40vE,2450
51
+ posthoganalytics-7.0.1.dist-info/METADATA,sha256=1-qRi7mQFUPA38W-YFrAQUZOcTefspYgQlJFF8TWxoY,5968
52
+ posthoganalytics-7.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
53
+ posthoganalytics-7.0.1.dist-info/top_level.txt,sha256=8QsNIqIkBh1p2TXvKp0Em9ZLZKwe3uIqCETyW4s1GOE,17
54
+ posthoganalytics-7.0.1.dist-info/RECORD,,