Skip to main content

A user management package using Firebase

Project description

User Management

A Python package for managing user-related operations using Firebase Authentication.

Installation

You can install the package using pip:

pip install user-management

Prerequisites

  1. A Firebase project
  2. Firebase service account credentials (as a JSON file or dictionary)
    • Go to Firebase Console
    • Project Settings > Service Accounts
    • Generate New Private Key
  3. Stripe API key (if using Stripe integration)

Configuration

The package provides a global configuration system that allows you to customize various settings in one place. You can configure settings in two ways:

  1. Using the configure function:
import user_management

user_management.configure(
    # Firebase configurations
    firebase_credentials_path="path/to/firebase-credentials.json",
    # OR
    firebase_credentials_dict={
        "type": "service_account",
        "project_id": "your-project-id",
        ...
    },
    firebase_app_name="your-app-name",  # Optional
    
    # Stripe configurations
    stripe_api_key="your-stripe-api-key",
    stripe_api_version="2023-10-16",  # Optional
    stripe_webhook_secret="your-webhook-secret",  # Optional
    
    # Database table names
    user_table_name="custom_users",
    customer_table_name="custom_customers",
    subscription_table_name="custom_subscriptions"
)
  1. Directly through the config object:
from user_management import config

# Firebase configurations
config.firebase_credentials_path = "path/to/firebase-credentials.json"
config.firebase_app_name = "your-app-name"

# Stripe configurations
config.stripe_api_key = "your-stripe-api-key"

# Database table names
config.user_table_name = "custom_users"
config.customer_table_name = "custom_customers"

Available Configuration Options

Firebase Configuration

  • firebase_credentials_path: Path to Firebase service account credentials JSON file
  • firebase_credentials_dict: Dictionary containing Firebase credentials
  • firebase_app_name: Optional name for the Firebase app instance

Stripe Configuration

  • stripe_api_key: Your Stripe API key
  • stripe_api_version: Stripe API version to use (default: "2023-10-16")
  • stripe_webhook_secret: Your Stripe webhook secret for verifying webhooks

Database Table Names

  • user_table_name: Name of the users table (default: "users")
  • customer_table_name: Name of the customers table (default: "customers")
  • subscription_table_name: Name of the subscriptions table (default: "subscriptions")

You can also add custom configuration options which will be stored in the custom_settings dictionary:

user_management.configure(
    custom_setting_1="value1",
    custom_setting_2="value2"
)

# Access custom settings
value = config.get("custom_setting_1", default="default_value")

Usage

Firebase Authentication

from user_management import FirebaseClient

# Initialize client using configuration (recommended)
client = FirebaseClient()

# Or provide credentials directly
client = FirebaseClient("path/to/firebase-credentials.json")

# Create a new user
user = client.create_user(
    email="user@example.com",
    password="securepassword123",
    display_name="John Doe"
)

Stripe Integration

from user_management import StripeClient

# Initialize client using configuration (recommended)
client = StripeClient()

# Or provide API key directly
client = StripeClient(api_key="your-stripe-api-key")

# Create a new customer
customer = client.create_customer(
    email="customer@example.com",
    name="John Doe"
)

User Profiles and Customers

from user_management import UserProfileClient, CustomerClient

# Initialize clients using configuration (recommended)
user_client = UserProfileClient()
org_client = CustomerClient()

# Create user profile
user = user_client.create_user(
    email="user@example.com",
    name="John Doe"
)

# Create organization
org = org_client.create_customer(
    name="Acme Corp",
    subscription_id="stripe_subscription_id",
    users=[user["id"]],
    is_org=True
)

Features

  • User creation and management
  • User information retrieval and updates
  • Custom claims management
  • JWT token verification
  • Type-safe with Pydantic models
  • Full Firebase Authentication integration
  • Flexible initialization with file path or credentials dictionary
  • Strong type hints and documentation

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

user_management-0.5.3.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

user_management-0.5.3-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file user_management-0.5.3.tar.gz.

File metadata

  • Download URL: user_management-0.5.3.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for user_management-0.5.3.tar.gz
Algorithm Hash digest
SHA256 0295efbed4b9bcb33091181794b1cd1b164713674d8e2ccb1d790f8b812f75c2
MD5 f8d6b3e8177d6bb5722a0262c0e2f277
BLAKE2b-256 0178d7e22a8e6e0a401fce951ff7386b94b692c1ec7b2862f69d8a4cbac612f2

See more details on using hashes here.

File details

Details for the file user_management-0.5.3-py3-none-any.whl.

File metadata

File hashes

Hashes for user_management-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 81b9784a8924aab2bd9ee6c6f5be86b66d5d8f3c24353eaba5158f38a75ceb02
MD5 5781da6d59133b4175563a941243f255
BLAKE2b-256 dd799fcd3c8822eb20584e9d2d015690c6206ee3bf3b46fe59a3c627b63be7ed

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