Registry / serialization / telepath

telepath

JSON →
library0.3.1pypypi✓ verified 24d ago

Telepath is a Python library designed for exchanging data between Python and JavaScript. It enables Python objects to be packed into primitive types suitable for frontend consumption, typically within a web context. The current version is 0.3.1. Releases are infrequent, usually tied to specific feature additions or compatibility updates, particularly concerning Django versions.

pip install telepath
INSTALL
IMPORT
SIG · TELEPATH
T
telepath
serializationpythonv0.3.1
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Adapter
from telepath import Adapter
from telepath import Adapter

This quickstart demonstrates how to define a custom Python object, create a Telepath adapter for it, register the adapter, and then pack an instance of the object into a JavaScript-compatible format. It also shows how to generate the necessary JavaScript context for the frontend to unpack the data using the companion `telepath-unpack.js` library.

from telepath import Adapter, register, JSContext, pack # 1. Define a custom Python object class MyCustomObject: def __init__(self, message, value): self.message = message self.value = value # 2. Define a Telepath adapter for your custom object class MyCustomObjectAdapter(Adapter): js_constructor = 'telepath.MyCustomObject' def pack(self, obj, context): # Pack the Python object into a list of primitive types return [obj.message, obj.value] # 3. Register the adapter with the custom object register(MyCustomObject, MyCustomObjectAdapter) # 4. Create an instance of your custom object my_instance = MyCustomObject("Hello from Python!", 123) # 5. Create a JSContext and pack the object context = JSContext() packed_data = pack(my_instance, context) print("--- Python Side ---") print(f"Original object: {my_instance.message}, {my_instance.value}") print(f"Packed data: {packed_data}") # The context provides the necessary JavaScript to unpack the data on the frontend. # This script tag should be included in your HTML. print("\n--- Frontend Integration (JavaScript) ---") print("Include this script tag in your HTML header:") print(context.as_script_tag()) print("\nOn the frontend, with telepath-unpack.js loaded, you would then do:") print("// const myUnpackedObject = window.telepath.unpack(packed_data);") print("// console.log(myUnpackedObject.message); // 'Hello from Python!'")
Debug
Known issues
breakingVersion 0.3.1 dropped support for Python versions older than 3.8 and Django versions older than 3.2. Projects on older environments must either upgrade Python/Django or pin telepath to an earlier version.
fix
Upgrade your Python environment to 3.8+ and Django to 3.2+, or restrict your `telepath` dependency to `<0.3.1`.
affects: <0.3.1
gotchaTelepath handles packing Python objects into primitive types. For client-side unpacking, you must include the `telepath-unpack.js` library in your frontend assets.
fix
Ensure `telepath-unpack.js` is loaded in your HTML, typically via a `<script>` tag, before attempting to unpack data on the frontend.
affects: All
gotchaThe `JSContext` object generated on the Python side contains crucial information for the frontend to correctly re-construct your Python objects. Its script tag (`context.as_script_tag()`) must be rendered into your HTML.
fix
Embed the output of `context.as_script_tag()` in the `<head>` or at the start of `<body>` of your HTML page.
affects: All
deprecatedWhile older manual packing methods might still function, Telepath v0.2 and v0.3 introduced and refined an API allowing classes to define their own packing logic (via the `Adapter` class and `pack` method). The recommended approach is to use this dedicated adapter pattern.
fix
Refactor custom object packing logic to use the `telepath.Adapter` class and `register()` function for clearer and more maintainable code.
affects: <0.2
Upgrade
Version history
0.3.1latest on PyPI · released Jun 12, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
1
Resources
telepath — pip install telepath · libregistry