Skip to main content

Dash-Access-Manager

Python package GitHub

Dash-Access-Manager provides user access management for Dash.

It is based on Flask-Login to manage user session and on MongoEngine to use MongoDB databases.

Table of contents

Description

This is an implementation of an access management to be used in a dash app. It provides login, logout and sign up buttons that can be integrated in a layout of a dash app.

Installation

Install the extension with pip:

pip install dash-access-manager

Usage

Once installed, import the package in your app.py.

import dash-access-manager as dam

app = dash.Dash(__name__)

server = app.server

Then, you have to set up the access manager. You need to change your_secret_key_here as it not secret. To do so, you can generate a secret key with the os module by using os.urandom(12)

#Define a secret key that is required for Flask-Login to manage user session
server.secret_key = 'your_secret_key_here' 

# Suppress errors for callbacks acting on layouts that are not displayed yet
app.config.suppress_callback_exceptions = True

# Initialize the acess manager
dam.init_access_manager(app)

After this you will define the layouts and callbacks of your dash app. Here is an simple example that can be used as it is.

app.layout = html.Div(children=[dcc.Location(id='url', refresh=False),
                            html.Div(id='root'),
                            html.Div(id='container')
                            ])


def render_default_page(navbar_button=[], page_content=[html.H3("Login successfull")]):
    return [
               dbc.Navbar([
                              dbc.NavbarBrand("Navbar"),
                          ] + navbar_button,
                          color="primary")
           ] + page_content


@app.callback(Output('root', 'children'),
              [Input('url', 'pathname')])
def display_page(pathname):
    if dam.current_user.is_authenticated:
        return render_default_page(dam.render_logout_button(), dam.render_logged_page())
    else:
        return render_default_page(dam.render_navbar_login() + dam.render_navbar_sign_up(), dam.render_login_page())

Finally, you need to connect the app with your MongoDB database before running your app. You have to change DatabaseName and DatabaseURL with the ones you want to use. If you want to use MongoDB you need to this change the host parameter at mongodb+srv://username.password@cluster.url where you have to replace username, password and cluster.url by your information.

if __name__ == "__main__":
    dam.connect(
        db='DatabaseName',
        host='DatabaseURL'
    )
    app.run_server()

You can use this file app.py to try it out.

Contributing

This project is under development so contributions are welcome to improve the code. Have a look at CONTRIBUTING.

Changelog

Take a look at CHANGELOG for more details.

License

Distributed under the MIT License. See LICENSE for more information.

Release files for dash-access-manager 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dash-access-manager 0.1.3
File Size Uploaded
dash_access_manager-0.1.3.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dash-access-manager 0.1.3
File Interpreter ABI Platform
dash_access_manager-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / dash_access_manager-0.1.3.tar.gz

Download URL dash_access_manager-0.1.3.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
10d9e759a800ad859ad3bf808907c32ab62931d3a5f294140c8f29f29c0384e3
BLAKE2b-256 checksum
How to use checksums
b86abf3fffe920f0898e8d7e466b3e0f74937e574f66b253ceae5ef0961c7851
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / dash_access_manager-0.1.3-py3-none-any.whl

Download URL dash_access_manager-0.1.3-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6be36929e9aae263ada9ccefc11b841f5738afa86f079a23714b2df6b1a4e65
BLAKE2b-256 checksum
How to use checksums
3aa8efe23cc3b37b7279f6b224e2b4447f10f7c213dc292be67d94b33a71076d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page