Skip to main content

Store Implementation for Users in MongoDB

Project description

MongoDB User Stores for Python

Frappy MongoDB Store Implementation for Users and UserTokens for Python

  1. Usage
  2. Methods


from frappymongouser import UserStore, UserTokenStore

MONGO_URL = "mongodb://localhost:27017"  # use your MongoDB url and add potential credentials

# this is how the stores are instantiated
user_store = UserStore(mongo_url=MONGO_URL, mongo_db="databaseName", collection_name="users")
token_store = UserTokenStore(mongo_url=MONGO_URL, mongo_db="databaseName", collection_name="userTokens")

# example usage: retrieve all documents
user_list = user_store.get_all() 
for user in user_list:
    # user is of type User and has attributes
    print(, user.permissions)


Base methods for both stores provided by pbu


  • create_local_user(username, password, permissions) - will create a new local user. The password will be MD5 encoded. The same encoding mechanism used for the login check.
  • login_with_password(username, password) - will attempt to perform a login with the provided credentials.
  • change_password(user_id, new_password) - update the users password using MD5 to encode the password.
  • update_permissions(user_id, permissions) - completely overwrites the permissions of a user with the provided.
  • update_profile(user_id, new_profile) - completely overwrites the profile of a user with the provided value
  • get_by_username(username) - fetches a user by it's username attribute.
  • initial_local_user_check(initial_username, initial_password, initial_permissions) - this function can be called when using local users only. It is already incorporated in the frappyflaskauth package when using local logins. It will check if there are any existing users. If there are no users in the system yet, this will create an initial user with the provided credentials and permissions that can be used as initial administrator account. If no permissions are provided, the user will receive the admin permission, which is also the default to manage users using the package frappyflaskauth (and/or @frappy/react-authentication
  • create_api_key(user_id) - the function will update a user's apiKey key in the database and return the new key. The key is something like this: e31d7880-e968-4195-96ac-4be8798f1915 and a str.
  • get_users_with_api_key() - retrieves a list of users that have an API key set (apiKey exists) - only used in context of admin functions
  • revoke_api_key(user_id) - removes an API key from a user leaving the user without an active API key.


  • create(user_id, token, lifetime) - simple, just creates a new token. The lifetime is provided as datetime.timedelta (and defaults to 30 days)
  • get_by_token(token) - searches for a specific token and returns a matching entry or None
  • clean_up_expired() - checking the expired flag on each token and deleting entries that exceed their lifetime
  • update_token(token_id) - just updates the last_update date of the token - deprecated, because rather useless

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

frappymongouser-1.5.1.tar.gz (5.0 kB view hashes)

Uploaded source

Built Distribution

frappymongouser-1.5.1-py3-none-any.whl (9.8 kB view hashes)

Uploaded py3

Supported by

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