Bank-Management-OOP

Usage Guide

Getting Started

Installation

# Clone the repository
git clone https://github.com/pyenthusiasts/Bank-Management-OOP.git
cd Bank-Management-OOP

# Install in development mode
pip install -e .

# Or install with development dependencies
pip install -e ".[dev]"

Quick Start

from bank_management import Bank

# Create a bank
bank = Bank(name="My Bank")

# Create an account
account = bank.create_account(
    account_type="checking",
    account_number="CHK001",
    account_holder="John Doe",
    initial_balance=1000.0
)

# Perform operations
account.deposit(500.0)
account.withdraw(200.0)

# View balance
print(f"Balance: ${account.get_balance():.2f}")

Using the CLI

The package includes an interactive CLI:

# Run the CLI
bank-cli

# Or run directly
python -m bank_management.cli

CLI Features

Account Types

1. Checking Account

Best for everyday transactions.

checking = bank.create_account(
    account_type="checking",
    account_number="CHK001",
    account_holder="John Doe",
    initial_balance=1000.0,
    overdraft_limit=500.0,      # Optional: default 100.0
    transaction_fee=1.0,         # Optional: default 0.0
    free_transactions=5          # Optional: default 5
)

Features:

2. Savings Account

Best for saving money with interest.

savings = bank.create_account(
    account_type="savings",
    account_number="SAV001",
    account_holder="Jane Doe",
    initial_balance=5000.0,
    interest_rate=0.03,          # Optional: default 0.02 (2%)
    minimum_balance=500.0,       # Optional: default 100.0
    withdrawal_limit=6           # Optional: default 6
)

# Apply interest
interest = savings.add_interest()
print(f"Interest earned: ${interest:.2f}")

Features:

3. Business Account

Best for business operations.

business = bank.create_account(
    account_type="business",
    account_number="BUS001",
    account_holder="Bob Smith",
    business_name="Tech Corp",
    tax_id="12-3456789",
    initial_balance=10000.0,
    monthly_fee=25.0             # Optional: default 10.0
)

# Charge monthly fee
business.charge_monthly_fee()

Features:

Common Operations

Deposits

account.deposit(500.0)

Withdrawals

account.withdraw(200.0)

Transfers

bank.transfer(
    from_account_number="CHK001",
    to_account_number="SAV001",
    amount=1000.0
)

Transaction History

# Get all transactions
history = account.get_transaction_history()

# Get last 10 transactions
recent = account.get_transaction_history(limit=10)

# Print transactions
for txn in history:
    print(txn)

Data Persistence

Saving Data

# Save all accounts
bank.save()

Loading Data

# Load previously saved accounts
bank.load()

Creating Backups

# Create backup
backup_path = bank.storage.backup()
print(f"Backup saved to: {backup_path}")

# Create backup with custom path
bank.storage.backup("my_backup.json")

Error Handling

from bank_management.exceptions import (
    InsufficientFundsError,
    InvalidAmountError,
    MinimumBalanceError,
    AccountNotFoundError,
)

try:
    account.withdraw(10000.0)
except InsufficientFundsError as e:
    print(f"Error: {e}")
    print(f"Current balance: ${e.balance:.2f}")
    print(f"Attempted withdrawal: ${e.amount:.2f}")

try:
    account.deposit(-100.0)
except InvalidAmountError as e:
    print(f"Error: {e}")

try:
    bank.get_account("NONEXISTENT")
except AccountNotFoundError as e:
    print(f"Error: {e}")

Bank Statistics

stats = bank.get_statistics()

print(f"Total Accounts: {stats['total_accounts']}")
print(f"Total Balance: ${stats['total_balance']:.2f}")

print("\nAccounts by Type:")
for acc_type, count in stats['accounts_by_type'].items():
    balance = stats['balance_by_type'][acc_type]
    print(f"  {acc_type}: {count} accounts, ${balance:.2f}")

Advanced Usage

Custom Interest Calculation

# Apply interest multiple times (e.g., monthly for a year)
for month in range(12):
    interest = savings.add_interest()
    print(f"Month {month + 1}: Interest ${interest:.2f}")

Batch Operations

# Process multiple transactions
transactions = [
    ("deposit", 100.0),
    ("withdraw", 50.0),
    ("deposit", 200.0),
]

for operation, amount in transactions:
    if operation == "deposit":
        account.deposit(amount)
    elif operation == "withdraw":
        account.withdraw(amount)

Account Lifecycle Management

# Create account
account = bank.create_account("checking", "TMP001", "Temp User")

# Use account
account.deposit(1000.0)

# Delete when no longer needed
bank.delete_account("TMP001")

Best Practices

  1. Always handle exceptions when performing financial operations
  2. Save data regularly to persist changes
  3. Use appropriate account types for different purposes
  4. Validate inputs before passing to methods
  5. Monitor transaction limits for savings and checking accounts
  6. Create backups before major operations
  7. Review transaction history regularly

Examples

See the examples/ directory for complete working examples:

Run examples:

python examples/basic_usage.py
python examples/advanced_usage.py