Skip to main content

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.

Metadata

Release files for flask-transcrypt 0.1.1

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

Source distribution (sdist)

Source distribution for flask-transcrypt 0.1.1
File Size Uploaded Provenance Actions
flask_transcrypt-0.1.1.tar.gz 19.7 kB Without provenance Details for flask_transcrypt-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flask-transcrypt 0.1.1
File Interpreter ABI Platform Actions
flask_transcrypt-0.1.1-py3-none-any.whl Python 3 none any Details for flask_transcrypt-0.1.1-py3-none-any.whl

Total release size: 24.1 kB

Release files / flask_transcrypt-0.1.1.tar.gz

Download URL flask_transcrypt-0.1.1.tar.gz
Size 19.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d721445c8164e3c61a2f92cb5a15d2aa94857e3a82beab861099d0fe38ab7382
BLAKE2b-256 checksum
How to use checksums
cdbcceadfb889685d9dcadc755ff61b86b635b985ffc32dc76a0decd833960b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / flask_transcrypt-0.1.1-py3-none-any.whl

Download URL flask_transcrypt-0.1.1-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8bfd1d007e2ef2338cfafa620e851d0309999105b7ae24ec4e4d4efb1ed4ac09
BLAKE2b-256 checksum
How to use checksums
2a9ace5a48582489038ecb26bf27d5972fae8038f2b456642d2bc58f2510501f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Security for flask-transcrypt 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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