by

## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• Mar 14 19:42
florimondmanca closed #334
• Mar 14 19:41
florimondmanca commented #334
• Mar 14 19:39

florimondmanca on pip

• Mar 14 19:39
dependabot-preview[bot] commented #342
• Mar 14 19:39
florimondmanca closed #342
• Mar 14 02:00

dependabot[bot] on npm_and_yarn

• Mar 14 02:00
dependabot[bot] commented #343
• Mar 14 02:00
florimondmanca closed #343
• Mar 13 23:34
codecov-io commented #343
• Mar 13 23:33
codecov-io commented #343
• Mar 13 23:32
codecov-io commented #343
• Mar 13 23:29
dependabot[bot] labeled #343
• Mar 13 23:29
dependabot[bot] opened #343
• Mar 13 23:29

dependabot[bot] on npm_and_yarn

Bump acorn from 6.1.1 to 6.4.1 … (compare)

• Mar 09 05:28
codecov-io commented #342
• Mar 09 05:28
florimondmanca commented #342
• Mar 09 05:27
codecov-io commented #342
• Mar 09 05:26
codecov-io commented #342
• Mar 09 05:23
dependabot-preview[bot] labeled #342
• Mar 09 05:23
dependabot-preview[bot] opened #342
Luca Lacerda
@lucawen
Hiii!!
I can create files/folders organization and import in main .py file ?
or anything need to be in the same file ?
Florimond Manca
@florimondmanca
Hi @lucawen, route registration is indeed Flask-style, so you can register routes anywhere you have access to an app. You can use recipes to separate an app into multiple sub-apps. We also have #234 open for module-based route registration. If that doesn't fit your use case feel free to open a feature request :)
Alfred Chiesa
@alfredchiesa
anyone have examples (or boilerplates) that show a more complete suggested large project structure? There is likely something, but I am having a hard time finding it.
Florimond Manca
@florimondmanca
Hey Alfred, I’m not sure how big of a structure you’re looking for. An example real-life application is TermPair, made by @cs01: https://github.com/cs01/termpair Not sure it qualifies as « large », though. If you think there should be some hints in the docs about this, feel free to open an issue!
By the way everyone, I’ll be on vacation for the next 7 days so might not be able to respond right away. Feel free to help each other out as you can. :-)
Zuhair
Hi!
How can I clone and built/customize bocadillo locally on my own computer
So that I can contribute
Zuhair
a problem is that, I have installed python3.6 on my laptop, how to replace it with 3.7?? in ubunut
ubuntu*
Florimond Manca
@florimondmanca
As for your question about Python, I’m not an Ubuntu user but I guess you should be able to find an answer by a bit of googling 👍
Zuhair
@florimondmanca Thanks bro
EricE
@EricE
Thanks for the updated documentation on async. In https://bocadilloproject.github.io/guides/async.html#converting-a-regular-function-to-an-asynchronous-function, if compute is slow, the I assume you would wrap it in run_in_threadpool since wrapping it in an async function doesn't protect you?
Florimond Manca
@florimondmanca
Absolutely @EricE, something like:
async def compute_async(*args, **kwargs):
return await run_in_threadpool(compute, *args, **kwargs)
Florimond Manca
@florimondmanca
I pushed an update to that section with an additional tip on using partial :)
@alfredchiesa Coming back to your question on larger project structures last time, you may want to check out the new Bocadillo CLI and fiddle around with the create command, it should give you an example of a full-featured project file structure: https://github.com/bocadilloproject/bocadillo-cli
We’re still working towards being able to easily split an app into multiple files :)
^For example via #261
EricE
@EricE
Thanks for the update! For truly CPU bound applications, wouldn't you want to use ProcessPoolExecutor instead of ThreadPoolExecutor (unfortunately not in starlette)? Seems like you would slow down your asyncio app using the ThreadPoolExecutor but have minimal impact with ProcessPoolExecutor. I know it can be more limiting to work with Processes over Threads (pickling) but for maximum speed using ThreadPoolExecutor seems better.
Florimond Manca
@florimondmanca
Yes, I’ve heard that deferring highly CPU-bound operations to a process is more effective in Python. @EricE Maybe you should open a PR to Starlette to add run_in_processpool()? ;)
EricE
@EricE
If I only knew how to use Github :) I just downloaded their desktop app, I'll see if I can figure it out. The hardware guys at my company still use SVN for our FPGA files, etc., and I use it for my Python projects. Our SW guys are switching to Git and it is clearly the winner so time to switch...
Florimond Manca
@florimondmanca
Ah right, you’re into hardware! This website helped me a lot when starting with git two years ago :) http://rogerdudler.github.io/git-guide/
Ilyes Bouchlaghem
@Ibouch
Hi ! I am reading about ASGI servers more precisely on Uvicorn and a framework using it (Starlette.io). It turns out that in their section 'Third Party Packages' they quote you with another framework (FastAPI), so Bocadillo is a framework of another framework? Would not this add unnecessary overlays rather than contribute directly to the Starlette.io project?
Anyway good job, there are features that look cool
Florimond Manca
@florimondmanca

