# Recipe: Passing Objects from PyScript to JavaScript (and vice versa)

**URL:** <https://forum.anaconda.com/t/recipe-passing-objects-from-pyscript-to-javascript-and-vice-versa/31810>\
**Category:** PyScript\
**Tags:** pyscript\
**Created:** [August 21, 2022, 9:51pm UTC](https://forum.anaconda.com/t/recipe-passing-objects-from-pyscript-to-javascript-and-vice-versa/31810 "2022-08-21T21:51:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeffGlass](https://dub1.discourse-cdn.com/anaconda/user_avatar/forum.anaconda.com/jeffglass/32/1301_2.png) [@JeffGlass](https://forum.anaconda.com/u/JeffGlass)\
**Post date:** [August 21, 2022, 9:51pm UTC](https://forum.anaconda.com/t/recipe-passing-objects-from-pyscript-to-javascript-and-vice-versa/31810/1 "2022-08-21T21:51:19Z")

</div>

Part of the magic of the Pyodide runtime that PyScript uses is the ability to pass objects back and forth between JavaScript and Python more or less directly. But what exactly the syntax is for doing so isn’t necessarily obvious to new PyScript users.

I’ve written up four recipes to help illustrate this, for passing objects:

- From JavaScript to Python (in Pyodide)
- From JavaScript to Python (in PyScript)
- From Python (in Pyodide) to JavaScript
- From Python (in PyScript) to JavaScript

> **[Pyscript/Pyodide and JS Object Passing](https://jeff.glass/post/pyscript-js-functions/)**
>
> How to Pass Objects from Python to JavaScript and Back

~~Due to some current implementation details, the last option isn’t quite as straightforward as it could be; I suspect it will only get easier as PyScript evolves, but I wanted to share a method that works in the current version of PyScript (2022.06.1) for those who need it.~~

Edit: Like any good blog post, I thought of a better solution to the last problem immediately after posting. The post has now been updated, but to summarize: we can use a JavaScript function to export the Python global namespace from PyScript as a dictionary. This allows JavaScript to dynamically access any variable created in Python.

---

<div class="post-metadata">

**Author:** ![john.hanley](https://dub1.discourse-cdn.com/anaconda/user_avatar/forum.anaconda.com/john.hanley/32/1294_2.png) [@john.hanley](https://forum.anaconda.com/u/john.hanley)\
**Post date:** [August 22, 2022, 7:30pm UTC](https://forum.anaconda.com/t/recipe-passing-objects-from-pyscript-to-javascript-and-vice-versa/31810/2 "2022-08-22T19:30:39Z")

</div>

Very good article. We should create a sticky post with links to good sites for PyScript and Pyodide articles.
