Code Monkey home page Code Monkey logo

aiornot-python's Introduction

AIORNOT Logo

AIORNOT Python Client

Tests PyPI version Better Stack Badge

This is a Python client for the AIORNOT API.

Getting Started

Account Registration and API Key Generation

Register for an account at AIORNOT. After creating an account, you can generate an API key via your dashboard. If you just created your account, the page looks like,

Click the Request API Key button to generate a new API key. After generating a key, the page looks like,

Press the Copy API Key button to copy the key to your clipboard. If you already have generated an API key, the page looks like,

Press the Refresh API Key button to generate a new API key. Then press the Copy API Key button to copy the key to your clipboard.

Warning

Never share your API key with anyone. It is like a password.

Installing the Python Package

To install the python package, run the following command,

pip install aiornot

Using the client requires an API key. You can set the API key in two ways.

The easier and more flexible way is to set an environment variable,

AIORNOT_API_KEY=your_api_key

Otherwise, you can pass the api key in as an argument to the client,

from aiornot import Client, AsyncClient


client = Client(api_key='your_api_key')               # sync client
async_client = AsyncClient(api_key='your_api_key')    # async client

Failure to set either the environment variable or the api key argument will result in a runtime error.

View from 10,000 feet

from aiornot import Client

# Create a client (reads AIORNOT_API_KEY env)
client = Client()

# Classify an image by url
resp = client.image_report_by_url('https://thispersondoesnotexist.com')

# Classify an image by path
resp = client.image_report_by_file('path/to/image.jpg')

# Classify audio by url
resp = client.audio_report_by_url('https://www.youtube.com/watch?v=v4WiI4es_UI')

# Classify audio by path
resp = client.audio_report_by_file('path/to/audio.mp3')

# Check your token
resp = client.check_token()

# Refresh your token
resp = client.refresh_token()

# Revoke your token
resp = client.revoke_token()

# Check if the API is up
resp = client.is_live()

There is also an async client that has the same methods as the sync client, but as coroutines.

import asyncio
from aiornot import AsyncClient


async def main():
    client = AsyncClient()
    if await client.check_api():
        print('API is up!')
    else:
        print('API is down :(')


if __name__ == '__main__':
    asyncio.run(main())

CLI Usage

AIOrNot also comes with a CLI. You can use it easily via a pipx installation,

# For fresh install
pipx install aiornot

# For upgrade
pipx upgrade aiornot

The CLI also looks for the AIORNOT_API_KEY environment variable. But it will also look for a ~/.aiornot/config.json file if the environment variable is not set. To set it up, run the following command,

aiornot token config

and follow the prompts. Afterwards, you can see a menu of commands with,

aionot

the two most useful ones being,

# Classify an image by url or path
aiornot image [url|path]

# Classify audio by url or path
aionot audio [text]

aiornot-python's People

Contributors

jbnaion avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.