Skip to content

Soheab/somerandomapi.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

106 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to somerandomapi.py!

An actively maintained wrapper for the somerandomapi API.

Installation

Install the stable version from PyPI using pip:

python -m pip install somerandomapi

Or the latest dev version from GitHub using pip and git:

python -m pip install "somerandomapi.py @ git+https://github.com/Soheab/somerandomapi.py"

Basic Examples

Get a random joke

import asyncio

import somerandomapi

sra_api = somerandomapi.Client("<optional api token>")

async def main():
   joke = await sra_api.joke()
   print(joke)
   await sra_api.close()

asyncio.run(main())

Use the chatbot feature:

import asyncio

import somerandomapi


async def main():
   async with somerandomapi.Client("<optional api token>") as sra_api:
      stopped: bool = False
      while not stopped:
            # can also do await sra-api.chatbot("message") to get a response immediately
            # but this is more efficient for long conversations
            async with sra_api.chatbot() as chatbot:
               user_input = input("You: ")
               if user_input.lower() == "stop":
                  stopped = True
                  print("Stopping the chatbot.")
                  break

               # can also do await chatbot.send("message") to get a response
               async with chatbot.send(user_input) as response:
                  if response is None:
                        print("No response received.")
                        continue
                  print(f"Bot: {response.response}")


asyncio.run(main())

See more examples in the examples directory on GitHub.

Documentation

Visit the full documentation at: https://somerandomapipy.readthedocs.io

Contact

For any questions, suggestions, or issues, feel free to reach out to me on Discord (@Soheab_).

License

This project is licensed under the MPL2-0 License. See the LICENSE file for details.

About

A maintained Python wrapper for the Somerandomapi API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages