Skip to main content

jy

Tools to control JS from Python.

(jy stands for "Js pY" or "Js python proxY".)

To install: pip install jy

Documentation

Example

Say you have the test01.js (whose contents are displayed in the next subsection).

from jy import add_js_funcs
js = add_js_funcs("./test01.js")

js has two methods called bar and foo

assert sorted([x for x in dir(js) if not x.startswith('_')]) == [
    'add_one', 'bar', 'foo', 'obj', 'prop', 'with_arrow_func', 'with_let'
]

They mirror the signatures of the underlying JS functions

from inspect import signature
assert str(signature(js.foo)) == "(a, b='hello', c=3)"
assert str(signature(js.bar)) == "(green, eggs='food', and=True, /, ham=4)"

(and is a Python keyword, so it -- and every parameter before it -- is exposed as positional-only, hence the /. You can never pass and=... by keyword from Python anyway.)

Calling this function returns a string (the code to call the underlying JS function)

assert js.foo(1, 'hi', 5) == 'foo(1, "hi", 5)'

Notice that you can use positional or keyword arguments Also, notice that though "prop" is the name of js's attribute, the function call string does indeed use the original full reference: func.assigned.to.nested.prop

assert js.prop('up') == (
    'func.assigned.to.nested.prop("up")'
)

Notice that the python (signature) defaults are applied before translating to JS

assert js.bar(42) == 'bar(42, "food", true, 4)'
alt_js = add_js_funcs("./test01.js", apply_defaults=False)

You can opt not to do this by specifying apply_defaults=False This will result in only injecting those inputs you specify in the js call string, which will have the effect of letting JS apply its defaults, what ever they are

alt_js = add_js_funcs("./test01.js", apply_defaults=False)
assert alt_js.bar(42) == 'bar(42)'

Appendix

The test01.js file's contents

// "test01.js" file
// Straight function definition
function foo(a, b="hello", c= 3) {
    return a + b.length * c
}

// Straight function definition
function bar(green, eggs = 'food', and= true, ham= 4) {
    if (and) return eggs.length * ham
}

// global callable variable
add_one = function (x) {
    return x + 1
}

// does the presence of a let break the parser?
let with_let = function (x) {
    return x + 2
}

// with arrow func
// (also testing if const breaks the parse)
const with_arrow_func = (y, z= 1) => y * z

// function assigned to a nested property
func.assigned.to.nested.prop = function (x) {
    return x + 3
}

// function nested in some other function, assigned to a variable
var obj = (function (exports) {
    function bar(name) {
        return name + "__"
    }
})

Metadata

Release files for jy 0.1.21

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

Source distribution (sdist)

Source distribution for jy 0.1.21
File Size Uploaded Provenance Actions
jy-0.1.21.tar.gz 53.0 kB Without provenance Details for jy-0.1.21.tar.gz

Built distribution (wheel)

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

Total release size: 77.0 kB

Release files / jy-0.1.21.tar.gz

Download URL jy-0.1.21.tar.gz
Size 53.0 kB
Tags Source
SHA-256 checksum
How to use checksums
29ccc9cc062f0aa9b4b7cde3d1382fabfa636e1098626af3606dabb19fc4570a
BLAKE2b-256 checksum
How to use checksums
e9e242c7c816acd3303c48261a3a86e92d30449eb99c91bc0293a35e8c08d62d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / jy-0.1.21-py3-none-any.whl

Download URL jy-0.1.21-py3-none-any.whl
Size 24.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3db13b5d682622e8b60aa4411977d6c0e19bf0fca4ee66491cf419335c5d8f4b
BLAKE2b-256 checksum
How to use checksums
95d30fe9ed68ae42ebdb2fe15128b5436aa26e8330716df2caa20592e9fdaf4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for jy 0.1.21

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