Hi Ilyes! Thanks for pitching in, this is an interesting question!

Actually, Bocadillo uses Starlette as an ASGI toolkit, not as a framework. For example, we reuse Starlette’s HTTP request representation (the Request class), as well as various ASGI middleware classes (eg the CORS middleware) and some other features (eg background tasks). But Bocadillo has a different design for views, and other features completely separate from Starlette (eg dependency injection). This hasn’t happened yet, but I’d be very much keen to bring generic enough features back into Starlette (in fact, I am personally a contributor to Starlette and uvicorn). :)

OTOH, it is true that FastAPI can be seen as a framework of a framework. For example, its app class is a direct subclass of ‘Starlette’ class. I think tiangolo is involved in both Starlette and uvicorn as well though.

Ilyes Bouchlaghem
@Ibouch
Ok thank you for the precision, in the description of your project, would you know what 'asynchronous salsa means?
Florimond Manca
@florimondmanca
Bocadillo means sandwich in Spanish, and salsa means sauce, so it’s just a pun for the fact that Bocadillo is an async framework :)
Ilyes Bouchlaghem
@Ibouch
hm ok, because I had found on the internet "Salsa: A Framework for Scalable Asynchronous Replica Exchange"
but it did not make sense
Florimond Manca
@florimondmanca
Oh, right. Yeah, Bocadillo has nothing to do with this paper. 😅 I can see that’s what I get as a second result when googling for “asynchronous salsa” as well.
Ilyes Bouchlaghem
@Ibouch
I chose to use starlette.io, but I may reconsider my choice if I realize that bocadillo saves me development time and does not affect performance. This is for a web application of a large community and the current version under Flask (and Flask-SocketIO for websocket), does not support the load.
If I use bocadillo, I will mention to my community (video games so also some devs) to increase the visibility of your project!
Florimond Manca
@florimondmanca
Sounds good! Good luck with your project 👍
Ilyes Bouchlaghem
@Ibouch
Thank you :)
EricE
@EricE
I'm wondering is something is off with the demo file structure? I ran bocadillo create demo and got
+---demo
¦   +---demo
¦   ¦   +---app.py
¦   ¦   +---asgi.py
¦   ¦   +---providerconf.py
¦   ¦   +---settings.py
¦   ¦   +---__init__.py
¦   +---templates
(I added templates). From the tutorial it seems like templates should be in the same subdirectory as app.py but jinja2 throws an error if it is
I run uvicorn demo.asgi:app --reload in the first demo subdirectory
EricE
@EricE
If I run uvicorn asgi:app --reload in the second demo subdirectory, it errors:
(D:\SVNRepo\projects-sw\async_web\trunk\env) D:\SVNRepo\projects-sw\async_web\tr
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
Process SpawnProcess-1:
Traceback (most recent call last):
File "d:\svnrepo\projects-sw\async_web\trunk\env\lib\multiprocessing\process.p
y", line 297, in _bootstrap
self.run()
File "d:\svnrepo\projects-sw\async_web\trunk\env\lib\multiprocessing\process.p
y", line 99, in run
self._target(*self._args, **self._kwargs)
File "d:\svnrepo\projects-sw\async_web\trunk\env\lib\site-packages\uvicorn\mai
n.py", line 305, in run
loop.run_until_complete(self.serve(sockets=sockets))
File "d:\svnrepo\projects-sw\async_web\trunk\env\lib\asyncio\base_events.py",
line 584, in run_until_complete
return future.result()
File "d:\svnrepo\projects-sw\async_web\trunk\env\lib\site-packages\uvicorn\mai
n.py", line 312, in serve
File "d:\svnrepo\projects-sw\async_web\trunk\env\lib\site-packages\uvicorn\con
File "d:\svnrepo\projects-sw\async_web\trunk\env\lib\site-packages\uvicorn\imp
orter.py", line 23, in import_from_string
raise exc from None
File "d:\svnrepo\projects-sw\async_web\trunk\env\lib\site-packages\uvicorn\imp
orter.py", line 20, in import_from_string
module = importlib.import_module(module_str)
File "d:\svnrepo\projects-sw\async_web\trunk\env\lib\importlib\__init__.py", l
ine 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File ".\asgi.py", line 3, in <module>
from .app import app
ImportError: attempted relative import with no known parent package
INFO: Stopping reloader process [18712]`
Florimond Manca
@florimondmanca

From the tutorial it seems like templates should be in the same subdirectory as app.py but jinja2 throws an error if it is

The docs say that it should be placed in the same directory relative to where the app is run (ie using uvicorn), so that means the location you put it at should work. Doesn’t it?

If I run uvicorn asgi:app --reload in the second demo subdirectory, it errors:

Yes, that is expected, because the generated demo package uses relative imports, which you can’t use in Python unless you’re running from outside of that package. We should probably add a warning/caveat in the docs

EricE
@EricE
It did work when I put the templates directory as I showed in the directory tree listing above. However, in the templates guide it looks different: