flask-transcrypt


Nameflask-transcrypt JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/codewithmpia/flask_transcrypt
SummaryFlask extension to integrate Transcrypt
upload_time2024-09-15 07:46:03
maintainerNone
docs_urlNone
authorcodewithmpia
requires_pythonNone
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```bash
pip install flask-transcrypt
or 
pip3 install flask-transcrypt
```

## Usage

### Initialization

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

```python
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:

```python
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:

```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>
```

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:

```python
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`):

```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](LICENSE) file for details.

## Contributing

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

## Acknowledgments

- [Transcrypt](https://www.transcrypt.org/) for the Python to JavaScript compiler.
- [Flask](https://flask.palletsprojects.com/) for the web framework.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/codewithmpia/flask_transcrypt",
    "name": "flask-transcrypt",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "codewithmpia",
    "author_email": "codewithmpia@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/cd/bc/ceadfb889685d9dcadc755ff61b86b635b985ffc32dc76a0decd833960b3/flask_transcrypt-0.1.1.tar.gz",
    "platform": null,
    "description": "# FlaskTranscrypt\n\nFlaskTranscrypt 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.\n\n## Features\n\n- Automatic compilation of Python files to JavaScript using Transcrypt.\n- Easy integration with Flask applications.\n- Configurable source and target directories.\n\n## Installation\n\nTo install FlaskTranscrypt, you can use pip:\n\n```bash\npip install flask-transcrypt\nor \npip3 install flask-transcrypt\n```\n\n## Usage\n\n### Initialization\n\nFirst, import and initialize the `FlaskTranscrypt` extension in your Flask application:\n\n```python\nfrom flask import Flask\nfrom flask_transcrypt import FlaskTranscrypt\n\napp = Flask(__name__)\ntranscrypt = FlaskTranscrypt(app)\n\nif __name__ == \"__main__\":\n    app.run()\n```\n\n### Configuration\n\nYou 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:\n\n```python\napp.config[\"TRANSCRYPT_SOURCE_DIR\"] = \"/path/to/source/directory\"\napp.config[\"TRANSCRYPT_TARGET_DIR\"] = \"/path/to/target/directory\"\n```\n\nBy 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.\n\n### Template Integration\n\nIn your Flask template, include the compiled JavaScript file using the following script tag:\n\n```html\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Flask Transcrypt Example</title>\n</head>\n<body>\n    <!-- Your HTML content goes here -->\n\n    <!-- Include the compiled JavaScript file -->\n    <script type=\"module\" src=\"{{ url_for('static', filename='__target__/name_for_file.js') }}\"></script>\n</body>\n</html>\n```\n\nReplace `name_for_file.js` with the actual name of your compiled JavaScript file.\n\n## Example\n\nHere is a complete example of how to use FlaskTranscrypt in a Flask application:\n\n```python\nfrom flask import Flask\nfrom flask_transcrypt import FlaskTranscrypt\n\napp = Flask(__name__)\ntranscrypt = FlaskTranscrypt(app)\n\nif __name__ == \"__main__\":\n    app.run()\n```\n\nIn your template (e.g., `index.html`):\n\n```html\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Flask Transcrypt Example</title>\n</head>\n<body>\n    <!-- Your HTML content goes here -->\n\n    <!-- Include the compiled JavaScript file -->\n    <script type=\"module\" src=\"{{ url_for('static', filename='__target__/name_for_file.js') }}\"></script>\n</body>\n</html>\n```\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request.\n\n## Acknowledgments\n\n- [Transcrypt](https://www.transcrypt.org/) for the Python to JavaScript compiler.\n- [Flask](https://flask.palletsprojects.com/) for the web framework.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Flask extension to integrate Transcrypt",
    "version": "0.1.1",
    "project_urls": {
        "Author": "https://github.com/codewithmpia",
        "Homepage": "https://github.com/codewithmpia/flask_transcrypt",
        "Source": "https://github.com/codewithmpia/flask_transcrypt",
        "Tracker": "https://github.com/codewithmpia/flask_transcrypt/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2a9ace5a48582489038ecb26bf27d5972fae8038f2b456642d2bc58f2510501f",
                "md5": "9aac6b14df900c3156202e44f9b5eb22",
                "sha256": "8bfd1d007e2ef2338cfafa620e851d0309999105b7ae24ec4e4d4efb1ed4ac09"
            },
            "downloads": -1,
            "filename": "flask_transcrypt-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9aac6b14df900c3156202e44f9b5eb22",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4444,
            "upload_time": "2024-09-15T07:46:02",
            "upload_time_iso_8601": "2024-09-15T07:46:02.309137Z",
            "url": "https://files.pythonhosted.org/packages/2a/9a/ce5a48582489038ecb26bf27d5972fae8038f2b456642d2bc58f2510501f/flask_transcrypt-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cdbcceadfb889685d9dcadc755ff61b86b635b985ffc32dc76a0decd833960b3",
                "md5": "c840eb242adf739b28eac15117a4f311",
                "sha256": "d721445c8164e3c61a2f92cb5a15d2aa94857e3a82beab861099d0fe38ab7382"
            },
            "downloads": -1,
            "filename": "flask_transcrypt-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c840eb242adf739b28eac15117a4f311",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 19676,
            "upload_time": "2024-09-15T07:46:03",
            "upload_time_iso_8601": "2024-09-15T07:46:03.905219Z",
            "url": "https://files.pythonhosted.org/packages/cd/bc/ceadfb889685d9dcadc755ff61b86b635b985ffc32dc76a0decd833960b3/flask_transcrypt-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-15 07:46:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "codewithmpia",
    "github_project": "flask_transcrypt",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "flask-transcrypt"
}
        
Elapsed time: 7.14188s