# 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]"
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}")
The package includes an interactive CLI:
# Run the CLI
bank-cli
# Or run directly
python -m bank_management.cli
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:
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:
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:
account.deposit(500.0)
account.withdraw(200.0)
bank.transfer(
from_account_number="CHK001",
to_account_number="SAV001",
amount=1000.0
)
# 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)
# Save all accounts
bank.save()
# Load previously saved accounts
bank.load()
# 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")
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}")
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}")
# 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}")
# 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)
# 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")
See the examples/ directory for complete working examples:
basic_usage.py - Simple operations and account managementadvanced_usage.py - Error handling and complex scenariosRun examples:
python examples/basic_usage.py
python examples/advanced_usage.py