Metadata-Version: 2.1
Name: tremolo-session
Version: 1.0.11
Summary: A simple, file-based session middleware for Tremolo.
Author-email: nggit <contact@anggit.com>
License: MIT License
Project-URL: Homepage, https://github.com/nggit/tremolo-session
Project-URL: Source, https://github.com/nggit/tremolo-session
Project-URL: Funding, https://github.com/sponsors/nggit
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE

# tremolo-session
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=nggit_tremolo-session&metric=coverage)](https://sonarcloud.io/summary/new_code?id=nggit_tremolo-session)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=nggit_tremolo-session&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=nggit_tremolo-session)

A simple, file-based session middleware for [Tremolo](https://github.com/nggit/tremolo).

See also: [tremolo-login](https://github.com/nggit/tremolo-login).

## Usage
```python
#!/usr/bin/env python3

from tremolo import Application
from tremolo_session import Session

app = Application()

# this is a session middleware
# that enables you to use request.ctx.session
Session(app, expires=86400)


@app.route('/')
async def index(request, **server):
    session = request.ctx.session

    if session is None:
        return b'The session will be created after you reload this page.'

    if 'visits' in session:
        session['visits'] += 1
    else:
        session['visits'] = 0

    return b'You have visited this page %d times today.' % session['visits']


if __name__ == '__main__':
    app.run('0.0.0.0', 8000, debug=True, reload=True)
```

## Installing
```
python3 -m pip install --upgrade tremolo_session
```

## Testing
Just run `python3 -m tests`.

Or if you also want measurements with [coverage](https://coverage.readthedocs.io/):

```
coverage run -m tests
coverage combine
coverage report
coverage html # to generate html reports
```

## License
MIT License
