Skip to main content

MongoDB User Stores for Python

Frappy MongoDB Store Implementation for Users and UserTokens for Python

  1. Usage
  2. Methods

Usage

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.email, user.permissions)

Methods

Base methods for both stores provided by pbu

UserStore

  • 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.

UserTokenStore

  • 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

Release files for frappymongouser 1.5.1

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

Source distribution (sdist)

Source distribution for frappymongouser 1.5.1
File Size Uploaded
frappymongouser-1.5.1.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for frappymongouser 1.5.1
File Interpreter ABI Platform
frappymongouser-1.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / frappymongouser-1.5.1.tar.gz

Download URL frappymongouser-1.5.1.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e6d9a7348a1a24e101b74cd8487245c9bdf58ecaa9f7f88b6ff9a15d8d557c5f
BLAKE2b-256 checksum
How to use checksums
dc7f83570c1bc6a8912d2cd19e012218be5ae960f166cb4e69fe10cf6d1e8d51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.12

Release files / frappymongouser-1.5.1-py3-none-any.whl

Download URL frappymongouser-1.5.1-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cec511407d768ec9523fd5d23d5f988232ea292055079ca4ecb4d861e040c0fb
BLAKE2b-256 checksum
How to use checksums
8fc833159dd34fdbbd0b3ac54ceffe597c70e60fdf3f1d7f33a2a18165b42ac4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.12

Release history Release notifications | RSS feed

This release

1.5.1 This release

2 release files

1.5.0

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