Skip to main content

Python API for the NovelAI REST API

Project description

novelai-api

Python API for the NovelAI REST API

This module is intended to be used by developers as a helper for using NovelAI's REST API.

Category Badges
Pypi PyPI PyPI - Python Version PyPI - License PyPI - Format
Quality checking Python package Python package linting: pylint security: bandit Code style: black
Stats GitHub top language Libraries.io dependency status for GitHub repo GitHub repo size Pypi package size GitHub issues GitHub pull requests
Activity GitHub last commit GitHub commits since tagged version GitHub commit activity

Retired versions: 3.7.2 Final commit of retired versions can be found with the tag py<version> (e.g. py3.7.2).

Usage

Download via pip:

pip install novelai-api

Using the module via Command Line

Get access key

Get the access key for your account. This key is used to login to the API through the /login endpoint.

python -m novelai_api get_access_key <username> <password>

Get access token

Login to the API and get the access token. This token is valid 30 days and is required to use most of the API. Take care to properly escape the arguments if they contain special characters.

python -m novelai_api get_access_token <username> <password>

Sanity check

Run a sanity check on your user content. It will print what content couldn't be decrypted. Take care to properly escape the arguments if they contain special characters.

python -m novelai_api sanity_check <username> <password>

Decode

Decode a b64 encoded tokenized text. This will print the tokens and the decoded text.

python -m novelai_api decode <model> <data>

Using the module in your code

A full list of examples is available in the example directory

The API works through the NovelAIAPI object. It is split in 2 groups: NovelAIAPI.low_level and NovelAIAPI.high_level

low_level

The low level interface is a strict implementation of the official API (https://api.novelai.net/docs). It only checks for input types via assert, and output schema if NovelAIAPI.low_level.is_schema_validation_enabled is True

high_level

The high level interface builds on the low level one for easier handling of complex settings. It handles many tasks from the frontend

Development

All relevant objects are in the novelai_api directory. The Poetry package is required (pip install poetry) as the venv manager.

Contributing

You can contribute features and enhancements through PR. Any PR should pass the tests and the pre-commits before submission. The pre-commit hook can be installed via

poetry run nai-pre-commit

Testing against the API

To run against the API, you can use poetry run nai-test-api.

API

Testing against the mocked API

To run against the mocked API, you can use poetry run nai-test-mock.

:warning: WIP, does not work yet :warning:

Mock

Docs

To build the docs, run

poetry run nai-build-docs

The docs will be locally viewable at docs/build/html/index.html

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_api-0.34.0.tar.gz (6.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

novelai_api-0.34.0-py3-none-any.whl (6.4 MB view details)

Uploaded Python 3

File details

Details for the file novelai_api-0.34.0.tar.gz.

File metadata

  • Download URL: novelai_api-0.34.0.tar.gz
  • Upload date:
  • Size: 6.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.1 Linux/6.11.0-1015-azure

File hashes

Hashes for novelai_api-0.34.0.tar.gz
Algorithm Hash digest
SHA256 77bf6896a86a34235376206dbeba157b81f29cb77f53c5345d988d4fe36bd9cb
MD5 8226bcc6792ac60aa2a320d54ebd3530
BLAKE2b-256 c871788abd41e3f1e8269f25531f2b04e919e303d4198c56f7ad6cb0db04d232

See more details on using hashes here.

File details

Details for the file novelai_api-0.34.0-py3-none-any.whl.

File metadata

  • Download URL: novelai_api-0.34.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.1 Linux/6.11.0-1015-azure

File hashes

Hashes for novelai_api-0.34.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a624eeaedfb2e104464e85a5ea7c33a342866a555f36fbe8e70b26482181d0f7
MD5 77b26f6e868b68407385cf174a722c0e
BLAKE2b-256 224b77cc9fc41bd4856b48f023dd5a70abd7c0aae968bca43cbe4cf716530cd9

See more details on using hashes here.

Supported by

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