Skip to main content

User Bank

A Pythonic wrapper for Google Sheets based user management using the official Google API client.

Features

  • Secure Authentication: Check credentials (username/email and password) without listing or exposing other user records.
  • Least Privilege Access: Operates entirely over read-only Google Sheets scopes (spreadsheets.readonly), guaranteeing that the client cannot write to, modify, or corrupt the user spreadsheet.
  • Zero OAuth Popups: Uses a Google Service Account — fully automated, ideal for headless/CI/CD usage.
  • CLI Setup Wizard: One command (userbank) to configure credentials and connect.
  • Environment-First Auth: Pulls credentials from GOOGLE_APPLICATION_CREDENTIALS or USER_BANK_CREDENTIALS_JSON environment variables (or .env file).

Quick Start

pip install .

# Run the setup wizard
userbank

The wizard will:

  1. Ask for your Google Service Account JSON key (path or paste)
  2. Ask for your Google Sheet URL (it saves it to config.yml)
  3. Write GOOGLE_APPLICATION_CREDENTIALS=keys.json to .env
  4. Test the connection

Then use it:

from userbank import UserBank

bank = UserBank.from_config()
is_authenticated = bank.authenticate("jdoe", "securepass123", "MyApp")

Manual Setup

1. Google Service Account

  1. Go to Google Cloud Console.
  2. Create a project (or select an existing one).
  3. Create a Service Account → Keys → Add Key → Create New Key (JSON).
  4. Save the downloaded file as keys.json in your project root.

2. Enable Google Sheets API

Visit the URL below and click Enable:

https://console.cloud.google.com/apis/api/sheets.googleapis.com/

(The API must be enabled for the project your service account belongs to.)

3. Spreadsheet

  1. Create a new Google Sheet.
  2. Share it with the service account email (found in keys.json).
  3. Copy the sheet URL into config.yml:
    USER_BANK_URL: https://docs.google.com/spreadsheets/d/YOUR_ID/edit
    

3. Authentication

Credentials are resolved in this order:

# Source Example
1 credentials_path argument UserBank(..., credentials_path="keys.json")
2 credentials_info argument UserBank(..., credentials_info={...})
3 GOOGLE_APPLICATION_CREDENTIALS env var path to JSON key file
4 USER_BANK_CREDENTIALS_JSON env var inline JSON string
5 .env file loaded automatically, then checks #3–#4

The simplest approach: put GOOGLE_APPLICATION_CREDENTIALS=keys.json in your .env and it just works. With the configured environment/config file, the class can be instantiated with no arguments:

from userbank import UserBank

bank = UserBank()  # Implicitly resolves spreadsheet ID and credentials

Usage

from userbank import UserBank

bank = UserBank()

# Authenticate a user by username or email
is_authenticated = bank.authenticate(
    username_or_email="jdoe", # or "john.doe@example.com"
    password="securepassword123",
    application="MyApp"
)

if is_authenticated:
    print("User authenticated successfully!")
else:
    print("Invalid credentials or inactive user.")

Spreadsheet Fields

The first row of the Google Sheet must contain these headers:

Field Description
Application App name
Email User's email
UserName Login name
UserPassword Password
DateCreated Auto-filled on add
DateLastAccess Auto-filled on add
DateDeleted Soft-delete timestamp
IsActive TRUE or FALSE

CLI Reference

Run userbank with no arguments for the interactive setup wizard.

Installation

pip install .

Publishing

make publish

or

$ python -m build
$ python -m twine upload --repository pypi dist/*

Metadata

Release files for userbank 2.0.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 userbank 2.0.1
File Size Uploaded Provenance Actions
userbank-2.0.1.tar.gz 8.8 kB Without provenance Details for userbank-2.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 17.2 kB

Release files / userbank-2.0.1.tar.gz

Download URL userbank-2.0.1.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9c79a625342776e713685ac8364a1c3f57cacc6a3824357ba378757ab2422c72
BLAKE2b-256 checksum
How to use checksums
6a5a9289850d4d5da30049b50a987b975dc1e475125c9bcdedc029150c410cbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.9

Release files / userbank-2.0.1-py3-none-any.whl

Download URL userbank-2.0.1-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ba497567409421c4d07e92a17c143a23c4a244c4b4b2353127f04b253e06d1d
BLAKE2b-256 checksum
How to use checksums
a716e1410298895e3c6c37cd1b526d6ee16f064c8f65259270488320c0254c5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.9

Security for userbank 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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