pure_eval for Python
Learn about pure_eval and how to add it to your integrations list.
This integration uses pure_eval to safely evaluate additional expressions in the source code and display their values alongside other local variables.
Install sentry-sdk from PyPI with the pure_eval extra or pip install pure_eval executing asttokens.
Copied
pip install "sentry-sdk[pure_eval]"
pip install "sentry-sdk[pure_eval]"
uv add "sentry-sdk[pure_eval]"
Add PureEvalIntegration() to your integrations list:
Copied
import sentry_sdk
from sentry_sdk.integrations.pure_eval import PureEvalIntegration
sentry_sdk.init(
dns="___PUBLIC_DSN___",
# Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected
data_collection={
"user_info": True,
},
integrations=[
PureEvalIntegration(),
],
)
import sentry_sdk
from sentry_sdk.integrations.pure_eval import PureEvalIntegration
sentry_sdk.init(
dns="___PUBLIC_DSN___",
# Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected
data_collection={
"user_info": True,
},
integrations=[
PureEvalIntegration(),
],
)
Copied
from types import SimpleNamespace
def main():
sentry_sdk.init(...) # same as above
namespace = SimpleNamespace()
namespace.d = {1: 2}
print(namespace.d[1] / 0)
main()
from types import SimpleNamespace
def main():
sentry_sdk.init(...) # same as above
namespace = SimpleNamespace()
namespace.d = {1: 2}
print(namespace.d[1] / 0)
main()
When you run this example script an error will be sent to Sentry. Through the PureEvalIntegration the stack trace of the error will include the values of namespace.d and namespace.d[1] which would not be shown without PureEvalIntegration.
- Python:
- 3.6+ (SDK <3.0)
- 3.7+ (SDK 3.0+)
If you're looking to use Sentry with older Python or framework versions, consider using an older major version of the SDK. The minimum versions for each major version are listed above.
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").