An actively maintained wrapper for the somerandomapi API.
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"
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.
Visit the full documentation at: https://somerandomapipy.readthedocs.io
For any questions, suggestions, or issues, feel free to reach out to me on Discord (@Soheab_).
This project is licensed under the MPL2-0 License. See the LICENSE file for details.