{"id":28625322,"url":"https://github.com/marwan116/raycraft","last_synced_at":"2026-05-18T19:37:25.449Z","repository":{"id":205683618,"uuid":"714151898","full_name":"marwan116/raycraft","owner":"marwan116","description":"A drop-in replacement of fastapi to enable scalable and fault tolerant deployments with ray serve","archived":false,"fork":false,"pushed_at":"2023-11-07T16:21:02.000Z","size":209,"stargazers_count":1,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-05T02:02:05.291Z","etag":null,"topics":["fastapi","fault-tolerance","ray","ray-serve","scalability"],"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/marwan116.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2023-11-04T03:58:02.000Z","updated_at":"2023-11-07T16:00:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"d89d337a-8484-45df-a31f-e7bce12c4ef7","html_url":"https://github.com/marwan116/raycraft","commit_stats":null,"previous_names":["marwan116/raycraft"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/marwan116/raycraft","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marwan116%2Fraycraft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marwan116%2Fraycraft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marwan116%2Fraycraft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marwan116%2Fraycraft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marwan116","download_url":"https://codeload.github.com/marwan116/raycraft/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marwan116%2Fraycraft/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273220553,"owners_count":25066408,"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","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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","fault-tolerance","ray","ray-serve","scalability"],"created_at":"2025-06-12T08:10:16.763Z","updated_at":"2026-05-18T19:37:20.423Z","avatar_url":"https://github.com/marwan116.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RayCraft\n\n## Motivation\nFastAPI + Ray = \u003c3\n\nLet's take a FastAPI app and supercharge it with raycraft\n\n```python\nfrom fastapi import FastAPI\n\nsimple_service = FastAPI()\n\n@simple_service.post(\"/\")\nasync def read_root() -\u003e dict[str, str]:\n    return {\"Hello\": \"World\"}\n```\n\nYou can now run it using raycraft using the RayCraftAPI instead of FastAPI with only two lines of code changes\n\n```diff\n+ from raycraft import RayCraftAPI\n\n+ simple_service = RayCraftAPI()\n\n@simple_service.post(\"/\")\nasync def read_root() -\u003e dict[str, str]:\n    return {\"Hello\": \"World\"}\n```\n\n## How to use\n\n### Basic example\nOk so an endpoint returning {\"Hello\": \"World\"} isn't going to be enough to serve as a basic example so let's try something more interesting and relevant to why you might want to use raycraft!\n\nLet's say you build a translation service using the following fastAPI code:\n\n```python\nfrom fastapi import FastAPI\nfrom transformers import pipeline\n\napp = FastAPI()\n\ndef load_model():\n    return pipeline(\"translation_en_to_fr\", model=\"t5-small\")\n\n@app.post(\"/\")\nasync def translate(text: str):\n    model = load_model()\n    translated = model(text)[0][\"translation_text\"]\n    return {\"translation\": translated}\n```\n\nWe can now build this app using raycraft with the same two lines of code changes\n\n```python\nfrom raycraft import RayCraftAPI\nfrom transformers import pipeline\n\napp = RayCraftAPI()\n\ndef load_model():\n    return pipeline(\"translation_en_to_fr\", model=\"t5-small\")\n\ndef translate(text: str):\n    model = load_model()\n    translated = model(text)[0][\"translation_text\"]\n    return translated\n\n@app.post(\"/\")\nasync def translate(text: str):\n    return translate(text)    \n```\n\nWe then call the following command to run the app:\n```bash\nraycraft run demo:app\n```\n\nOk now for the distributed part, let's say we want to run this app on 2 \"replicas\", each \"replica\" taking half a GPU, and we want to properly load balance between the replicas, we can do this by running the following command:\n\n```python\nfrom raycraft import RayCraftAPI\nfrom transformers import pipeline\n\napp = RayCraftAPI(ray_actor_options={\"num_gpus\": 0.5}, num_replicas=2)\n\ndef load_model():\n    return pipeline(\"translation_en_to_fr\", model=\"t5-small\")\n\ndef translate(text: str):\n    model = load_model()\n    translated = model(text)[0][\"translation_text\"]\n    return translated\n\n@app.post(\"/\")\nasync def translate(text: str):\n    return translate(text)    \n```\n\nTo avoid loading the model on every request, we can load the model in the constructor of the app:\n\n```python\nfrom raycraft import RayCraftAPI, App\nfrom transformers import pipeline\n\napp = RayCraftAPI(ray_actor_options={\"num_gpus\": 0.5}, num_replicas=2)\n\n@app.init\ndef model():\n    return pipeline(\"translation_en_to_fr\", model=\"t5-small\")\n\ndef translate(app: App, text: str):\n    translated = app.model(text)[0][\"translation_text\"]\n    return translated\n\n@app.post(\"/\")\nasync def translate(app: App, text: str):\n    return translate(app, text) \n```\n\nRayCraft is a thin-layer built on top of [Ray Serve](https://docs.ray.io/en/latest/serve/index.html) adopting a functional interface to ease the migration from fastAPI apps.\n\nWith Ray Serve, you can now:\n- Scale your app deployment to multiple replicas running on different machines\n- Define the resources allocated to each replica including fractional GPUs\n- Batch requests together to improve throughput\n- Get fault tolerance and automatic retries\n- Stream responses using websockets\n- Compose different services together using RPC calls that are strictly typed and faster than http requests\n\n\u003c!-- \n### Advanced example\n\nOk now let's say we want to improve the throughput of our translation service by batching requests together, we can do this by using the `batch` decorator:\n\n```python\nfrom raycraft import RayCraftAPI, App\nfrom transformers import pipeline\n\napp = RayCraftAPI(ray_actor_options={\"num_gpus\": 0.5}, num_replicas=2)\n\n@app.init\ndef model():\n    return pipeline(\"translation_en_to_fr\", model=\"t5-small\")\n\ndef translate(text: str):\n    model = load_model()\n    translated = model(text)[0][\"translation_text\"]\n    return translated\n\n@app.batch(max_batch_size=32, batch_timeout=0.1)\n@app.post(\"/\")\nasync def translate(app: App, text: str):\n    return translate(text) \n``` --\u003e\n\n\n### Composing models\n\n\n## How to setup\n\nUsing poetry:\n\n```bash\npoetry add raycraft\n```\n\nUsing pip:\n\n```bash\npip install raycraft\n```\n\n\n## Roadmap\n- Streaming support using websockets\n- Deployment guide\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarwan116%2Fraycraft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarwan116%2Fraycraft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarwan116%2Fraycraft/lists"}