Skip to main content

Free Alternative For The Cleverbot API

Project description

Python 3.8 GPLv3 license PyPI version Downloads Language grade: Python Quality Gate Status Security Rating

cleverbotfree

Cleverbot.com used to have a free API for their chatbot application. They have
removed their free API in place of a tiered subscription API service.
cleverbotfree is a free alternative to that API that uses a headless Firefox
browser to communicate with their chatbot application. You can use this module
to create applications/bots that send and receive messages to the Cleverbot
chatbot application.

Installation

Requirments

  • node >= 14.16.1
  • Python >= 3.8.0
  • python3-pip >= 21.1.1

Once requirments are met, you can install this library through pip.

pip install cleverbotfree

Drivers

This library uses the Playwright library to interface the Cleverbot website
with a headless Firefox browser.
To download the Playwright Firefox browser binary simply run this command after
installing cleverbotfree:

playwright install firefox

Usage

Examples

Example of a simple CLI script that creates a single use, one message chat session.

import asyncio
import cleverbotfree

def chat():
    """Example code using cleverbotfree sync api."""
    with cleverbotfree.sync_playwright() as p_w:
        c_b = cleverbotfree.Cleverbot(p_w)
        user_input = input("User: ")
        response = c_b.single_exchange(user_input)
        print("Cleverbot:", response)
        c_b.browser.close()

chat()

async def aysnc_chat():
    """Example code using cleverbotfree async api."""
    async with cleverbotfree.async_playwright() as p_w:
        c_b = await cleverbotfree.CleverbotAsync(p_w)
        user_input = input("User: ")
        response = await c_b.single_exchange(user_input)
        print("Cleverbot:", response)
        await c_b.browser.close()

asyncio.run(async_chat())

Example of a simple CLI script that creates a persistent chat session untill closed.

import asyncio
import cleverbotfree

def chat():
    with cleverbotfree.sync_playwright() as p_w:
        c_b = cleverbotfree.Cleverbot(p_w)
        while True:
            user_input = input("User: ")
            if user_input == 'quit':
                break
            c_b.send_input(user_input)
            bot = c_b.get_response()
            print('Cleverbot:', bot)
        c_b.browser.close()

chat()

async def async_chat():
    """Example code using cleverbotfree async api."""
    async with cleverbotfree.async_playwright() as p_w:
        c_b = await cleverbotfree.CleverbotAsync(p_w)
        while True:
            user_input = input("User: ")
            if user_input == 'quit':
                break
            await c_b.send_input(user_input)
            bot = await c_b.get_response()
            print('Cleverbot:', bot)
        await c_b.browser.close()

asyncio.run(async_chat())

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

cleverbotfree-2.1.1.tar.gz (16.5 kB view hashes)

Uploaded Source

Built Distribution

cleverbotfree-2.1.1-py3-none-any.whl (16.7 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