Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Provides server-backed sessions for Sanic using Redis, Memcache and more.

License

NotificationsYou must be signed in to change notification settings

ahopkins/sanic-session

Repository files navigation

ReadTheDocsLicense: MITPyPI version

sanic-session is session management extension forSanic that integrates server-backed sessions with most convenient API.

sanic-session provides a number ofsession interfaces for you to store a client's session data. The interfaces available right now are:

  • Redis (supports both driversaioredis andasyncio_redis)
  • Memcache (viaaiomcache)
  • Mongodb (viasanic_motor andpymongo)
  • In-Memory (suitable for testing and development environments)

Installation

Install withpip (there is other options for different drivers, check documentation):

pip install sanic_session

Documentation

Documentation is available atsanic-session.readthedocs.io.

Also, make sure you readOWASP's Session Management Cheat Sheet for some really useful info on session management.

Example

A simple example uses the in-memory session interface.

fromsanicimportSanicfromsanic.responseimporttextfromsanic_sessionimportSession,InMemorySessionInterfaceapp=Sanic(name="ExampleApp")session=Session(app,interface=InMemorySessionInterface())@app.route("/")asyncdefindex(request):# interact with the session like a normal dictifnotrequest.ctx.session.get('foo'):request.ctx.session['foo']=0request.ctx.session['foo']+=1returntext(str(request.ctx.session["foo"]))if__name__=="__main__":app.run(host="0.0.0.0",port=8000)

Examples of using redis and memcache backed sessions can be found in the documentation, underUsing the Interfaces.

— ⭐️ —

About

Provides server-backed sessions for Sanic using Redis, Memcache and more.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

[8]ページ先頭

©2009-2025 Movatter.jp