{"id":39259495,"url":"https://github.com/grongierisc/iris-fastapi-template","last_synced_at":"2026-01-18T00:25:13.296Z","repository":{"id":246005797,"uuid":"818240440","full_name":"grongierisc/iris-fastapi-template","owner":"grongierisc","description":"Iris python first experience with fastapi","archived":false,"fork":false,"pushed_at":"2024-07-09T06:45:10.000Z","size":21,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-07-09T09:08:57.094Z","etag":null,"topics":["fastapi","intersystems-iris","iris","sqlmodel"],"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-21T12:02:05.000Z","updated_at":"2024-07-09T06:45:13.000Z","dependencies_parsed_at":"2024-06-25T10:31:05.955Z","dependency_job_id":"587299fa-233e-468f-92bc-a8a339c88c2d","html_url":"https://github.com/grongierisc/iris-fastapi-template","commit_stats":null,"previous_names":["grongierisc/iris-fastapi-template"],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/grongierisc/iris-fastapi-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grongierisc%2Firis-fastapi-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grongierisc%2Firis-fastapi-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grongierisc%2Firis-fastapi-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grongierisc%2Firis-fastapi-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grongierisc","download_url":"https://codeload.github.com/grongierisc/iris-fastapi-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grongierisc%2Firis-fastapi-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":["fastapi","intersystems-iris","iris","sqlmodel"],"created_at":"2026-01-18T00:25:12.547Z","updated_at":"2026-01-18T00:25:13.272Z","avatar_url":"https://github.com/grongierisc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iris-fastapi-template\n\n![fastapi_logo](https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png)\n\n## Description\n\nThis is a template for a FastApi 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-fastapi-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/fastapi/`.\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 FastAPI application. It contains the FastAPI application and the routes.\n\n```python\nfrom fastapi import FastAPI, Request\n\nimport iris\n\nfrom iop import Director\n\n# import models\nfrom models import Post, Comment, init_db\nfrom sqlmodel import Session,select\n\napp = FastAPI()\n\n# create a database engine\nurl = \"iris+emb://IRISAPP\"\nengine = init_db(url)\n```\n\n- `from fastapi import FastAPI, Request` - Import the FastAPI class and the Request class.\n- `import iris` - Import the IRIS module.\n- `from iop import Director`: Import the Director class to bind the flask app to the IRIS interoperability framework.\n- `from models import Post, Comment, init_db` - Import the models and the init_db function.\n- `from sqlmodel import Session,select` - Import the Session class and the select function from the sqlmodel module.\n- `app = FastAPI()` - Create a FastAPI application.\n- `url = \"iris+emb://IRISAPP\"` - Define the URL of the IRIS namespace.\n- `engine = init_db(url)` - Create a database engine for the sqlmodel ORM.\n\n### `models.py`\n\nThis file contains the models for the application.\n\n```python\nfrom sqlmodel import Field, SQLModel, Relationship, create_engine\n\nclass Comment(SQLModel, table=True):\n    id: int = Field(default=None, primary_key=True)\n    post_id: int = Field(foreign_key=\"post.id\")\n    content: str\n    post: \"Post\" = Relationship(back_populates=\"comments\")\n\nclass Post(SQLModel, table=True):\n    id: int = Field(default=None, primary_key=True)\n    title: str\n    content: str\n    comments: list[\"Comment\"] = Relationship(back_populates=\"post\")\n```\n\nNot much to say here, just the definition of the models with foreign keys and relationships.\n\nThe `init_db` function is used to create the database engine.\n\n```python\ndef init_db(url):\n\n    engine = create_engine(url)\n\n    # create the tables\n    SQLModel.metadata.drop_all(engine)\n    SQLModel.metadata.create_all(engine)\n\n    # initialize database with fake data\n    from sqlmodel import Session\n\n    with Session(engine) as session:\n        # Create fake data\n        post1 = Post(title='Post The First', content='Content for the first post')\n        ...\n        session.add(post1)\n        ...\n        session.commit()\n\n    return engine\n```\n\n- `engine = create_engine(url)` - Create a database engine.\n- `SQLModel.metadata.drop_all(engine)` - Drop all the tables.\n- `SQLModel.metadata.create_all(engine)` - Create all the tables.\n- `with Session(engine) as session:` - Create a session to interact with the database.\n- `post1 = Post(title='Post The First', content='Content for the first post')` - Create a Post object.\n- `session.add(post1)` - Add the Post object to the session.\n- `session.commit()` - Commit the changes to the database.\n- `return engine` - Return the database engine.\n\n### `/iris` endpoint\n\n```python\n######################\n# IRIS Query example #\n######################\n\n@app.get(\"/iris\")\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 result\n```\n\n- `@app.get(\"/iris\")` - Define a GET route for the `/iris` endpoint.\n- `query = \"SELECT top 10 * FROM %Dictionary.ClassDefinition\"` - Define the query to get the top 10 classes in the IRIS namespace.\n- `rs = iris.sql.exec(query)` - Execute the query.\n- `result = []` - Create an empty list to store the results.\n- `for row in rs:` - Iterate over the result set.\n- `result.append(row)` - Append the row to the result list.\n- `return result` - Return the result list.\n\n### `/interop` endpoint\n\n```python\n########################\n# IRIS interop example #\n########################\nbs = Director.create_python_business_service('BS')\n\n@app.get(\"/interop\")\n@app.post(\"/interop\")\n@app.put(\"/interop\")\n@app.delete(\"/interop\")\ndef interop(request: Request):\n    \n    rsp = bs.on_process_input(request)\n\n    return rsp\n\n```\n\n- `bs = Director.create_python_business_service('BS')` - Create a Python business service.\n  - Must be created outside the route definition to prevent multiple instances of the business service.\n- `@app.get(\"/interop\")` - Define a GET route for the `/interop` endpoint.\n- `@app.post(\"/interop\")` - Define a POST route for the `/interop` endpoint.\n- ...\n- `def interop(request: Request):` - Define the route handler.\n- `rsp = bs.on_process_input(request)` - Call the `on_process_input` method of the business service.\n- `return rsp` - Return the response.\n\n### `/posts` endpoint\n\n```python\n############################\n# CRUD operations posts    #\n############################\n\n@app.get(\"/posts\")\ndef get_posts():\n    with Session(engine) as session:\n        posts = session.exec(select(Post)).all()\n        return posts\n    \n@app.get(\"/posts/{post_id}\")\ndef get_post(post_id: int):\n    with Session(engine) as session:\n        post = session.get(Post, post_id)\n        return post\n    \n@app.post(\"/posts\")\ndef create_post(post: Post):\n    with Session(engine) as session:\n        session.add(post)\n        session.commit()\n        return post\n```\n\nThis endpoint is used to perform CRUD operations on the `Post` object.\n\nNote much to say here, just the definition of the routes to get all posts, get a post by id, and create a post.\n\nEverything is done using the sqlmodel ORM.\n\n### `/comments` endpoint\n\n```python\n############################\n# CRUD operations comments #\n############################\n\n\n@app.get(\"/comments\")\ndef get_comments():\n    with Session(engine) as session:\n        comments = session.exec(select(Comment)).all()\n        return comments\n    \n@app.get(\"/comments/{comment_id}\")\ndef get_comment(comment_id: int):\n    with Session(engine) as session:\n        comment = session.get(Comment, comment_id)\n        return comment\n    \n@app.post(\"/comments\")\ndef create_comment(comment: Comment):\n    with Session(engine) as session:\n        session.add(comment)\n        session.commit()\n        return comment\n```\n\nThis endpoint is used to perform CRUD operations on the `Comment` object.\n\nNote much to say here, just the definition of the routes to get all comments, get a comment by id, and create a comment.\n\nEverything is done using the sqlmodel ORM.\n\n## Troubleshooting\n\n### How to run the FastAPI 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-fastapi-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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrongierisc%2Firis-fastapi-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrongierisc%2Firis-fastapi-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrongierisc%2Firis-fastapi-template/lists"}