Python Lab Toolkit (python-lab-toolkit)
A beginner-friendly, production-quality Python package and CLI named pylab designed to generate complete, working, runnable solutions for all 52 Python laboratory questions with automatic dataset downloading and verified offline support.
Table of Contents
- Key Features
- Installation
- Quick Start
- Complete Command Reference
- The 52 Lab Questions Catalog
- Automated Dataset Management
- Offline Installation & Laboratory Bundle
- Database Configuration (SQLite & MySQL)
- CGI Web Handlers and Local Test Servers
- Troubleshooting & FAQ
- Development & Automated Testing
- PyPI Publication Guide
- License & Dataset Attribution
1. Key Features
- Short, Intuitive Commands: Generate any project with simple commands like
pylab q1,pylab q12,pylab q49. - Zero Comments in Generated Code: In accordance with clean code standards, generated Python source code contains no explanatory inline comments, decorative comments, or header comments, remaining self-explanatory through readable structure and expressive naming.
- Real, Runnable Python Files: Generates real files on disk (not hidden functions or stubs) that students and instructors can inspect, run, and modify.
- Automated Dataset Handling: Automatically downloads datasets when missing or instantly extracts verified bundled datasets when offline.
- 100% Offline Capable: Small verified copies of all required datasets (
winequality-red.csv,iris.csv,breast-cancer.csv,groceries.csv,Data.csv,dirtydata.csv,alphabet_stock_data.csv,rainfall.csv,students.csv) are bundled inside the package wheel. - Zero External Dependencies for Generator: The
pylabCLI and generator depend strictly on the Python standard library. It installs anywhere instantly without dependency conflicts. - Accidental Overwrite Protection: Existing user files are never silently overwritten. Use
--forceto deliberately replace files. - Built-in System Doctor: Run
pylab doctorto check Python versions, directory permissions, and optional scientific libraries.
2. Installation
Standard Installation via pip
python -m pip install python-lab-toolkit
Optional Scientific Libraries
The core toolkit runs anywhere on standard Python. If you want to execute machine learning, plotting, or numerical labs (Q23, Q31-Q52), install the scientific packages:
python -m pip install -r requirements-labs.txt
Or install specific dependencies per question:
pylab install-deps q49
3. Quick Start
1. View Available Questions
pylab list
2. Generate a Single Question
Generate the modular text analysis lab (Question 12):
pylab q12
Output:
Question 12 generated successfully.
Project: q12_text_analysis/
Files:
text_preprocessor.py
text_analyzer.py
main_analyzer.py
README.md
Run:
python q12_text_analysis/main_analyzer.py
3. Run the Generated Program
python q12_text_analysis/main_analyzer.py
4. Generate Machine Learning Labs with Automatic Datasets
Generate the 22-step Wine Quality regression pipeline:
pylab q49
This automatically obtains winequality-red.csv and winequality-white.csv, creates results/, and generates wine_regression.py and README.md.
4. Complete Command Reference
| Command | Description |
|---|---|
pylab list |
Display all 52 registered questions with numbers, titles, and categories. |
pylab list --category <cat> |
Filter questions by category (fundamentals, oop, pandas, etc.). |
pylab q<N> |
Generate Question <N> (e.g. pylab q1, pylab q25, pylab q49). |
pylab q<N> --force |
Overwrite existing project files. |
pylab q<N> --offline |
Force usage of bundled offline datasets. |
pylab q<N> --output-dir <dir> |
Generate the project inside a specified directory. |
pylab category <cat> |
Generate all questions belonging to a specific category. |
pylab all |
Generate all 52 questions (prompts for confirmation). |
pylab all --yes |
Generate all 52 questions non-interactively. |
pylab doctor |
Inspect environment, Python version, directory write permissions, and libraries. |
pylab datasets |
Display status and metadata for all bundled and downloadable datasets. |
pylab install-deps <q> |
Check and install missing optional pip packages for a specific question. |
pylab version |
Show the installed toolkit version. |
pylab --help |
Display CLI help and options. |
5. The 52 Lab Questions Catalog
Python Fundamentals (Questions 1–11)
- Q1 (
q01_variable_name_validator): Validate identifier rules and check reserved keywords usingkeyword.iskeyword(). - Q2 (
q02_single_number): Find the unique integer in an array where all other integers appear twice using XOR ($O(n)$ time, $O(1)$ space). - Q3 (
q03_string_operations): Implementprocess_string()to display uppercase, lowercase, length, slicing reversal[::-1], and palindrome status. - Q4 (
q04_menu_string_processor): Menu-driven program for substring checking, character occurrence counting, substring replacement, and uppercase conversion. - Q5 (
q05_phonebook): Dictionary-based contact management supporting Add, Update, Search, Delete, and Display. - Q6 (
q06_simple_calculator): Arithmetic calculator supporting+,-,*,/,//,%,**with zero-division handling. - Q7 (
q07_session_attendees): Set operations on conference attendees: Union, Intersection, AI-only, and Cybersecurity-only. - Q8 (
q08_number_properties): Functions verifying Even/Odd, Palindrome, Armstrong numbers, Prime numbers, and Perfect numbers. - Q9 (
q09_greet_people): Variable argument functiongreet_people(*names)handling zero, one, or multiple parameters. - Q10 (
q10_password_strength): Password validator testing length, digits, uppercase, lowercase, and special characters with detailed deficiency reporting. - Q11 (
q11_recursion): Recursive sum and recursive factorial evaluated on $n = 5, 10, 18$.
Modular Programming (Question 12)
- Q12 (
q12_text_analysis): Multi-module architecture withtext_preprocessor.py,text_analyzer.py, andmain_analyzer.pydisplaying required function docstrings via__doc__.
Object-Oriented Programming (Questions 13–18)
- Q13 (
q13_student_class):Studentclass withname,roll_number,course, anddisplay(). - Q14 (
q14_circle_class):Circleclass with radius,area(), andcircumference()methods usingmath.pi. - Q15 (
q15_employee_salary):Employeegross salary calculator with basic pay, HRA (20%), and DA (10%). - Q16 (
q16_smart_calculator):SmartCalculatordemonstrating default arguments,*argsmultiplication, and polymorphic type dispatch. - Q17 (
q17_complex_number):ComplexNumberclass with+(__add__) and==(__eq__) operator overloading. - Q18 (
q18_vehicle_inheritance):Vehiclebase class andCarderived class with method overriding andsuper().
Files, Exceptions, and Dates (Questions 19–22)
- Q19 (
q19_file_word_counter): Read text file, count lines, words, characters, find top 5 frequent words, and handle file exceptions. Includessample.txt. - Q20 (
q20_custom_exception_age): Custom exceptionInvalidAgeExceptionvalidating ages between 18 and 60. - Q21 (
q21_transaction_handling): Robust banking transaction demonstratingtry,except,else, andfinallyblocks. - Q22 (
q22_date_formatter): Date parser convertingdd-mm-yyyytoMonthName dd, yyyywith invalid calendar date detection.
CSV Processing (Questions 23–24)
- Q23 (
q23_rainfall_analysis): Read rainfall CSV data, calculate station averages, maximum rainfall record, standard deviation, and export results. - Q24 (
q24_students_csv): Managestudents.csv, find highest-scoring student, and compute class average marks.
Database Systems (Questions 25–26)
- Q25 (
q25_sqlite_library): SQLite Library Management system with parameterized single inserts,executemany()batch inserts, category queries, and menu CLI. - Q26 (
q26_mysql_employee): MySQL Employee Management system with parameterized queries, salary filtering (> ₹50,000), and secure environment credentials.
REST API & Networking (Question 27)
- Q27 (
q27_crudcrud_api): Functionalrequests-based REST client performing Create, Read, Update, and Delete on students. Includes built-inmock_server.pyfor offline testing!
CGI & Web Applications (Questions 28–30)
- Q28 (
q28_cgi_login): HTML login form and Python CGI handler displaying welcome response, with built-inserver.py. - Q29 (
q29_cgi_registration): MSc registration form and Python CGI script returning formatted admission receipt. - Q30 (
q30_cgi_crud): Web-based database CRUD portal backed by SQLite, HTML frontend, and Python CGI HTTP server.
NumPy and Pandas Numerical Analysis (Questions 31–43)
- Q31 (
q31_numpy_matrix_operations): Array 1–20 reshaped to 4×5, transpose, total/row/column sums, and even number extraction. - Q32 (
q32_numpy_slicing_reversal): 5×5 array (1–25) submatrix slicing, row slicing, column slicing, and axis reversals. - Q33 (
q33_pandas_student_pass_fail): Convert student marks Series to DataFrame, classify Pass/Fail, and filter passing students. - Q34 (
q34_pandas_employee_salary): Departmental salary analysis computing average salary per department and top earner. - Q35 (
q35_pandas_sales_barchart): 6 months sales table for 3 products, detecting top month, and plotting bar chart toresults/. - Q36 (
q36_pandas_weather_plot): 7-day weather table calculating average temperature and total rainfall, plotting temperature trend line. - Q37 (
q37_pandas_age_categorization): Continuous age categorization usingpd.cut()with mismatch detection. - Q38 (
q38_pandas_concat_rows): Concatenate two student DataFrames along rows (axis=0). - Q39 (
q39_pandas_concat_cols): Combine student DataFrames along columns (axis=1). - Q40 (
q40_pandas_concat_merge): Concatenate student batches and merge with exam scores DataFrame onstudent_id. - Q41 (
q41_pandas_join_operations): Relational join operations: Inner, Left, Right, and Outer joins with detailed semantics explanation. - Q42 (
q42_pandas_groupby_school): Group school records by school code, compute mean/min/max age, and inspect GroupBy object type. - Q43 (
q43_pandas_groupby_multi): Multi-column GroupBy (['school_code', 'class']) computing group counts withsize().
Visualization and Preprocessing (Questions 44–48)
- Q44 (
q44_alphabet_stock_visualization): Alphabet stock historical data filtering, line plots, volume bar plot, stacked OHLC histogram, and scatter correlation. - Q45 (
q45_multi_plot_demonstration): 2×2 multi-plot demonstration grid (waveform, categories, scatter, histogram). - Q46 (
q46_dataframe_barchart): Grouped categorical bar plot with value annotations and legends. - Q47 (
q47_data_preprocessing): Impute missing numerical values (SimpleImputer), One-Hot encode categorical features, and standard scale features (StandardScaler). - Q48 (
q48_dirtydata_cleaning): Clean dirty dataset: fix inconsistent date formats, impute null calories, correct outlier duration, and drop duplicates.
Machine Learning & Data Mining Pipelines (Questions 49–52)
- Q49 (
q49_wine_quality_regression): Full 22-step regression pipeline on red and white wine: data integration, correlation heatmap, feature scaling, Linear Regression, Decision Tree Regressor, Random Forest Regressor, and $R^2$, MAE, MSE, RMSE evaluation. - Q50 (
q50_breast_cancer_classification): Breast cancer diagnosis classification, Random Forest feature ranking, top-feature reduction, and classifier comparison (Decision Tree, Random Forest, Logistic Regression) with confusion matrices and false-negative analysis. - Q51 (
q51_iris_clustering): Unsupervised clustering on Iris features: standardization, K-Means ($k = 2, 3, 4$), elbow method, and 2D PCA cluster visualization. - Q52 (
q52_apriori_association_rules): Market basket transaction processing with Apriori, frequent itemset generation, and association rules sorted by lift.
6. Automated Dataset Management
When generating questions requiring datasets, pylab automatically acquires them:
q49_wine_quality_regression/
├── wine_regression.py
├── winequality-red.csv <-- Auto-acquired
├── winequality-white.csv <-- Auto-acquired
├── README.md
└── results/
Dataset Registry
| Dataset Filename | Used In | Official Source | Bundled Offline |
|---|---|---|---|
winequality-red.csv |
Q49 | UCI Machine Learning Repository | Yes |
winequality-white.csv |
Q49 | UCI Machine Learning Repository | Yes |
breast-cancer.csv |
Q50 | UCI Machine Learning Repository | Yes |
iris.csv |
Q51 | UCI Machine Learning Repository | Yes |
groceries.csv |
Q52 | Association Mining Market Baskets | Yes |
Data.csv |
Q47 | ML Preprocessing Reference Data | Yes |
dirtydata.csv |
Q48 | Data Cleaning Reference Data | Yes |
alphabet_stock_data.csv |
Q44 | Financial Time Series Reference | Yes |
rainfall.csv |
Q23 | Weather Station Records | Yes |
students.csv |
Q24 | Student Grades Records | Yes |
To view dataset status at any time, run:
pylab datasets
7. Offline Installation & Laboratory Bundle
In lab environments where internet access is unavailable or restricted, you can prepare an offline installation bundle.
Step 1: Prepare the Offline Wheels Folder (on an internet-connected machine)
mkdir -p offline_bundle/wheels
python -m pip download -d offline_bundle/wheels python-lab-toolkit
python -m pip download -d offline_bundle/wheels -r requirements-labs.txt
Step 2: Install Completely Offline in the Laboratory
Transfer the offline_bundle folder to your offline laboratory computers and install:
python -m pip install --no-index --find-links ./offline_bundle/wheels python-lab-toolkit
Step 3: Run Generation Offline
pylab q49 --offline
The toolkit will immediately use the verified bundled datasets stored inside the package wheel.
8. Database Configuration (SQLite & MySQL)
SQLite (Q25 & Q30)
SQLite is built into Python. No installation, server configuration, or credentials are required. The database files (library.db and cgi_records.db) are created automatically in the project folder.
MySQL (Q26)
Question 26 integrates with a MySQL database. To run Question 26 against your MySQL server:
- Start your local MySQL service (e.g.
sudo systemctl start mysqldor through XAMPP / MySQL Workbench). - Configure credentials using environment variables:
export MYSQL_HOST="localhost" export MYSQL_USER="root" export MYSQL_PASSWORD="your_password" export MYSQL_DATABASE="company_db"
- Run the manager:
python q26_mysql_employee/mysql_employee_manager.pyOr run the automated demonstration:python q26_mysql_employee/mysql_employee_manager.py --demo
9. CGI Web Handlers and Local Test Servers
Questions 28, 29, and 30 demonstrate CGI forms and web applications. Each generated project contains a self-contained local Python HTTP server (server.py).
To test in your browser:
cd q28_cgi_login
python server.py
Open http://localhost:8080 in your web browser. You can enter credentials, submit forms, and inspect the CGI responses immediately!
10. Troubleshooting & FAQ
"No module named 'numpy'" or other scientific library error
The code generator does not require scientific libraries, but running the generated script might. Run:
pylab install-deps <question_number>
# Example: pylab install-deps q49
Or install all lab dependencies at once:
pip install -r requirements-labs.txt
"The directory already contains existing files"
To prevent accidental loss of code, pylab will not overwrite existing directories. Pass --force:
pylab q12 --force
How can I check if my Python environment is ready?
Run the built-in system diagnostics tool:
pylab doctor
11. Development & Automated Testing
Running Tests
The toolkit includes a 56-test automated test suite verifying registry integrity, file generation, syntax correctness, comment absence (Rule A), CLI subcommands, database queries, and program execution.
Run the test suite using standard Python:
python -m unittest discover -s tests -v
Building Distribution Packages
Build modern wheel and source distributions into dist/:
python setup.py sdist bdist_wheel
12. PyPI Publication Guide
To publish python-lab-toolkit to PyPI:
Step 1: Install Build and Twine Tools
python -m pip install --upgrade build twine
Step 2: Build Clean Artifacts
rm -rf dist build src/*.egg-info
python -m build
Step 3: Check Package Metadata with Twine
python -m twine check dist/*
Step 4: Securely Upload to PyPI using an API Token
python -m twine upload --username __token__ dist/*
When prompted for your password, enter your PyPI API token (pypi-AgEI...).
13. License & Dataset Attribution
Package License
This software is distributed under the MIT License. See LICENSE for full details.
Dataset Attributions
- Wine Quality Datasets (
winequality-red.csv,winequality-white.csv): P. Cortez, A. Cerdeira, F. Almeida, T. Matos, and J. Reis (2009). Modeling wine preferences by data mining from physicochemical properties. Decision Support Systems, Elsevier, 47(4):547-553. - Breast Cancer Wisconsin (Diagnostic) Dataset (
breast-cancer.csv): Dr. William H. Wolberg, W. Nick Street, and Olvi L. Mangasarian. UCI Machine Learning Repository. - Iris Dataset (
iris.csv): R.A. Fisher (1936). The use of multiple measurements in taxonomic problems. Annals of Eugenics, 7, Part II, 179-188. - Groceries Dataset (
groceries.csv): Michael Hahsler, Kurt Hornik, and Christian Buchta (2005). arules - Mining Association Rules and Frequent Itemsets.
Metadata
Release files for python-lab-toolkit 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_lab_toolkit-1.0.0.tar.gz | 191.0 kB | Without provenance | Details for python_lab_toolkit-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_lab_toolkit-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for python_lab_toolkit-1.0.0-py3-none-any.whl |
Total release size: 392.2 kB
Release files / python_lab_toolkit-1.0.0.tar.gz
| Download URL | python_lab_toolkit-1.0.0.tar.gz |
|---|---|
| Size | 191.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8453333c5183a6b5c2d964b54a144d61864822710dd2108ca3b2e5f7f6673136
|
|
BLAKE2b-256 checksum How to use checksums |
4c16fb2b99ac3d924188c84a1013ed7b174dd8297dc0d1a6bd94cb56d87a8910
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Release files / python_lab_toolkit-1.0.0-py3-none-any.whl
| Download URL | python_lab_toolkit-1.0.0-py3-none-any.whl |
|---|---|
| Size | 201.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
912da7c32c4e36a87ea64942cc1f9d7c1f319f3857a925912d1cb6a66e400a00
|
|
BLAKE2b-256 checksum How to use checksums |
84202390d04900c5d64ec8f65f39a577cded3dfa2a7a20d09317e3d133b01247
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Security for python-lab-toolkit 1.0.0
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.