You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
aiohttp is faster than httpx, but is more cumbersome to use, and i dont think the difference is that significant.
if we are zo use httpx, it would be worth considering stopping using requests for the sync side of things.
Also, since async with httpx would require an AsyncClient to be used anyway, it might be worth partially restructuring the library to use requests.Session/httpx.Client objects instead of storing headers and cookies seperately. There could be a Session/Client object as an attribute of ever session object, e.g. with the name rq. so it'd become self.rq.get(url),or self._sess.rq.get(url). the only problem is data validation.
synchronicity is less mainstream and requires .aio. it adds these dynamically though so you need typing stubs. even so, it doesnt really give you a great API surface. msoft's playwright-python uses greenlet and has a pretty nice api so i was suggesting we go with that. however it appears that playwright also has some kind of codegen process? It still has a much nicer API surface than synchronicity though and greenlet seems more well-supported. idk
tcc mentioned using uplink. this seems fascinating. how viable is this?
I am coming to the opinion again that manually maintaining both synchronous and asynchronous code may be the best choice.
It does not require unorthodox tooling
so it is easier to learn the codebase as a newbie
so it is easier to maintain even after we leave
so we dont have to maintain internal tools
It does not use magic - we would not have any magic constants or functions or a preprocessor
this makes it easier to understand the codebase (if there is magic, it is much harder to learn)
new contributors/maintainers can come and go without as much danger to the project
it is vanilla python code, so anyone can understand it by reading it. they do not need to know about our specific strange build process and internal code generation tool
however as with all choices here, there are downsides, the main one here being the need to write everything twice
so individual features take longer to be made
or extra abstractions have to be added
however this can be somewhat mitigated by having a separate component for the internal logic of handling the data itself (e.g. return User(data["username"], id=data["user-id"], some_other_field=data["foobar"])), but making synchronous and asynchronous wrappers around them.
this means that there is a need to understand how the codebase is structured
however this is already part of the contributor documentation so we can just amend that
we would then try our best to keep the sync, async, and core toplevel submodules tightly organized, having, if possible the exact same directory hierarchy/structure.
this will make implementing 1 feature meaning having to add core code, as well as sync/async wrappers, and also tests for the async/sync wrappers. However, in fact, if we make unit tests on the core submodule, we could easily create the "mock tests" that i described in improve test suite #703 without even having to monkeypatch anything.
This would mean that we would need a good upgrade to our contributor documentation.
The reason i emphasize easiness to understand is because in my opinion, scratchattach should serve as a good transition point to go from a basic python user to an actually decent python user. For a project with the target demographic of scratch users aiming to do something cool with scratch (only using python as a means to that end), i think this is the right approach
In terms of async, i think either we should: a. do it manually (it hurts but at the same time so does everything) OR b. redirect users to scapi by kakeruzoku
another option is to put async on extremely low priority, redirect users to scapi, refactor the codebase so it is satisfactory in the other regards, and then, and only then, do the core/async refactor. Since this is an open source project, we are not constrained by deadlines, so this approach is possible. However, progress is not guaranteed (this is essentially the path we are taking right now)
Activity
TheCommCraft commentedon Jun 18, 2025
aspizu commentedon Jun 18, 2025
use httpx it has an async client
faretek1 commentedon Jun 23, 2025
should/would this be done as a separate submodule, a seperate repository,or a seperate branch? or something else?
faretek1 commentedon Jun 23, 2025
and then upload to pypi as sa-async or something?
TheCommCraft commentedon Jun 23, 2025
I'd say a submodule just for async event handlers and also async versions of site classes in the same files as the blocking ones
TheCommCraft commentedon Jun 23, 2025
If anything, I would have be an extra like
pip install scratchattach[async]TheCommCraft commentedon Jun 24, 2025
I could create a milestone for this and you could create a pull request if you wanr
faretek1 commentedon Jul 1, 2025
aiohttp is faster than httpx, but is more cumbersome to use, and i dont think the difference is that significant.
if we are zo use httpx, it would be worth considering stopping using requests for the sync side of things.
Also, since async with httpx would require an AsyncClient to be used anyway, it might be worth partially restructuring the library to use requests.Session/httpx.Client objects instead of storing headers and cookies seperately. There could be a Session/Client object as an attribute of ever session object, e.g. with the name rq. so it'd become self.rq.get(url),or self._sess.rq.get(url). the only problem is data validation.
faretek1 commentedon Jul 1, 2025
n.b. scapi uses aiohttp
TheCommCraft commentedon Jul 1, 2025
maybe we could create an internal api for creating api calls like with uplink but for async and sync simultaneously
faretek1 commentedon Dec 20, 2025
https://pypi.org/project/synchronicity
https://pypi.org/project/greenlet
faretek1 commentedon May 4, 2026
greenlet is hard
synchronicity is less mainstream and requires
.aio. it adds these dynamically though so you need typing stubs. even so, it doesnt really give you a great API surface. msoft's playwright-python uses greenlet and has a pretty nice api so i was suggesting we go with that. however it appears that playwright also has some kind of codegen process? It still has a much nicer API surface than synchronicity though and greenlet seems more well-supported. idktcc mentioned using uplink. this seems fascinating. how viable is this?
faretek1 commentedon Jul 27, 2026
I am coming to the opinion again that manually maintaining both synchronous and asynchronous code may be the best choice.
however as with all choices here, there are downsides, the main one here being the need to write everything twice
however this can be somewhat mitigated by having a separate component for the internal logic of handling the data itself (e.g.
return User(data["username"], id=data["user-id"], some_other_field=data["foobar"])), but making synchronous and asynchronous wrappers around them.sync,async, andcoretoplevel submodules tightly organized, having, if possible the exact same directory hierarchy/structure.coresubmodule, we could easily create the "mock tests" that i described in improve test suite #703 without even having to monkeypatch anything.The reason i emphasize easiness to understand is because in my opinion, scratchattach should serve as a good transition point to go from a basic python user to an actually decent python user. For a project with the target demographic of scratch users aiming to do something cool with scratch (only using python as a means to that end), i think this is the right approach
In terms of async, i think either we should: a. do it manually (it hurts but at the same time so does everything) OR b. redirect users to
scapiby kakeruzokuanother option is to put async on extremely low priority, redirect users to scapi, refactor the codebase so it is satisfactory in the other regards, and then, and only then, do the core/async refactor. Since this is an open source project, we are not constrained by deadlines, so this approach is possible. However, progress is not guaranteed (this is essentially the path we are taking right now)