Skip to main content

Python implementation of the Joint Editors Protocol.

Project description

Build Status Coveralls Status PyPI Status

This is the Python implementation of the Joint Editors Protocol (JEP), see http://joint-editors.org/ for more information. jep-python is providing language authors with a frontend library for IDE/editor integration and a backend library for language support.

This implementation is currently compatible with Python 3.3+.

Look at these associated projects for examples of productive use of the library:

Backend support

Implementing JEP based support for a custom language is easy. Simply derive one or more listener classes to respond to frontend messages and then run the backend with those listeners.

from jep_py.backend import Backend, FrontendListener

class Listener(FrontendListener):
    def on_completion_request(self, completion_request, context):
        # process completion request and send back response:
        completion_response = f(completion_request)
        context.send_message(completion_response)

# instantiate and start backend service with our listeners:
listener = Listener()
backend = Backend([listener])
backend.start()

Callbacks that are not needed by a certain listener do not need to be overridden in the derived class.

While the user is editing a file in a connected IDE the frontend will repeatedly send ContentSync objects to the backend. The backend implementation already processes these messages internally and provides an accumulated file view to client code. Since backend-internal message processing is done before messages are passed to subscribed listeners, you can process the latest view of a file directly inside your listener’s handler of ContentSync by accessing the context’s content_monitor filepath dictionary:

def on_content_sync(self, content_sync, context):
    # get the content monitor's view of the file that was just updated:
    file_content = context.content_monitor[content_sync.file]

    # ...

Frontend support

Similarly in an IDE frontend you again derive listener classes, this time listening to backend messages. Since the frontend initiates the connection you additionally have to create such a connection for a certain language. JEP service lookup is then used to determine the supporting backend and the frontend will start it in its own subprocess.

Here is an example shutting down the backend service upon reception of its first alive message:

import datetime
from jep_py.frontend import Frontend, BackendListener, State
from jep_py.schema import Shutdown

class MyListener(BackendListener):
    def on_backend_alive(self, context):
        context.send_message(Shutdown())


frontend = Frontend([MyListener()])
connection = frontend.get_connection('localfile.mydsl')

while connection.state is not State.Disconnected:
    connection.run(datetime.timedelta(seconds=0.1))

Project details


Download files

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

Source Distribution

jep-python-0.5.5.zip (36.2 kB view details)

Uploaded Source

Built Distribution

jep_python-0.5.5-py3-none-any.whl (113.1 kB view details)

Uploaded Python 3

File details

Details for the file jep-python-0.5.5.zip.

File metadata

  • Download URL: jep-python-0.5.5.zip
  • Upload date:
  • Size: 36.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jep-python-0.5.5.zip
Algorithm Hash digest
SHA256 a824798d4b9b2ccf1c9491defcca0983af591baaefa7b2dc49bb8ed827ac1b05
MD5 5d50ab3b589fa8f6104bfc892cb4995d
BLAKE2b-256 1c30ea4790524c0c2427cfca0bc8cd40a05fe8e9bd31863d40a9de9ea58db669

See more details on using hashes here.

File details

Details for the file jep_python-0.5.5-py3-none-any.whl.

File metadata

File hashes

Hashes for jep_python-0.5.5-py3-none-any.whl
Algorithm Hash digest
SHA256 780303d7ce6ea5a5422280976280b24bda8fe4c7e094cefa270fc976cfa82c2e
MD5 b16befe8a14aa6a70e3c554741e2248d
BLAKE2b-256 1bf0084e617ece4d4f4800f302b5ab2b185ba4e8a86e428f0ab8a0276f749822

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page