{"id":39259524,"url":"https://github.com/grongierisc/iris-flask-template","last_synced_at":"2026-01-18T00:25:15.308Z","repository":{"id":246005683,"uuid":"816205764","full_name":"grongierisc/iris-flask-template","owner":"grongierisc","description":"Iris python first experience flask template","archived":false,"fork":false,"pushed_at":"2024-07-09T06:47:14.000Z","size":23,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-07-09T16:23:33.590Z","etag":null,"topics":["flask","flask-sqlalchemy","intersystems-iris","iris"],"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/grongierisc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2024-06-17T08:57:41.000Z","updated_at":"2024-07-09T06:47:18.000Z","dependencies_parsed_at":"2024-07-08T16:08:27.988Z","dependency_job_id":null,"html_url":"https://github.com/grongierisc/iris-flask-template","commit_stats":null,"previous_names":["grongierisc/iris-flask-template"],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/grongierisc/iris-flask-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grongierisc%2Firis-flask-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grongierisc%2Firis-flask-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grongierisc%2Firis-flask-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grongierisc%2Firis-flask-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grongierisc","download_url":"https://codeload.github.com/grongierisc/iris-flask-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grongierisc%2Firis-flask-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28523717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T23:53:28.710Z","status":"ssl_error","status_checked_at":"2026-01-17T23:52:20.131Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["flask","flask-sqlalchemy","intersystems-iris","iris"],"created_at":"2026-01-18T00:25:14.681Z","updated_at":"2026-01-18T00:25:15.299Z","avatar_url":"https://github.com/grongierisc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iris-flask-template\n\n![Flask_logo](https://flask.palletsprojects.com/en/2.0.x/_images/flask-logo.png)\n\n## Description\n\nThis is a template for a Flask application that can be deployed in IRIS as an native Web Application.\n\n## Installation\n\n1. Clone the repository\n2. Create a virtual environment\n3. Install the requirements\n4. Run the docker-compose file\n\n```bash\ngit clone\ncd iris-flask-template\npython3 -m venv .venv\nsource .venv/bin/activate\npip install -r requirements.txt\ndocker-compose up\n```\n\n## Usage\n\nThe base URL is `http://localhost:53795/flask/`.\n\n### Endpoints\n\n- `/iris` - Returns a JSON object with the top 10 classes present in the IRISAPP namespace.\n- `/interop` - A ping endpoint to test the interoperability framework of IRIS.\n- `/posts` - A simple CRUD endpoint for a Post object.\n- `/comments` - A simple CRUD endpoint for a Comment object.\n\n## How to develop from this template\n\nSee WSGI introduction article: [wsgi-introduction](https://community.intersystems.com/post/wsgi-support-introduction).\n\nTL;DR : You can toggle the `DEBUG` flag in the Security portal to make changes to be reflected in the application as you develop.\n\n## Code presentation\n\n### `app.py`\n\nThis is the main file of the application. It contains the Flask application and the endpoints.\n\n```python\nfrom flask import Flask, jsonify, request\nfrom models import Comment, Post, init_db\n\nfrom iop import Director\n\nimport iris\n\napp = Flask(__name__)\napp.config['SQLALCHEMY_DATABASE_URI'] = 'iris+emb://IRISAPP'\n\ndb = init_db(app)\n```\n\n- `from flask import Flask, jsonify, request`: Import the Flask library.\n- `from models import Comment, Post, init_db`: Import the models and the database initialization function.\n- `from iop import Director`: Import the Director class to bind the flask app to the IRIS interoperability framework.\n- `import iris`: Import the IRIS library.\n- `app = Flask(__name__)`: Create a Flask application.\n- `app.config['SQLALCHEMY_DATABASE_URI'] = 'iris+emb://IRISAPP'`: Set the database URI to the IRISAPP namespace.\n  - The `iris+emb` URI scheme is used to connect to IRIS as an embedded connection (no need for a separate IRIS instance).\n- `db = init_db(app)`: Initialize the database with the Flask application.\n\n### `models.py`\n\nThis file contains the SQLAlchemy models for the application.\n\n```python\nfrom dataclasses import dataclass\nfrom typing import List\nfrom flask_sqlalchemy import SQLAlchemy\n\ndb = SQLAlchemy()\n\n@dataclass\nclass Comment(db.Model):\n    id:int = db.Column(db.Integer, primary_key=True)\n    content:str = db.Column(db.Text)\n    post_id:int = db.Column(db.Integer, db.ForeignKey('post.id'))\n\n@dataclass\nclass Post(db.Model):\n    __allow_unmapped__ = True\n    id:int = db.Column(db.Integer, primary_key=True)\n    title:str = db.Column(db.String(100))\n    content:str = db.Column(db.Text)\n    comments:List[Comment] = db.relationship('Comment', backref='post')\n```\n\nNot much to say here, the models are defined as dataclasses and are subclasses of the `db.Model` class.\n\nThe use of the `__allow_unmapped__` attribute is necessary to allow the creation of the `Post` object without the `comments` attribute.\n\n`dataclasses` are used to help with the serialization of the objects to JSON.\n\nThe `init_db` function initializes the database with the Flask application.\n\n```python\ndef init_db(app):\n    db.init_app(app)\n\n    with app.app_context():\n        db.drop_all()\n        db.create_all()\n        # Create fake data\n        post1 = Post(title='Post The First', content='Content for the first post')\n        ...\n        db.session.add(post1)\n        ...\n        db.session.commit()\n    return db\n```\n\n- `db.init_app(app)`: Initialize the database with the Flask application.\n- `with app.app_context()`: Create a context for the application.\n- `db.drop_all()`: Drop all the tables in the database.\n- `db.create_all()`: Create all the tables in the database.\n- Create fake data for the application.\n- return the database object.\n\n\n### `/iris` endpoint\n\n```python\n######################\n# IRIS Query example #\n######################\n\n@app.route('/iris', methods=['GET'])\ndef iris_query():\n    query = \"SELECT top 10 * FROM %Dictionary.ClassDefinition\"\n    rs = iris.sql.exec(query)\n    # Convert the result to a list of dictionaries\n    result = []\n    for row in rs:\n        result.append(row)\n    return jsonify(result)\n```\n\nThis endpoint executes a query on the IRIS database and returns the top 10 classes present in the IRISAPP namespace.\n\n### `/interop` endpoint\n\n```python\n########################\n# IRIS interop example #\n########################\nbs = Director.create_python_business_service('BS')\n\n@app.route('/interop', methods=['GET', 'POST', 'PUT', 'DELETE'])\ndef interop():\n    \n    rsp = bs.on_process_input(request)\n\n    return jsonify(rsp)\n```\n\nThis endpoint is used to test the interoperability framework of IRIS. It creates a Business Service object and binds it to the Flask application.\n\nNB : The `bs` object must be outside of the scope of the request to keep it alive.\n\n- `bs = Director.create_python_business_service('BS')`: Create a Business Service object named 'BS'.\n- `rsp = bs.on_process_input(request)`: Call the `on_process_input` method of the Business Service object with the request object as an argument.\n\n### `/posts` endpoint\n\n```python\n############################\n# CRUD operations posts    #\n############################\n\n@app.route('/posts', methods=['GET'])\ndef get_posts():\n    posts = Post.query.all()\n    return jsonify(posts)\n\n@app.route('/posts', methods=['POST'])\ndef create_post():\n    data = request.get_json()\n    post = Post(title=data['title'], content=data['content'])\n    db.session.add(post)\n    db.session.commit()\n    return jsonify(post)\n\n@app.route('/posts/\u003cint:id\u003e', methods=['GET'])\ndef get_post(id):\n    ...\n```\n\nThis endpoint is used to perform CRUD operations on the `Post` object.\n\nThanks to the `dataclasses` module, the `Post` object can be easily serialized to JSON.\n\nHere we use the sqlalchemy `query` method to get all the posts, and the `add` and `commit` methods to create a new post.\n\n### `/comments` endpoint\n\n```python\n############################\n# CRUD operations comments #\n############################\n\n@app.route('/comments', methods=['GET'])\ndef get_comments():\n    comments = Comment.query.all()\n    return jsonify(comments)\n\n@app.route('/comments', methods=['POST'])\ndef create_comment():\n    data = request.get_json()\n    comment = Comment(content=data['content'], post_id=data['post_id'])\n    db.session.add(comment)\n    db.session.commit()\n    return jsonify(comment)\n\n@app.route('/comments/\u003cint:id\u003e', methods=['GET'])\ndef get_comment(id):\n    ...\n```\n\nThis endpoint is used to perform CRUD operations on the `Comment` object.\n\nThe `Comment` object is linked to the `Post` object by a foreign key.\n\n## Troubleshooting\n\n### How to run the Flask application in a standalone mode\n\nYou can always run a standalone Flask application with the following command:\n\n```bash\npython3 /irisdev/app/community/app.py\n```\n\nNB : You must be inside of the container to run this command.\n\n```bash\ndocker exec -it iris-flask-template-iris-1 bash\n```\n\n### Restart the application in IRIS\n\nBe in `DEBUG` mode make multiple calls to the application, and the changes will be reflected in the application.\n\n### How to access the IRIS Management Portal\n\nYou can access the IRIS Management Portal by going to `http://localhost:53795/csp/sys/UtilHome.csp`.\n\n### Run this template locally\n\nFor this you need to have IRIS installed on your machine.\n\nNext you need to create a namespace named `IRISAPP`.\n\nInstall the requirements.\n\nInstall IoP :\n\n```bash\n#init iop\niop --init\n\n# load production\niop -m /irisdev/app/community/interop/settings.py\n\n# start production\niop --start Python.Production\n```\n\nConfigure the application in the Security portal.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrongierisc%2Firis-flask-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrongierisc%2Firis-flask-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrongierisc%2Firis-flask-template/lists"}