Skip to main content

Runtime AOP injection for Python — intercept and modify local variables at any execution point

Project description

pytrace-inject: Runtime AOP injection for Python.

A lightweight framework that lets you intercept and modify local variables at any execution point of a target function, using sys.settrace.

Quick Start

import random
from pytrace_inject import At, inject, start_trace, end_trace

@inject(At(random.randrange).atcall())
def modify(start, end):
    start, end = 42, 43
    return {'start': start, 'end': end}

start_trace()
print(random.randrange(100, 999))  # Output: 42
end_trace()

Key Concepts

  • At — Where to inject (call time / return time / specific line / custom condition).
  • Tracer — The active injection, can be .remove()'d at any time.
  • Callback — Your function that receives current local variables and returns a dict of replacements (or None).

License

MIT — see LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytrace_inject-0.2.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytrace_inject-0.2.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file pytrace_inject-0.2.0.tar.gz.

File metadata

  • Download URL: pytrace_inject-0.2.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pytrace_inject-0.2.0.tar.gz
Algorithm Hash digest
SHA256 55e46f4d67f7093645822e7d529bedc76a8c5b30fa89e714bf236a10ad43615e
MD5 185ea5663394feec71d0301d1af68fe9
BLAKE2b-256 74baff2b4bf240ab282272730861a0e4a3707dfa1f6bd6d9f3d9660e039a3278

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytrace_inject-0.2.0.tar.gz:

Publisher: python-publish.yml on YuYi-09/pytrace-inject

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytrace_inject-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pytrace_inject-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pytrace_inject-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a53946411220d0e226169a61c85ab036a12e6165a3c37999ca9f6717f516e8d
MD5 cc7dd0db85ec7ebac9dda42ee04062f4
BLAKE2b-256 0e85279cc1170bc8617c56b71e02a2159bef672e9614726ae14ebeb2b213d8e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytrace_inject-0.2.0-py3-none-any.whl:

Publisher: python-publish.yml on YuYi-09/pytrace-inject

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page