by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Adam Hopkins
    @ahopkins
    This seems more like something for package maintainers, no?
    Primarily, how do you decide what plug-ins to display?
    Do you know of any other frameworks with something like this?
    Justin
    @Paladiamors

    The Python 2 -> 3 migration had a dashboard like that and developers had in the past chose the flavor of Python they would use based on the availability of the packages they needed.

    One of the reasons I got into sanic recently is indeed for the speed and the simplicity of the code. Sanic is indeed growing and I think having a way of showing what key modules are used and its stability would also be encouraging to enterprises that might be interested in using this stack. If enterprises start using it, I think the popularity of sanic could also grow.

    In terms of picking which plugins to display, I think that would be up to you as the maintainers or even have a separate team that would accept modules that are for sanic. Django has something like django packages: https://djangopackages.org/
    Adam Hopkins
    @ahopkins
    Ah true. I forgot about Django packages.
    Justin
    @Paladiamors
    Would there be a schedule to have an update to the 20.3.0 release logs by any chance? I'm not able to find the details just yet here: https://github.com/huge-success/sanic/blob/master/CHANGELOG.rst
    Adam Hopkins
    @ahopkins
    Yes. I apologize that it did not accompany the release. We have been thrown for a loop with this last release and are recollecting to do better for 20.6
    Justin
    @Paladiamors
    Not a problem, much appreciated for all the hard work that you guys are doing.
    Anh Mai
    @theanht1
    Hey guys, I have a question on Sanic app context
    Basically I'm working on a project that supports running on both Sanic and CLI, and I want to know whether a function is called on app context or not. It's kind of has_app_context in Flask,
    but I didn't find something similar in Sanic
    Thanks for taking a look
    Adam Hopkins
    @ahopkins
    Even though Sanic's routing and handler mechanism looks like Flask, Sanic does not try to achieve a parity of API design. I apologize, but I am not familiar with has_app_context. In what case do you use it?
    If your function called is the same as your handler, then you can access your app from request.app
    Marwan Rabbâa
    @waghanza
    /@all I have compare sanic and other python frameworks
    https://github.com/the-benchmarker/web-frameworks/tree/cloudify#results :tada:
    Ewan Higgs
    @ehiggs
    Neat; the backend for covid contact tracing in italy is using sanic: https://github.com/immuni-app/immuni-backend-common
    @waghanza did you test this on a mac laptop in docker? Or did you test this on actual infra?
    2 replies
    Adam Hopkins
    @ahopkins
    Results are run on Digital Ocean.
    3 replies
    I see now 🤦‍♂️ my bad
    Marwan Rabbâa
    @waghanza
    :-)
    Ahmed
    @ahmedhr

    debug sanic with pycharm when debug=False
    , if we want to keep debug=True we also have to explicitly mention auto_reload=False

    Microsoft/vscode-python#2316

    Is this a bug?

    Adam Hopkins
    @ahopkins
    nope
    that is intentional
    debug mode automatically enables auto reload on purpose
    if you only want the debug logging, and not reload, then you need to be explicit.
    Ahmed
    @ahmedhr
    Alright, makes sense. Thanks!
    Andrew Bastien
    @volundmush
    Sanic peoples! I am curious
    So I am looking at the 'Custom Protocols' thing and am wondering about just how far those can go. For instance, what about protocols that don't necessarily generate a response - such as Telnet? I am currently working on something MUD-related and want to use modern Python to give it web features so am looking at various ASGI technologies built on Asyncio for this purpose....
    it seems like every single ASGI-related tool and library assumes HTTP+WebSockets. which, I mean, that's a fairly sensible assumption to make I suppose, but...
    I'm imagining a server that opens up several ports, each serving different protocols - one is telnet, another is ssh, then a third is HTTP+WS...
    Adam Hopkins
    @ahopkins
    First, Sanic is not an ASGI server. You would need to use uvicorn, hypercorn, or daphne if you wanted ASGI. With that said, I am not familiar enough with the internals of any of those tools of they can be configured to handle any service other than http and websockets.
    Sanic is an ASGI framework. But, as such, it would exist only in the http and websockets world.
    Second, Sanic does ship with its own web server
    This is not based upon the ASGI event system.
    It is based directly upon asyncio.Protocol
    While I have never done either of those, if definitely should be possible
    Andrew Bastien
    @volundmush
    yeah I am starting to understand more about how this works after reading a bit more. ASGI was confusing me a bit but I see the difference between server and app now
    Adam Hopkins
    @ahopkins
    :+1: I am really interested to hear how this comes out. If you do come up with something, would you mind sharing in the community forums?
    I guess the main distinction worth pointing out is that Sanic is first and foremost a server and web framework.
    It also just so happens to allow for the "framework" to also be hooked into an ASGI server if you need
    rlundy82
    @rlundy82
    I'm new to async development. I'm coming from a Flask(ish) background, so I'm loving the way Sanic looks to me. I've got a question regarding Sanic-WTF.
    I've not been able to get it to work, I keep getting errors while following the examples. My question is if there's any updated docs or alternatives or... what's the best practices when dealing with form submission?
    rlundy82
    @rlundy82
    I just spotted in the forums that it's a dead package. =/
    Here is a list of some Sanic packages.
    Obviously not everything is there.
    There's also a discussion where I think that package did come up. https://community.sanicframework.org/t/move-essential-sanic-libraries-under-sanic-organisation/567
    rlundy82
    @rlundy82

    I'm having an issue with request.ctx and middleware.

    @app.middleware('request')
    async def _prepare(request):
        request.ctx.test = '1234'
    
    @app.middleware('response')
    async def _cleanup(request, response):
        test = request.ctx.test
        #test = getattr(request.ctx, 'test')

    I'm getting this error
    AttributeError: 'types.SimpleNamespace' object has no attribute 'test'

    I guess my question is if this is the same ctx as in _prepare, or if I have to do anything extra to get _cleanup the same info

    rlundy82
    @rlundy82
    I'm getting request.ctx.test just fine in the handler
    rlundy82
    @rlundy82

    I've made this small example to help recreate the issue.

    from sanic import Sanic
    from sanic.response import HTTPResponse
    
    app = Sanic("middleware_test")
    
    @app.middleware("request")
    async def _prepare(request):
        request.ctx.test = 'ASDF'
    
    @app.middleware("response")
    async def _cleanup(request, response):
        test = request.ctx.test
    
    @app.route("/")
    async def test(request):
        test = request.ctx.test
        return HTTPResponse("Got Test: %s" % test, content_type='text/html')
    
    if __name__ == "__main__":
        app.run(host="0.0.0.0", port=8888)

    If you run the code, you'll notice the handler renders the response just fine, but if you look at the console output you'll notice the traceback:

    [2020-07-04 21:45:19 +0000] [21208] [ERROR] Exception occurred in one of response middleware handlers
    Traceback (most recent call last):
      File "<path>/env/lib/python3.6/site-packages/sanic/app.py", line 977, in handle_request
        request, response, request_name=name
      File "<path>/env/lib/python3.6/site-packages/sanic/app.py", line 1281, in _run_response_middleware
        _response = await _response
      File "mwtest.py", line 12, in _cleanup
        test = request.ctx.test
    AttributeError: 'types.SimpleNamespace' object has no attribute 'test'
    Justin
    @Paladiamors

    Got a quick question about csrf tokens for sanic. With the 20.3 release, looks like sanic-wtf no longer works and there is a pull request that hasn't been merged. pyx/sanic-wtf#17

    The developer doesn't seem to be active anymore, are there any alternatives to this library?