Skip to main content

jiphy

PyPI version PyPi downloads Build Status License Bitdeli Badge

Write your client side code in a Jiphy! Jiphy is a two-way Python->JavaScript converter. It’s not meant to create runnable Python code from complex JavaScript files, or runnable JavaScript from complex Python projects. Instead, Jiphy enables Python programmers to more easily write JavaScript code by allowing them to use more familiar syntax, and even JavaScript developers to more easily write Python code.

As a Python developer you can convert existing code in someone else’s project from JavasScript into Python, edit it, and then convert it back before submitting.

Jiphy’s Design Objectives:

  • Reduce the context switching necessary for a Python developer to write JavaScript code and vice versa.

  • Always output 1:1 line mappings (a line of Python produces a line of JavaScript) so source maps are not necessary.

  • Be usable for a single developer on a project (No mass buy-in needed).

  • Should be easy to write text-editor plugins that expose Jiphy within IDEs for on-the-spot conversion.

  • Quickly run over many files.

  • Change syntax only

Write:

import underscore as _

def my_function(argument1, argument2):
    if argument1:
        del argument2
    elif argument2:
        print(argument2)

    if somevar is someothervar And x is not b: pass

Get:

var _ = require('_');

function my_function(argument1, argument2) {
    if (argument1) {
        delete argument2;
    } else if (argument2) {
        console.log(argument2);
    }
    if (somevar === someothervar && x !== b) {}
}

in a jiphy.

Why jiphy?

jiphy (pronounced: jiffy) simply stands for JavaScript In, Python Out.

Jiphy is very different from other attempts at Python -> JavaScript conversion for the following reasons: - Converts in both directions (JavaScript -> Python, Python -> JavaScript). - Allows intermixing of code. You can add a Python function to a JavaScript file and then convert it all to JavaScript. - Converts lines 1:1, so you always know which source line causes which output line. No source mapping needed. - Doesn’t require any extra JavaScript files to be loaded. - Can be used by a single developer without team buy-in.

Jiphy only supports syntax, but with ES6 around the corner should one day support Classes, default arguments, etc.

Important things to know when writing Python for conversion to JavaScript

  • Every indented block must have a line after it.

For instance:

if something is True:
    do_something()

print("done")

Is valid as the if statement has a new line after it. However:

if something is True:
    do_something()
print("done")

is NOT valid in Jiphy. The lack of a new line makes it impossible to do a 1:1 conversion and still be nicely formatted JS code.

  • Jiphy isn’t smart enough to know when to create a var

For now, you still have to write var in front of new variables in Jiphy. Jiphy simply does not yet have the smarts to know when it is and when it is not required.

  • Jiphy does not implement stdlib components, classes, etc. It’s SYNTAX ONLY.

Syntax / Contstructs Jiphy Suppports

Python

JavaScript

Supported To JavaScript

Supported To Python

def (…):

function(…) {}

if …:

if (…) {}

while …:

while (…) {}

elif …:

} else if (…) {

else:

} else {

pass

{}

print(…)

console.log(…)

True

true

False

false

None

null

Or

||

And

&&

Unset

undefined

not

!

is

===

del

delete

;

# comment

// comment

str(…)

String(…)

bool(…)

Boolean(…)

int(…)

Number(…)

import pdb; pdb.set_trace()

debugger;

try:

try {

except

catch

except Exception as e

catch(e)

.append(…)

.push(…)

raise ‘error’

throw ‘error’;

import x

var x = require(x)

import x as _

var _ = require(x)

“String”

‘String’

“””String”””

‘Str’ + ‘ing’

@decorator

f = decorator(f)

Installing jiphy

Installing jiphy is as simple as:

pip install jiphy

or if you prefer

easy_install jiphy

Using jiphy

from the command line:

jiphy mypythonfile.py mypythonfile2.py

or to conform all code to the specified file format

jiphy mypythonfile.js mypythonfile2.js --conform

or recursively:

jiphy -rc .

which is equivalent to

jiphy **/*.py

or recursively conform:

jiphy -rc --conform .

or to see the proposed changes without applying them

jiphy mypythonfile.py --diff

from within Python:

import jiphy

jiphy.to.javascript(python_code)
jiphy.to.python(javascript_code)

Thanks and I hope you find jiphy useful!

~Timothy Crosley

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jiphy-1.2.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jiphy-1.2.0-py2.py3-none-any.whl (24.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file jiphy-1.2.0.tar.gz.

File metadata

  • Download URL: jiphy-1.2.0.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jiphy-1.2.0.tar.gz
Algorithm Hash digest
SHA256 63fa4e927801972be846388f2ceff60d9758e61b6abf83d83e3cb9a416a686f4
MD5 41307168fa27c80cabbb92a2fa35231f
BLAKE2b-256 b6cbb289d2a754363e234073db6d36e7317a65431dcd7e9d2d0bf64ffb624103

See more details on using hashes here.

File details

Details for the file jiphy-1.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for jiphy-1.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4197db60d05d059a2cda614564a6ea04117b00693ec8386965253dbc987ed98f
MD5 36ad005aba8af904741623194c845760
BLAKE2b-256 bf1dc948fa8afd244fc999a3f9f0a2ef07c219cd203001fd5583af9c5512b85c

See more details on using hashes here.

Release history Release notifications | RSS feed

1.2.2

1 file

1.2.1

2 files

This release

1.2.0 This release

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.0.1

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