#๐Ÿ”’ How can I optimise my api wrapper library for use with discord.py?

51 messages ยท Page 1 of 1 (latest)

merry cypressBOT
#

@urban hollow

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

urban hollow
silk kestrel
#

optimise it by making it asynchronous

#

this library is an asynchronous way to make requests

#

sleep's should be replaced with asyncio.sleep

urban hollow
#

there is one sleep in _BaseApiClient iirc

#

so just replace that one?

silk kestrel
#

asynchronous code just lets your computer switch between what code its running

silk kestrel
urban hollow
#

so the whole simplicity would kinda go away

#

it would no longer be a super simple as possible library

silk kestrel
#

whats going to happen is that if you ever hit a ratelimit your bot will become completely unresponsive for retry-after seconds

#

every single command, everything

urban hollow
#

i do plan on adding a leaky bucket algo so that never happens

urban hollow
#

but if im rate limited by the riot api surely ill have to wait for the timer anyway

silk kestrel
#

just have it be asynchronous

#

the point of asynchronous code is that

#

you can run other code while waiting

#

for example, one command invocation might be waiting for the riot api call

urban hollow
#

ohhh u mean the whole bot will hang and wait

silk kestrel
#

but all the others don't care about that right

#

they can keep running

urban hollow
#

right right

silk kestrel
#

that's what asynchronous programming is for

urban hollow
#

cool

silk kestrel
#

and its really useful in network IO

#

because networking consists of lots of waiting

#

you are waiting for the response to your request

#

so why not run other code during that time

urban hollow
#

ok so should i make it async only

#

or

#

aync and synchronous

silk kestrel
#

you could try both but it could increase the complexity

urban hollow
#

yeah i really want it to stay simple as possible

#

hard choice, i dont know if i should do one or both

silk kestrel
#

if it's intended for discord bots you def want async

urban hollow
#

i might make it just async only then

silk kestrel
#

generally it'll be useful that way for most applications

#

and its not like you wouldn't be able to use it standalone

#

for example if you just wanted a program that makes one call you could chuck it in an async function and asyncio.run it

urban hollow
#

i guess im just thinking how many users does that exclude

silk kestrel
#

shouldn't really exclude any users

urban hollow
#

just the newer devs that dont know how to do that i guess

silk kestrel
#

that can be your quickstart example

urban hollow
#

i also badly need docs

silk kestrel
urban hollow
#

ive used aiohttp a bit but yeah i defo will look into it

merry cypressBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.