Skip to main content

A lightweight async wrapper for NovelAI image generation API

Project description

NovelAI Icon NovelAI-API

A lightweight asynchronous Python wrapper for NovelAI image generation API. Supports both web and api backend.

Installation

pip install novelai

Usage

Initialization

import asyncio
from novelai import NAIClient

# Replace argument values with your actual account credentials
username = "Your NovelAI username"
password = "Your NovelAI password"

async def main():
    client = NAIClient(username, password, proxy=None)
    await client.init()

asyncio.run(main())

Generate

from pathlib import Path

async def main():
    # Choose host between "api" and "web"
    output = await client.generate_image(prompt="1girl", host="api")

    path = Path("output")
    path.mkdir(parents=True, exist_ok=True)

    for filename, data in output.items():
        Path(path / filename).write_bytes(data)

asyncio.run(main())

Use in CLI

Optionally, a module function is also provided to directly generate access token in CLI.

Once a access token is generated, it will be valid for 30 days. Token can be used as the authentication header to make requests to NovelAI.

# Replace argument values with your actual account credentials
python3 -m novelai login <username> <password>

References

NovelAI Backend

Aedial/novelai-api

NovelAI Unofficial Knowledgebase

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

novelai-0.1.0.tar.gz (16.6 kB view hashes)

Uploaded Source

Built Distribution

novelai-0.1.0-py3-none-any.whl (12.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page