Skip to main content

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

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dash_access_manager-0.1.3.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dash_access_manager-0.1.3-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file dash_access_manager-0.1.3.tar.gz.

File metadata

  • Download URL: dash_access_manager-0.1.3.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for dash_access_manager-0.1.3.tar.gz
Algorithm Hash digest
SHA256 10d9e759a800ad859ad3bf808907c32ab62931d3a5f294140c8f29f29c0384e3
MD5 1235143c708826ed9e970c6722963b51
BLAKE2b-256 b86abf3fffe920f0898e8d7e466b3e0f74937e574f66b253ceae5ef0961c7851

See more details on using hashes here.

File details

Details for the file dash_access_manager-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: dash_access_manager-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for dash_access_manager-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e6be36929e9aae263ada9ccefc11b841f5738afa86f079a23714b2df6b1a4e65
MD5 5989b7f92a9ed66d3ce0fb9b96aa9904
BLAKE2b-256 3aa8efe23cc3b37b7279f6b224e2b4447f10f7c213dc292be67d94b33a71076d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page