{"id":28249091,"url":"https://github.com/coultonf/inertia-flask","last_synced_at":"2025-07-20T01:05:47.512Z","repository":{"id":276820502,"uuid":"930190117","full_name":"CoultonF/inertia-flask","owner":"CoultonF","description":"Flask Inertia JS Adapter","archived":false,"fork":false,"pushed_at":"2025-05-24T02:42:02.000Z","size":75,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-07T13:24:37.425Z","etag":null,"topics":["angular","flask","inertiajs","python","react","vite","vue"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CoultonF.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-10T08:22:36.000Z","updated_at":"2025-05-24T02:43:16.000Z","dependencies_parsed_at":"2025-03-31T21:24:46.808Z","dependency_job_id":"0492d032-3eba-4ba2-8774-f32dbd005e81","html_url":"https://github.com/CoultonF/inertia-flask","commit_stats":null,"previous_names":["coultonf/inertia-flask"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/CoultonF/inertia-flask","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoultonF%2Finertia-flask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoultonF%2Finertia-flask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoultonF%2Finertia-flask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoultonF%2Finertia-flask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CoultonF","download_url":"https://codeload.github.com/CoultonF/inertia-flask/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoultonF%2Finertia-flask/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266052533,"owners_count":23869475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","flask","inertiajs","python","react","vite","vue"],"created_at":"2025-05-19T13:14:08.631Z","updated_at":"2025-07-20T01:05:47.469Z","avatar_url":"https://github.com/CoultonF.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Inertia.js](https://raw.githubusercontent.com/coultonf/inertia-flask/main/LOGO.png)](https://inertiajs.com/)\n[![Inertia 2.0](\u003chttps://img.shields.io/badge/Inertia-2.0-rgb(107%2C70%2C193).svg\u003e)](https://inertiajs.com/)\n[![build](https://github.com/CoultonF/inertia-flask/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/CoultonF/inertia-flask/actions/workflows/build.yml)\n[![Coverage Status](https://coveralls.io/repos/github/CoultonF/inertia-flask/badge.svg)](https://coveralls.io/github/CoultonF/inertia-flask)\n[![Download](https://img.shields.io/pypi/dm/inertia-flask.svg)](https://pypi.org/project/inertia-flask/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n# Inertia.js Flask Adapter\n\nThe Inertia.js Flask Adapter allows you to seamlessly integrate Inertia.js with your Flask applications. This adapter provides the necessary tools to build modern, single-page applications using Flask as the backend and Inertia.js for the frontend.\n\n## Development Installation\n\n## Using uv (recommended)\n\n1. Install uv:\n\n```bash\npip install uv\n```\n\n2. Create and activate virtual environment:\n\n```bash\nuv venv\nsource .venv/bin/activate  # Unix/macOS\n```\n\n3. Install dependencies:\n\n```bash\nuv pip install -e .\nuv pip install -r requirements.txt\n```\n\n4. For development:\n\n```bash\nuv pip install -r requirements-dev.txt\n```\n\n5. For testing:\n\n````bash\nuv pip install -r requirements-test.txt\n\n## Configuration\nYou can initialize inertia-flask like most other extensions in Flask.\n\n``` python\nfrom flask import Flask\nfrom inertia_flask import Inertia\n\n# Required configuration keys\nSECRET_KEY = \"secret!\"\nINERTIA_TEMPLATE = \"base.html\"  # Mandatory key\n\napp = Flask(__name__)\napp.config.from_object(__name__)\n\n# Initialize Inertia\ninertia = Inertia()\ninertia.init_app(app)\n# Alternatively, you can initialize it directly: inertia = Inertia(app)\n````\n\n### Initializing on a Blueprint\n\nYou can also initialize the Inertia extension on a specific Blueprint:\n\n#### Important Note About Blueprints\n\nWhen using Inertia with Flask, you must choose between initializing Inertia on either:\n\n- The main Flask application\n- A Blueprint\n\nYou cannot initialize Inertia on both simultaneously. This is because Inertia manages page state and routing, which can lead to conflicts if multiple instances are running.\n\n```python\nfrom flask import Blueprint, Flask\nfrom flask_inertia import Inertia\n\n# Required configuration keys\nSECRET_KEY = \"secret!\"\nINERTIA_TEMPLATE = \"base.html\"  # Mandatory key\n\napp = Flask(__name__)\napp.config.from_object(__name__)\n\n# Create a Blueprint\nblueprint = Blueprint('inertia', __name__, template_folder='templates')\n\n# Initialize Inertia on the Blueprint\ninertia = Inertia(blueprint)\n# Alternatively, you can initialize it directly: inertia = Inertia(blueprint)\n```\n\n## Command Line Interface (CLI)\n\n- `flask vite build`: Builds Vite assets for production\n- `flask vite dev`: Runs Flask and Vite dev servers together\n- `flask vite install`: Installs Vite dependencies\n\n## CSRF\n\nFlask does not provide CSRF protection by default. To handle CSRF protection, you can use the [Flask Seasurf](https://github.com/maxcountryman/flask-seasurf) extension, which is a simple and effective solution for Flask applications.\n\nInertia.js uses Axios as the requests library. You can modify axios to integrate Seasurf with Inertia.js in your .js entry file as follows:\n\n```javascript\naxios.defaults.xsrfHeaderName = \"X-CSRFToken\";\naxios.defaults.xsrfCookieName = \"_csrf_token\";\n```\n\nThis ensures that Axios automatically includes the CSRF token in requests, aligning with Seasurf's protection mechanism.\n\n## Configuration Options\n\nThe following configuration options can be set in your Flask application's config:\n\n### Core Settings\n\nUse these settings for core Inertia functionality.\n\n- `INERTIA_TEMPLATE` (required): The base template used for rendering Inertia pages\n- `INERTIA_JSON_ENCODER`: Custom JSON encoder for serializing data (default: `InertiaJsonEncoder`)\n- `INERTIA_ENCRYPT_HISTORY`: Enable encryption of Inertia history state (default: `False`)\n- `INERTIA_STATIC_ENDPOINT`: Directory for static assets (default: `\"static\"`, blueprints: `\"your_bp_name.static\"`)\n\n### Server-Side Rendering (SSR)\n\nUse these settings to configure SSR support.\n\n- `INERTIA_SSR_ENABLED`: Enable server-side rendering support (default: `False`)\n- `INERTIA_SSR_URL`: URL where the SSR server is running (default: `\"http://localhost:13714\"`)\n\n### Vite Integration\n\nUse these settings to configure Vite.\n\n- `INERTIA_VITE_DIR`: Directory containing your Vite/frontend project (default: `\"inertia\"`)\n- `INERTIA_VITE_ORIGIN`: URL where Vite dev server runs (default: `\"http://localhost:5173\"`)\n- `INERTIA_INTERNAL_VITE_ORIGIN`: URL where Vite dev server runs relative to the flask app. This is useful when your exposed vite service and docker container have different locations or ports. (default: `\"http://localhost:5173\"`)\n- `INERTIA_ROOT`: Root element ID for mounting the Inertia app (default: `\"app\"`)\n\n  #### Manifest Files\n\n  Use these settings to specify the manifest filenames.\n\n  - `INERTIA_VITE_MANIFEST_PATH` (required): Client-side manifest file path\n  - `INERTIA_VITE_SSR_MANIFEST_PATH`: Server-side manifest file path (default: `None`)\n\n### Example Configuration\n\n```python\napp.config.update(\n    INERTIA_TEMPLATE=\"base.html\",\n    INERTIA_SSR_ENABLED=True,\n    INERTIA_VITE_DIR=\"frontend\",\n    INERTIA_ROOT=\"app\",\n    # Custom JSON encoder for special serialization needs\n    INERTIA_JSON_ENCODER=MyCustomJsonEncoder\n)\n```\n\nFor blueprint-specific configuration, use prefixes:\n\n```python\napp.config.update(\n    # Global settings\n    INERTIA_TEMPLATE=\"base.html\",\n    # Blueprint-specific settings\n    BP_INERTIA_TEMPLATE=\"blueprint.html\",\n    BP_INERTIA_VITE_DIR=\"bp_frontend\"\n)\n```\n\n## Examples\n\nEnsure you have pnpm/npm installed and are on the latest version of node as Vite has dropped support for Node v21. If you are encountering issues around node and using Windows, try to sign out.\n\nTo run the example project, follow these steps:\n\n```bash\nuv venv\nsource .venv/bin/activate  # Unix/macOS\nuv pip install -e .\nuv pip install -r requirements.txt\nuv pip install -r requirements-dev.txt\ncd examples/react\nflask vite install\nflask vite dev\n```\n\n## Contributing\n\nTo contribute to the development of this extension, follow these steps:\n\n1. Install the project dependencies with test support:\n\n   ```bash\n   uv pip install -e .\n   uv pip install -r requirements.txt\n   uv pip install -r requirements-test.txt\n   source .venv/bin/activate  # Unix/macOS\n   ```\n\n2. Run the unit tests using pytest:\n   ```bash\n   python -m pytest\n   ```\n\n## Testing\n\n### Running Tests\n\n1. Install test dependencies:\n\n```bash\nuv pip install -r requirements-test.txt\n```\n\n2. Run tests using the test script:\n\n```bash\n./scripts/test.sh\n```\n\n### Test Options\n\n- Run specific test file:\n\n```bash\n./scripts/test.sh tests/test_inertia.py\n```\n\n- Run tests with specific marker:\n\n```bash\n./scripts/test.sh -m \"integration\"\n```\n\n- Run tests with output:\n\n```bash\n./scripts/test.sh -v\n```\n\n### Coverage Report\n\nThe test script automatically generates a coverage report. To generate an HTML coverage report:\n\n```bash\n./scripts/test.sh --cov-report=html\n```\n\nThe report will be available in the `htmlcov` directory.\n\n## Thank you\n\nParts of this repo were inspired by:\n\n[Inertia-django](https://github.com/inertiajs/inertia-django?tab=readme-ov-file), MIT License, Copyright 2022 Bellawatt, Brandon Shar\n\n[Flask-inertia](https://github.com/j0ack/flask-inertia), MIT License, Copyright 2021, TROUVERIE Joachim \u003cjtrouverie@joakode.fr\u003e\n\nMaintained and sponsored by [IJACK Technologies](https://myijack.com/).\n\n\u003ca href=\"https://myijack.com/\"\u003e \u003cimg src=\"https://raw.githubusercontent.com/coultonf/inertia-flask/main/IJACK.png\" alt=\"IJACK Technologies\" width=\"120\" /\u003e \u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoultonf%2Finertia-flask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoultonf%2Finertia-flask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoultonf%2Finertia-flask/lists"}