Skip to main content

Reflectivipy: A Python Implementation of the Reflectivity API from the Pharo language

Downloads

Reflectivipy is an API inspired by Reflectivity in Pharo. Reflectivity allows you to deal with partial behavioral reflection in Python by letting you install MetaLink directly on method AST nodes. Moreover, Reflectivity provides object-centric capabilities and let you install a modified behavior on a dedicated object.

Let see how to install a link on a method AST towards a meta-object:

import reflectivipy


# We define a new meta-object that will act as a logger
# each time a dedicated AST node will be "visited/executed"
class MetaLogger(object):
  def log_me(self):
    print("I'm here")


# Here is the class we will instrument
class ExampleClass(object):
  def foo(self):
    print('Executing foo')


# We create a link ('control' is 'before' by default)
link = reflectivipy.MetaLink(MetaLogger(), selector='log_me', control='before')

# We get the method AST we want to instrument
rf_ast = reflectivipy.reflective_ast_for_method(ExampleClass, 'foo')

# We select the node that we want to install the link on
# Here we selected the "print 'Executing foo'" AST node.
node = rf_ast.body[0].body[0]

# We install the link on the node
reflectivipy.link(link, node)

a = ExampleClass()
a.foo()

# When we don't need it anymore, we remove it
print('Uninstall Metalink')
link.uninstall()

a.foo()

# Produces:
#
# I'm here
# Executing foo
# Uninstall Metalink
# Executing foo

This small code example uses the two main Reflectivipy concepts:

  • the meta-object definition, i.e: the object that will own the behavior to add

  • the MetaLink in itself which link the meta-object to the AST node that must be modified.

The MetaLink link is used to install a new behavior before the code associated to the AST node on which it will be installed. The method AST is then gathered using the reflective_ast_for_method function. The desired AST node is gathered (here it’s the print node). Finally, the node and the meta-behavior are linked together using the link function. Once the new meta-behavior is not required anymore, the uninstall method of the created link is called. This call uninstall the link from every node it could be installed on.

On top of that, meta-behavior can be installed for a dedicated instance instead of a class. To do that, it’s just a matter of asking for the reflective_ast_for_method of the instance instead of the one from the class. The code remains then exactly the same.

Installation

Currently, Reflectivity is now on pypi, so you can install it using pip. It is recommanded to install it in the virtualenv.

$ pip install reflectivipy

Quick Start

Contributors

Metadata

Release files for reflectivipy 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for reflectivipy 0.1.1
File Size Uploaded Provenance
reflectivipy-0.1.1.tar.gz 10.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for reflectivipy 0.1.1
File Interpreter ABI Platform
reflectivipy-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 24.0 kB

Release files / reflectivipy-0.1.1.tar.gz

Download URL reflectivipy-0.1.1.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
db3f85f28845fe3ef977ff07c6501f26a5c697015c0dd194cf7b8c8831485ae3
BLAKE2b-256 checksum
How to use checksums
1e71fa571718677f557037dd5890457e9b72bf43e28116e904d93fb07ae71ead
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.1

Release files / reflectivipy-0.1.1-py3-none-any.whl

Download URL reflectivipy-0.1.1-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08fc7ec6b76186e06ddc4058e9f30066977cd9ef2951fc224f48988fc415813a
BLAKE2b-256 checksum
How to use checksums
14e1b1ef3b9857b57d3ba266753342c0748a96fc28ff3c489acf969e17e5ca8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.1

Security for reflectivipy 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page