{"id":23217018,"url":"https://github.com/novitalabs/python-sdk","last_synced_at":"2025-08-19T08:31:33.505Z","repository":{"id":217802757,"uuid":"697093484","full_name":"novitalabs/python-sdk","owner":"novitalabs","description":"Python SDK for Novita AI API (Txt2Img, Img2Img, Txt2Video, Img2Video, Doodle, Remove Background, Replace Object, Reimagine, Merge Faces, ControlNet, VAE, LoRA)","archived":false,"fork":false,"pushed_at":"2024-08-23T06:33:51.000Z","size":452,"stargazers_count":8,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-23T07:42:59.302Z","etag":null,"topics":["controlnet","img2img","img2video","lora","stable-diffusion","swapface","txt2img","txt2video"],"latest_commit_sha":null,"homepage":"https://novita.ai","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/novitalabs.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":"2023-09-27T03:27:34.000Z","updated_at":"2024-08-23T06:33:54.000Z","dependencies_parsed_at":"2024-01-18T10:44:23.664Z","dependency_job_id":"a048b113-4add-4c3a-858d-5cf3c95c3ce6","html_url":"https://github.com/novitalabs/python-sdk","commit_stats":null,"previous_names":["novitalabs/python-sdk"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novitalabs%2Fpython-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novitalabs%2Fpython-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novitalabs%2Fpython-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novitalabs%2Fpython-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/novitalabs","download_url":"https://codeload.github.com/novitalabs/python-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230339399,"owners_count":18211152,"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","img2img","img2video","lora","stable-diffusion","swapface","txt2img","txt2video"],"created_at":"2024-12-18T20:39:35.077Z","updated_at":"2024-12-18T20:39:35.607Z","avatar_url":"https://github.com/novitalabs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Novita AI Python SDK\n\nThis SDK is based on the official [API documentation](https://docs.novita.ai/).\n\n**Join our discord server for help:**\n\n[![](https://dcbadge.vercel.app/api/server/Mqx7nWYzDF)](https://discord.com/invite/Mqx7nWYzDF)\n\n## Installation\n\n```bash\npip install novita-client\n```\n\n## Examples\n\n- [fine tune example](https://colab.research.google.com/drive/1j_ii9TN67nuauvc3PiauwZnC2lT62tGF?usp=sharing)\n- [cleanup](./examples/cleanup.py)\n- [controlnet](./examples/controlnet.py)\n- [img2img](./examples/img2img.py)\n- [img2video](./examples/img2video.py)\n- [inpainting](./examples/inpainting.py)\n- [instantid](./examples/instantid.py)\n- [merge-face](./examples/merge-face.py)\n- [model-search](./examples/model-search.py)\n- [reimagine](./examples/reimagine.py)\n- [remove-background](./examples/remove-background.py)\n- [remove-text](./examples/remove-text.py)\n- [replace-background](./examples/replace-background.py)\n- [txt2img-with-hiresfix](./examples/txt2img-with-hiresfix.py)\n- [txt2img-with-lora](./examples/txt2img-with-lora.py)\n- [txt2img-with-refiner](./examples/txt2img-with-refiner.py)\n- [txt2video](./examples/txt2video.py)\n## Code Examples\n\n### cleanup\n```python\nimport os\n\nfrom novita_client import NovitaClient\nfrom novita_client.utils import base64_to_image\n\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\nres = client.cleanup(\n    image=\"https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png\",\n    mask=\"https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png\"\n)\n\nbase64_to_image(res.image_file).save(\"./cleanup.png\")\n```\n\n### controlnet\n```python\n#!/usr/bin/env python\n# -*- coding: UTF-8 -*-\n\nimport os\n\nfrom novita_client import NovitaClient, Img2ImgV3Request, Img2ImgV3ControlNetUnit, ControlnetUnit, Samplers, Img2ImgV3Embedding\nfrom novita_client.utils import base64_to_image\n\n\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\nres = client.img2img_v3(\n    input_image=\"https://img.freepik.com/premium-photo/close-up-dogs-face-with-big-smile-generative-ai_900101-62851.jpg\",\n    model_name=\"dreamshaper_8_93211.safetensors\",\n    prompt=\"a cute dog\",\n    sampler_name=Samplers.DPMPP_M_KARRAS,\n    width=512,\n    height=512,\n    steps=30,\n    controlnet_units=[\n        Img2ImgV3ControlNetUnit(\n            image_base64=\"https://img.freepik.com/premium-photo/close-up-dogs-face-with-big-smile-generative-ai_900101-62851.jpg\",\n            model_name=\"control_v11f1p_sd15_depth\",\n            strength=1.0\n        )\n    ],\n    embeddings=[Img2ImgV3Embedding(model_name=_) for _ in [\n        \"BadDream_53202\",\n    ]],\n    seed=-1,\n)\n\n\nbase64_to_image(res.images_encoded[0]).save(\"./img2img-controlnet.png\")\n```\n\n### img2img\n```python\nimport pdb\nimport os\n\nfrom novita_client import NovitaClient, Img2ImgV3ControlNetUnit, ControlNetPreprocessor, Img2ImgV3Embedding\nfrom novita_client.utils import base64_to_image, input_image_to_pil\n\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\nres = client.img2img_v3(\n    model_name=\"MeinaHentai_V5.safetensors\",\n    steps=30,\n    height=512,\n    width=512,\n    input_image=\"https://img.freepik.com/premium-photo/close-up-dogs-face-with-big-smile-generative-ai_900101-62851.jpg\",\n    prompt=\"1 cute dog\",\n    strength=0.5,\n    guidance_scale=7,\n    embeddings=[Img2ImgV3Embedding(model_name=_) for _ in [\n        \"bad-image-v2-39000\",\n        \"verybadimagenegative_v1.3_21434\",\n        \"BadDream_53202\",\n        \"badhandv4_16755\",\n        \"easynegative_8955.safetensors\"]],\n    seed=-1,\n    sampler_name=\"DPM++ 2M Karras\",\n    clip_skip=2,\n    # controlnet_units=[Img2ImgV3ControlNetUnit(\n    #     model_name=\"control_v11f1p_sd15_depth\",\n    #     preprocessor=\"depth\",\n    #     image_base64=\"./20240309-003206.jpeg\",\n    #     strength=1.0\n    # )]\n)\n\nbase64_to_image(res.images_encoded[0]).save(\"./img2img.png\")\n```\n\n### img2video\n```python\nimport os\n\nfrom novita_client import NovitaClient\nfrom novita_client.utils import base64_to_image\n\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URNOVITA_API_URII', None))\nres = client.img2video(\n    model_name=\"SVD-XT\",\n    steps=30,\n    frames_num=25,\n    image=\"https://replicate.delivery/pbxt/JvLi9smWKKDfQpylBYosqQRfPKZPntuAziesp0VuPjidq61n/rocket.png\",\n    enable_frame_interpolation=True\n)\n\n\nwith open(\"test.mp4\", \"wb\") as f:\n    f.write(res.video_bytes[0])\n```\n\n### inpainting\n```python\nimport os\nimport base64\nfrom novita_client import NovitaClient\nfrom novita_client.utils import base64_to_image\n\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\nres = client.inpainting(\n    model_name = \"realisticVisionV40_v40VAE-inpainting_81543.safetensors\",\n    image=\"https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png\",\n    mask=\"https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png\",\n    seed=1,\n    guidance_scale=15,\n    steps = 20,\n    image_num = 4,\n    prompt = \"black rabbit\",\n    negative_prompt = \"white rabbit\",\n    sampler_name = \"Euler a\",\n    inpainting_full_res = 1,\n    inpainting_full_res_padding = 32,\n    inpainting_mask_invert = 0,\n    initial_noise_multiplier = 1,\n    mask_blur = 1,\n    clip_skip = 1,\n    strength = 0.85,\n)\nwith open(\"result/result_image/inpaintingsdk.jpeg\", \"wb\") as image_file:\n    image_file.write(base64.b64decode(res.images_encoded[0]))```\n\n### instantid\n```python\n\nimport os\nfrom novita_client import NovitaClient, InstantIDControlnetUnit\nimport base64\n\n\n\nif __name__ == '__main__':\n\tclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\n\n\tres = client.instant_id(\n\t\tmodel_name=\"sdxlUnstableDiffusers_v8HEAVENSWRATH_133813.safetensors\",\n\t\tface_images=[\n\t\t\t\"https://raw.githubusercontent.com/InstantID/InstantID/main/examples/yann-lecun_resize.jpg\",\n\t\t],\n\t\tprompt=\"Flat illustration, a Chinese a man, ancient style, wearing a red cloth, smile face, white skin, clean background, fireworks blooming, red lanterns\",\n\t\tnegative_prompt=\"(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, photo, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green\",\n\t\tid_strength=0.8,\n\t\tadapter_strength=0.8,\n\t\tsteps=20,\n\t\tseed=42,\n\t\twidth=1024,\n\t\theight=1024,\n\t\tcontrolnets=[\n\t\t\tInstantIDControlnetUnit(\n\t\t\t\tmodel_name='controlnet-openpose-sdxl-1.0',\n\t\t\t\tstrength=0.4,\n\t\t\t\tpreprocessor='openpose',\n\t\t\t),\n\t\t\tInstantIDControlnetUnit(\n\t\t\t\tmodel_name='controlnet-canny-sdxl-1.0',\n\t\t\t\tstrength=0.3,\n\t\t\t\tpreprocessor='canny',\n\t\t\t),\n\t\t],\n\t\tresponse_image_type='jpeg',\n\t\tenterprise_plan=False,\n\t)\n\n\tprint('res:', res)\n\n\tif hasattr(res, 'images_encoded'):\n\t\twith open(f\"instantid.png\", \"wb\") as f:\n\t\t\tf.write(base64.b64decode(res.images_encoded[0]))\n```\n\n### merge-face\n```python\nimport os\n\nfrom novita_client import NovitaClient\nfrom novita_client.utils import base64_to_image\n\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\nres = client.merge_face(\n    image=\"https://toppng.com/uploads/preview/cut-out-people-png-personas-en-formato-11563277290kozkuzsos5.png\",\n    face_image=\"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQDy7sXtuvCNUQoQZvTbLRbX6qK9_kP3PlQfg\u0026s\",\n    enterprise_plan=False,\n)\n\nbase64_to_image(res.image_file).save(\"./merge_face.png\")\n```\n\n### model-search\n```python\n#!/usr/bin/env python\n# -*- coding: UTF-8 -*-\n\nfrom novita_client import NovitaClient, ModelType\n# get your api key refer to https://docs.novita.ai/get-started/\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\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### reimagine\n```python\nimport os\n\nfrom novita_client import NovitaClient\nfrom novita_client.utils import base64_to_image\n\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\nres = client.reimagine(\n    image=\"/home/anyisalin/develop/novita-client-python/examples/doodle-generated.png\"\n)\n\nbase64_to_image(res.image_file).save(\"./reimagine.png\")\n```\n\n### remove-background\n```python\nimport os\n\nfrom novita_client import NovitaClient\nfrom novita_client.utils import base64_to_image\n\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\nres = client.remove_background(\n    image=\"https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png\",\n)\nbase64_to_image(res.image_file).save(\"./remove_background.png\")\n```\n\n### remove-text\n```python\nimport os\n\nfrom novita_client import NovitaClient\nfrom novita_client.utils import base64_to_image\n\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\nres = client.remove_text(\n    image=\"https://images.uiiiuiii.com/wp-content/uploads/2023/07/i-banner-20230714-1.jpg\"\n)\n\nbase64_to_image(res.image_file).save(\"./remove_text.png\")\n```\n\n### replace-background\n```python\nimport os\n\nfrom novita_client import NovitaClient\nfrom novita_client.utils import base64_to_image\n\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\nres = client.replace_background(\n    image=\"./telegram-cloud-photo-size-2-5408823814353177899-y.jpg\",\n    prompt=\"in living room, Christmas tree\",\n)\nbase64_to_image(res.image_file).save(\"./replace_background.png\")\n```\n\n### txt2img-with-hiresfix\n```python\nimport os\n\nfrom novita_client import NovitaClient, Samplers, Txt2ImgV3HiresFix\nfrom novita_client.utils import base64_to_image\n\nfrom PIL import Image\n\n\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\nres = client.txt2img_v3(\n    model_name='dreamshaper_8_93211.safetensors',\n    prompt=\"a cute girl\",\n    width=384,\n    height=512,\n    image_num=1,\n    guidance_scale=7.5,\n    seed=12345,\n    sampler_name=Samplers.EULER_A,\n    hires_fix=Txt2ImgV3HiresFix(\n        # upscaler='Latent'\n        target_width=768,\n        target_height=1024,\n        strength=0.5\n    )\n)\n\n\nbase64_to_image(res.images_encoded[0]).save(\"./txt2img_with_hiresfix.png\")\n```\n\n### txt2img-with-lora\n```python\n#!/usr/bin/env python\n# -*- coding: UTF-8 -*-\n\nimport os\nfrom novita_client import NovitaClient, Txt2ImgV3LoRA, Samplers, ProgressResponseStatusCode, ModelType, add_lora_to_prompt, save_image\nfrom novita_client.utils import base64_to_image, input_image_to_pil\nfrom PIL import Image\n\n\ndef make_image_grid(images, rows: int, cols: int, resize: int = None):\n    \"\"\"\n    Prepares a single grid of images. Useful for visualization purposes.\n    \"\"\"\n    assert len(images) == rows * cols\n\n    if resize is not None:\n        images = [img.resize((resize, resize)) for img in images]\n\n    w, h = images[0].size\n    grid = Image.new(\"RGB\", size=(cols * w, rows * h))\n\n    for i, img in enumerate(images):\n        grid.paste(img, box=(i % cols * w, i // cols * h))\n    return grid\n\n\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\n\nres1 = client.txt2img_v3(\n    prompt=\"a photo of handsome man, close up\",\n    image_num=1,\n    guidance_scale=7.0,\n    sampler_name=Samplers.DPMPP_M_KARRAS,\n    model_name=\"dreamshaper_8_93211.safetensors\",\n    height=512,\n    width=512,\n    seed=1024,\n)\nres2 = client.txt2img_v3(\n    prompt=\"a photo of handsome man, close up\",\n    image_num=1,\n    guidance_scale=7.0,\n    sampler_name=Samplers.DPMPP_M_KARRAS,\n    model_name=\"dreamshaper_8_93211.safetensors\",\n    height=512,\n    width=512,\n    seed=1024,\n    loras=[\n        Txt2ImgV3LoRA(\n           model_name=\"add_detail_44319\",\n           strength=0.9,\n        )\n    ]\n)\n\nmake_image_grid([base64_to_image(res1.images_encoded[0]), base64_to_image(res2.images_encoded[0])], 1, 2, 512).save(\"./txt2img-lora-compare.png\")\n```\n\n### txt2img-with-refiner\n```python\nimport os\n\nfrom novita_client import NovitaClient, Txt2ImgV3Refiner, Samplers\nfrom novita_client.utils import base64_to_image\nfrom PIL import Image\n\n\ndef make_image_grid(images, rows: int, cols: int, resize: int = None):\n    \"\"\"\n    Prepares a single grid of images. Useful for visualization purposes.\n    \"\"\"\n    assert len(images) == rows * cols\n\n    if resize is not None:\n        images = [img.resize((resize, resize)) for img in images]\n\n    w, h = images[0].size\n    grid = Image.new(\"RGB\", size=(cols * w, rows * h))\n\n    for i, img in enumerate(images):\n        grid.paste(img, box=(i % cols * w, i // cols * h))\n    return grid\n\n\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\n\nr1 = client.txt2img_v3(\n    model_name='sd_xl_base_1.0.safetensors',\n    prompt='a astronaut riding a bike on the moon',\n    width=1024,\n    height=1024,\n    image_num=1,\n    guidance_scale=7.5,\n    sampler_name=Samplers.EULER_A,\n)\n\nr2 = client.txt2img_v3(\n    model_name='sd_xl_base_1.0.safetensors',\n    prompt='a astronaut riding a bike on the moon',\n    width=1024,\n    height=1024,\n    image_num=1,\n    guidance_scale=7.5,\n    sampler_name=Samplers.EULER_A,\n    refiner=Txt2ImgV3Refiner(\n        switch_at=0.7\n    )\n)\n\nr3 = client.txt2img_v3(\n    model_name='sd_xl_base_1.0.safetensors',\n    prompt='a astronaut riding a bike on the moon',\n    width=1024,\n    height=1024,\n    image_num=1,\n    guidance_scale=7.5,\n    sampler_name=Samplers.EULER_A,\n    refiner=Txt2ImgV3Refiner(\n        switch_at=0.5\n    )\n)\n\n\nmake_image_grid([base64_to_image(r1.images_encoded[0]), base64_to_image(r2.images_encoded[0]), base64_to_image(r3.images_encoded[0])], 1, 3, 1024).save(\"./txt2img-refiner-compare.png\")\n```\n\n### txt2video\n```python\nimport os\n\nfrom novita_client import NovitaClient\nfrom novita_client.utils import save_image\n\nclient = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))\nres = client.txt2video(\n        model_name = \"dreamshaper_8_93211.safetensors\",\n        prompts = [{\n                    \"prompt\": \"A girl, baby, portrait, 5 years old\",\n                    \"frames\": 16,},\n                    {\n                    \"prompt\": \"A girl, child, portrait, 10 years old\",\n                    \"frames\": 16,\n                    }\n                    ],\n        steps = 20,\n        guidance_scale = 10,\n        height = 512,\n        width = 768,\n        clip_skip = 4,\n        negative_prompt = \"a rainy day\",\n        response_video_type = \"mp4\",\n    )\nsave_image(res.video_bytes[0], 'output.mp4')\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnovitalabs%2Fpython-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnovitalabs%2Fpython-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnovitalabs%2Fpython-sdk/lists"}