{"id":22677780,"url":"https://github.com/omniinfer/python-sdk","last_synced_at":"2025-04-12T14:24:58.641Z","repository":{"id":186521727,"uuid":"675058905","full_name":"omniinfer/python-sdk","owner":"omniinfer","description":"Python SDK for Stable Diffusion API (Txt2Img/Img2Img/ControlNet/VAE)","archived":false,"fork":false,"pushed_at":"2023-09-03T15:56:29.000Z","size":43,"stargazers_count":40,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-21T19:49:45.305Z","etag":null,"topics":["controlnet","stable-diffusion","stable-diffusion-api","txt2img","vae"],"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/omniinfer.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}},"created_at":"2023-08-05T16:27:00.000Z","updated_at":"2025-02-18T03:16:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"5b44b854-43d8-4e61-95a2-3e9503f5bb33","html_url":"https://github.com/omniinfer/python-sdk","commit_stats":null,"previous_names":["omniinfer/python-sdk"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omniinfer%2Fpython-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omniinfer%2Fpython-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omniinfer%2Fpython-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omniinfer%2Fpython-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/omniinfer","download_url":"https://codeload.github.com/omniinfer/python-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248579215,"owners_count":21127777,"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":["controlnet","stable-diffusion","stable-diffusion-api","txt2img","vae"],"created_at":"2024-12-09T18:01:16.691Z","updated_at":"2025-04-12T14:24:58.612Z","avatar_url":"https://github.com/omniinfer.png","language":"Python","readme":"# Omniinfer Python SDK\n\nThanks to the initial contribution of [@shanginn](https://github.com/shanginn), we have made the decision to create this SDK.\n\nthis SDK is based on the official [API documentation](https://docs.omniinfer.io/)\n\n**join our discord server for help**\n\n[![](https://dcbadge.vercel.app/api/server/nzqq8UScpx)](https://discord.gg/nzqq8UScpx) \n\n## Installation\n\n```bash\npip install omniinfer-client\n```\n\n## Quick Start\n\n**Get api key refer to [https://docs.omniinfer.io/get-started](https://docs.omniinfer.io/get-started/)**\n\n```python\nimport os\nfrom omniinfer_client import OmniClient, Txt2ImgRequest, Samplers, ModelType, save_image\n\nclient = OmniClient(os.getenv('OMNI_API_KEY'))\n\nreq = Txt2ImgRequest(\n    model_name='sd_xl_base_1.0.safetensors',\n    prompt='a dog flying in the sky',\n    batch_size=1,\n    cfg_scale=7.5,\n    height=1024,\n    width=1024,\n    sampler_name=Samplers.EULER_A,\n)\nsave_image(client.sync_txt2img(req).data.imgs_bytes[0], 'output.png')\n```\n\n## Examples\n\n[txt2img_with_lora.py](./examples/txt2img_with_lora.py)\n\n```python\n#!/usr/bin/env python\n# -*- coding: UTF-8 -*-\n\nimport os\nfrom omniinfer_client import OmniClient, Txt2ImgRequest, Samplers, ProgressResponseStatusCode, ModelType, add_lora_to_prompt, save_image\n\n\nclient = OmniClient(os.getenv('OMNI_API_KEY'))\nmodels = client.models()\n\n# Anything V5/Ink, https://civitai.com/models/9409/or-anything-v5ink\ncheckpoint_model = models.filter_by_type(ModelType.CHECKPOINT).get_by_civitai_version_id(90854)\n\n# Detail Tweaker LoRA, https://civitai.com/models/58390/detail-tweaker-lora-lora\nlora_model = models.filter_by_type(ModelType.LORA).get_by_civitai_version_id(62833)\n\nprompt = add_lora_to_prompt('a dog flying in the sky', lora_model.sd_name, \"0.8\")\n\nres = client.sync_txt2img(Txt2ImgRequest(\n    prompt=prompt,\n    batch_size=1,\n    cfg_scale=7.5,\n    sampler_name=Samplers.EULER_A,\n    model_name=checkpoint_model.sd_name,\n    seed=103304,\n))\n\nif res.data.status != ProgressResponseStatusCode.SUCCESSFUL:\n    raise Exception('Failed to generate image with error: ' +\n                    res.data.failed_reason)\nsave_image(res.data.imgs_bytes[0], \"test.png\")\n```\n\n### Model Search\n\n[model_search.py](./examples/model_search.py)\n\n```python\nfrom omniinfer_client import OmniClient, ModelType\n\nclient = OmniClient(os.getenv('OMNI_API_KEY'))\n\n# filter by model type\nprint(\"lora count\", len(client.models().filter_by_type(ModelType.LORA)))\nprint(\"checkpoint count\", len(client.models().filter_by_type(ModelType.CHECKPOINT)))\nprint(\"textinversion count\", len(\n    client.models().filter_by_type(ModelType.TEXT_INVERSION)))\nprint(\"vae count\", len(client.models().filter_by_type(ModelType.VAE)))\nprint(\"controlnet count\", len(client.models().filter_by_type(ModelType.CONTROLNET)))\n\n\n# filter by civitai tags\nclient.models().filter_by_civi_tags('anime')\n\n# filter by nsfw\nclient.models().filter_by_nsfw(False)  # or True\n\n# sort by civitai download\nclient.models().sort_by_civitai_download()\n\n# chain filters\nclient.models().\\\n    filter_by_type(ModelType.CHECKPOINT).\\\n    filter_by_nsfw(False).\\\n    filter_by_civitai_tags('anime')\n```\n\n### ControlNet QRCode\n\n[controlnet_qrcode.py](./examples/controlnet_qrcode.py)\n\n```python\nimport os\n\nfrom omniinfer_client import *\n\n# get your api key refer to https://docs.omniinfer.io/get-started/\nclient = OmniClient(os.getenv('OMNI_API_KEY'))\n\ncontrolnet_model = client.models().filter_by_type(ModelType.CONTROLNET).get_by_name(\"control_v1p_sd15_qrcode_monster_v2\")\nif controlnet_model is None:\n    raise Exception(\"controlnet model not found\")\n\nreq = Txt2ImgRequest(\n    prompt=\"a beautify butterfly in the colorful flowers, best quality, best details, masterpiece\",\n    sampler_name=Samplers.DPMPP_M_KARRAS,\n    width=512,\n    height=512,\n    steps=30,\n    controlnet_units=[\n        ControlnetUnit(\n            input_image=read_image_to_base64(os.path.join(os.path.abspath(os.path.dirname(__file__)), \"fixtures/qrcode.png\")),\n            control_mode=ControlNetMode.BALANCED,\n            model=controlnet_model.sd_name,\n            module=ControlNetPreprocessor.NULL,\n            resize_mode=ControlNetResizeMode.JUST_RESIZE,\n            weight=2.0,\n        )\n    ]\n)\n\nres = client.sync_txt2img(req)\nif res.data.status != ProgressResponseStatusCode.SUCCESSFUL:\n    raise Exception('Failed to generate image with error: ' +\n                    res.data.failed_reason)\n\nsave_image(res.data.imgs_bytes[0], \"qrcode-art.png\")\n```\n\n### Txt2Img with Hires.Fix\n\n[txt2img_with_hiresfix.py](./examples/txt2img_with_hiresfix.py)\n\n```python\nimport os\n\nfrom omniinfer_client import *\n\nclient = OmniClient(os.getenv('OMNI_API_KEY'))\nreq = Txt2ImgRequest(\n    model_name='dreamshaper_8_93211.safetensors',\n    prompt='a dog flying in the sky',\n    width=512,\n    height=512,\n    batch_size=1,\n    cfg_scale=7.5,\n    sampler_name=Samplers.EULER_A,\n    enable_hr=True,\n    hr_scale=2.0\n)\n\nres = client.sync_txt2img(req)\nif res.data.status != ProgressResponseStatusCode.SUCCESSFUL:\n    raise Exception('Failed to generate image with error: ' +\n                    res.data.failed_reason)\n\nsave_image(res.data.imgs_bytes[0], \"txt2img-hiresfix-1024.png\")\n```\n\n### SDXL Refiner\n\n[sdxl_refiner.py](./txt2img_with_refiner.py)\n\n```python\nimport os\n\nfrom omniinfer_client import *\n\nclient = OmniClient(os.getenv('OMNI_API_KEY'))\nreq = Txt2ImgRequest(\n    model_name='sd_xl_base_1.0.safetensors',\n    prompt='a dog flying in the sky',\n    width=1024,\n    height=1024,\n    batch_size=1,\n    cfg_scale=7.5,\n    sampler_name=Samplers.EULER_A,\n    sd_refiner=Refiner(\n        checkpoint='sd_xl_refiner_1.0.safetensors',\n        switch_at=0.5,\n    ))\n\nres = client.sync_txt2img(req)\nif res.data.status != ProgressResponseStatusCode.SUCCESSFUL:\n    raise Exception('Failed to generate image with error: ' +\n                    res.data.failed_reason)\n\nsave_image(res.data.imgs_bytes[0], \"txt2img-refiner.png\")\n```\n\n\n## Testing\n\n```\nexport OMNI_API_KEY=\u003cYOUR_API_KEY\u003e\n\npython -m pytest\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomniinfer%2Fpython-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fomniinfer%2Fpython-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomniinfer%2Fpython-sdk/lists"}