Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

🎓 Student Management System (Python + Streamlit)

A complete Student Management System built in Python — featuring both a Command-Line Interface (CLI) version and a fully interactive Streamlit Web App.

This system allows you to add, update, view, delete, search, filter, import, export, and manage student records stored securely in a JSON database.


🌐 Live Web App (Streamlit)

👉 Deployed Link


📌 Project Description

This project provides two versions of the system:

1️⃣ CLI Version (studentmagnmt.py)

A terminal-based system with menu-driven options:

  • Add a student
  • Update student details
  • View one student
  • View all students
  • Remove a student
  • Automatically generate a unique Student ID
  • Store all data in students.json

2️⃣ Streamlit Web App (app.py)

A modern, interactive UI with:

  • Dashboard view
  • Search by name, email, or ID
  • Filter by age
  • Filter by course
  • View & inspect full student details
  • Add, update, delete students
  • Import/Export student records (JSON download / upload)
  • Course-based filtering
  • Dataset preview

🧠 What I Learned

🐍 Object-Oriented Programming (OOP) in Python

  • Defined a Student class to encapsulate all student-related data and behavior.
  • Used class attributes (data, database) shared across all instances to hold the in-memory dataset and file path.
  • Used instance methods (addstudent, updatestudent, viewstudent, removestudent, viewall) for CRUD operations.
class Student:
    database = 'students.json'
    data = []

🔒 Static Methods vs. Class Methods

  • @staticmethod — used for __generatestudentid() because it doesn't need access to the class or any instance.
  • @classmethod — used for __update() because it needs the class reference (cls) to open the correct database file.
@staticmethod
def __generatestudentid():
    ...

@classmethod
def __update(cls):
    with open(cls.database, 'w') as fs:
        fs.write(json.dumps(Student.data))

🆔 Unique ID Generation with random and string

Learned how to generate a human-readable unique student ID by combining:

  • random.choices(string.ascii_letters, k=7) — 7 random letters
  • random.choices(string.digits, k=4) — 4 random digits
  • random.choices("!@#$%&", k=1) — 1 special character
  • random.shuffle() — shuffle all parts together
  • .capitalize() — make the first character uppercase
alpha = random.choices(string.ascii_letters, k=7)
num   = random.choices(string.digits, k=4)
spchr = random.choices("!@#$%&", k=1)
id    = alpha + num + spchr
random.shuffle(id)
return "".join(id).capitalize()

💾 JSON as a Persistent Local Database

  • Learned to read a JSON file on startup with json.loads() and write back with json.dumps().
  • Used pathlib.Path.exists() to safely check if the database file exists before opening it, and create it if it doesn't.
if Path(database).exists():
    with open(database) as fs:
        data = json.loads(fs.read())
else:
    with open(database, 'w') as fs:
        fs.write('[]')

🔁 CRUD Operations

Operation Method Description
Create addstudent() Collects input, validates age, saves
Read viewstudent() Finds one student by ID
Read All viewall() Displays all students in the dataset
Update updatestudent() Looks up by ID, allows partial updates
Delete removestudent() Confirms with user before deleting

🔍 List Comprehensions for Filtering

Used list comprehensions to filter the in-memory list by student ID:

studdata = [i for i in Student.data if i['studentid'] == stuid]

✅ Input Validation

  • Validated that a student's age is 8 or above before creating a record.
  • Allowed users to skip fields during an update (press Enter to keep the old value).

⚠️ Exception Handling

  • Wrapped file I/O and user input in try/except blocks to handle errors gracefully.
try:
    resp = int(input("Enter your response: "))
except Exception as err:
    print(f"An error occured as {err}")

🖥️ Menu-Driven CLI with while True

Built an interactive console loop that keeps running until the user presses 6 to exit.

while True:
    print("Press '1' to add student.")
    ...
    if resp == 6:
        break

🌐 Streamlit Web App (app.py)

Extended the project into a web UI, learning:

  • Forms (st.form) for grouped input with a single submit action
  • Session state (st.session_state) to persist data between re-renders
  • Sidebar navigation (st.sidebar.radio) for page routing
  • Dataframes (st.dataframe) to display tabular student data
  • File upload/download (st.file_uploader, st.download_button) for JSON import/export
  • Atomic file writes (write to .tmp then rename) to avoid data corruption

🛠️ Technologies Used

Technology Purpose
Python Core language
json Persistent data storage
pathlib Safe file path handling
random & string Unique ID generation
datetime Timestamps on records
Streamlit Interactive web UI

▶️ How to Run

CLI Version

  1. Clone the repo:
git clone <repo-url>
cd StudentManagementProject
  1. Run the CLI program:
python studentmagnmt.py

Streamlit Web App

  1. Install dependencies:
pip install streamlit
  1. Run the app:
streamlit run app.py

Your browser will open the app automatically.


💡 Features at a Glance

CLI (studentmagnmt.py)

  • ✅ Add a student with auto-generated ID
  • ✅ Update name, email, and courses
  • ✅ View a single student by ID
  • ✅ View all students
  • ✅ Remove a student with confirmation

Web App (app.py)

  • ✅ Dashboard — search by keyword, filter by age & course
  • ✅ Add Student form with validation and auto ID
  • ✅ Update or delete any student
  • ✅ Import/Export full dataset as JSON
  • ✅ Dataset preview (first 10 rows)

About

This is my second ever Object Oriented Python Project.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages