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.1.3.tar.gz (4.7 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.1.3-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytrace_inject-0.1.3.tar.gz
  • Upload date:
  • Size: 4.7 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.1.3.tar.gz
Algorithm Hash digest
SHA256 07f5a85f9ab8b500293e57fb929dcfc265a4aff8e84c4103fcdc97255eb8d9cd
MD5 e4e7ff1ddda5ecdefaf7944749b3423d
BLAKE2b-256 068b830c3f644e4a7a82f42841a699a9fac616e9ab17eed41caac9aefe0ed11a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytrace_inject-0.1.3.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.1.3-py3-none-any.whl.

File metadata

  • Download URL: pytrace_inject-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.1 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.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3ea52f9d7c9bf0b160b38af704f9132a5b5fbff0e5c1fd54e5f712e67b5121d6
MD5 86f3b365a08620b3eb263b6e642aa3d8
BLAKE2b-256 2ca231a7dc8b608d2328e1c42aa3bdc91894fe488dbd80299ea2048c8ff43a80

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytrace_inject-0.1.3-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