Skip to main content

Flask extension to integrate Transcrypt

Project description

FlaskTranscrypt

FlaskTranscrypt is a Flask extension that integrates Transcrypt, a Python to JavaScript compiler. It automatically compiles Python files in a specified source directory to JavaScript before each request.

Features

  • Automatic compilation of Python files to JavaScript using Transcrypt.
  • Easy integration with Flask applications.
  • Configurable source and target directories.

Installation

To install FlaskTranscrypt, you can use pip:

pip install flask-transcrypt
or 
pip3 install flask-transcrypt

Usage

Initialization

First, import and initialize the FlaskTranscrypt extension in your Flask application:

from flask import Flask
from flask_transcrypt import FlaskTranscrypt

app = Flask(__name__)
transcrypt = FlaskTranscrypt(app)

if __name__ == "__main__":
    app.run()

Configuration

You can configure the source and target directories for the Transcrypt compilation in your Flask application's configuration. If these configurations are not defined, the extension will use the default values:

app.config["TRANSCRYPT_SOURCE_DIR"] = "/path/to/source/directory"
app.config["TRANSCRYPT_TARGET_DIR"] = "/path/to/target/directory"

By default, the source directory is set to the Flask application's static folder, and the target directory is set to __target__ within the static folder.

Template Integration

In your Flask template, include the compiled JavaScript file using the following script tag:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Flask Transcrypt Example</title>
</head>
<body>
    <!-- Your HTML content goes here -->

    <!-- Include the compiled JavaScript file -->
    <script type="module" src="{{ url_for('static', filename='__target__/name_for_file.js') }}"></script>
</body>
</html>

Replace name_for_file.js with the actual name of your compiled JavaScript file.

Example

Here is a complete example of how to use FlaskTranscrypt in a Flask application:

from flask import Flask
from flask_transcrypt import FlaskTranscrypt

app = Flask(__name__)
transcrypt = FlaskTranscrypt(app)

if __name__ == "__main__":
    app.run()

In your template (e.g., index.html):

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Flask Transcrypt Example</title>
</head>
<body>
    <!-- Your HTML content goes here -->

    <!-- Include the compiled JavaScript file -->
    <script type="module" src="{{ url_for('static', filename='__target__/name_for_file.js') }}"></script>
</body>
</html>

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Acknowledgments

  • Transcrypt for the Python to JavaScript compiler.
  • Flask for the web framework.

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

flask_transcrypt-0.1.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

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

flask_transcrypt-0.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file flask_transcrypt-0.1.tar.gz.

File metadata

  • Download URL: flask_transcrypt-0.1.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for flask_transcrypt-0.1.tar.gz
Algorithm Hash digest
SHA256 bb8c5c27235d86175fdb208181b9e1ac1c1aa02f0fb2e367a491502fdd3c66bc
MD5 e305fb3701049c1cc50d7715edb7101e
BLAKE2b-256 a8de8e1ae96a7e20efeb55bd443eb7127450a4b6ef75bb7cded7b9dc2e7a773b

See more details on using hashes here.

File details

Details for the file flask_transcrypt-0.1-py3-none-any.whl.

File metadata

  • Download URL: flask_transcrypt-0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for flask_transcrypt-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 04725df272c18918f7aae5a463cf95d5283b8d54a6887a810481b3c37c9b8716
MD5 1e5dddc3765f13e63fae1b4e1a1b0d96
BLAKE2b-256 f5fdb884a7c69fe1469acfd82752a2f0328b62094d1680da6b80741c2aa62362

See more details on using hashes here.

Supported by

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