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.1.tar.gz (19.7 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.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flask_transcrypt-0.1.1.tar.gz
  • Upload date:
  • Size: 19.7 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.1.tar.gz
Algorithm Hash digest
SHA256 d721445c8164e3c61a2f92cb5a15d2aa94857e3a82beab861099d0fe38ab7382
MD5 c840eb242adf739b28eac15117a4f311
BLAKE2b-256 cdbcceadfb889685d9dcadc755ff61b86b635b985ffc32dc76a0decd833960b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flask_transcrypt-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8bfd1d007e2ef2338cfafa620e851d0309999105b7ae24ec4e4d4efb1ed4ac09
MD5 9aac6b14df900c3156202e44f9b5eb22
BLAKE2b-256 2a9ace5a48582489038ecb26bf27d5972fae8038f2b456642d2bc58f2510501f

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