A malware classifier template with built-in logging.
Project description
MalwareClassifier
MalwareClassifier is a Python package that provides a template for building a malware classification system with a built-in logging system and configurable settings.
It is designed to be modular, extensible, and easy to install using pip or conda.
Table of Contents
- Features
- Project Structure
- Installation
- Quick Start
- Configuration (
config.json) - Logging Usage
- Development Guide
- Publishing (PyPI / conda-forge)
- License
Features
- Malware Classification Template A structured skeleton for implementing training and prediction workflows.
- Built-in Logging Provides flexible logging with console and file outputs, automatic timestamped log filenames, and customizable log directories.
- Centralized Configuration
Uses
config.jsonto define dataset paths, output folders, and caching behavior. - Packaging Ready
Supports
pip install -e .for development mode and is prepared for publishing to PyPI and conda-forge.
Project Structure
MalwareClassifier/
├─ pyproject.toml
├─ LICENSE
├─ README.md
├─ requirements.txt
└─ src/
└─ MalwareClassifier/
├─ __init__.py
├─ Logging.py
├─ MalwareClassifier.py
├─ config.json
└─ config_loader.py
- The package name is
MalwareClassifier(case-sensitive).config.jsondefines default dataset paths, output directories, and behavior flags.
Installation
It is recommended to use a virtual environment (
condaorvenv).
Option A: Development mode (recommended)
# Clone the repository
git clone https://github.com/yourname/MalwareClassifier.git
cd MalwareClassifier
# Install in editable mode
pip install -e .
# Install additional dependencies if needed
pip install -r requirements.txt
Option B: Standard installation
pip install .
Note:
- Check
requirements.txtfor additional dependencies.- Example:
python-box==7.3.2(imported asfrom box import Box).
Quick Start
1) Minimal example (using the default config.json)
import MalwareClassifier as MC
# Initialize logging (by default, logs are written to ./output/log/)
MC.setup_logging()
# Create the classifier instance
clf = MC.MalwareClassifier(config_path="./config.json")
# Typical workflow (override these methods in subclasses if needed)
clf.feature() # Feature extraction
clf.vectorize() # Feature vectorization
clf.model(action="train") # Train or load model
clf.predict() # Run predictions
The
MalwareClassifierclass inMalwareClassifier.pydefines the workflow skeleton. Subclass it to overridefeature(),vectorize(),model(), andpredict().
2) Specify a custom log directory
MC.setup_logging(log_dir="./output/log")
Or via environment variables (lower priority than the function argument):
# Linux/macOS
export MALCLASS_LOG_DIR=./output/log
# Windows PowerShell
$env:MALCLASS_LOG_DIR="./output/log"
Configuration (config.json)
The package includes a default config.json:
{
"file": {
"label": "./dataset/label.csv"
},
"folder": {
"log": "./output/log/",
"dataset": "./dataset/",
"feature": "./output/feature/",
"vectorize": "./output/vectorize/",
"model": "./output/model/",
"predict": "./output/predict/"
},
"parameter": {
"feature": { "save": true, "load": false },
"vectorize": { "save": true, "load": false },
"model": { "save": true, "load": false },
"predict": { "save": true, "load": false }
}
}
- folder → Defines output directories for logs, models, features, etc.
- parameter.* → Flags to control whether intermediate results are saved or loaded.
- You can provide your own
config.jsonwhen creating a classifier:
clf = MC.MalwareClassifier(config_path="./my_config.json")
Logging Usage
The logging system is defined in src/MalwareClassifier/Logging.py.
Available functions
setup_logging(config=None, reset_handlers=True, log_dir=None)Initialize logging with optional config overrides.get_logger(name=None)Retrieve a logger for any module.
Default behavior
-
Logs are written both to console and file.
-
Log files are automatically named as:
malware_classifier-YYYYMMDD-HHMMSS.log -
The log directory can be configured:
- Using the
log_dirargument insetup_logging - Using the environment variable
MALCLASS_LOG_DIR - Defaults to
./output/log/
- Using the
Environment variables
| Variable | Description | Example |
|---|---|---|
MALCLASS_LOG_LEVEL |
Set log level | DEBUG, INFO |
MALCLASS_LOG_FILE |
Full path for the log file | /tmp/log.txt |
MALCLASS_LOG_DIR |
Directory for log files | ./output/log |
MALCLASS_LOG_FORMATTER |
Choose formatter: basic, verbose, json |
verbose |
Note: JSON logging requires installing python-json-logger.
Example usage in modules
from MalwareClassifier import get_logger
logger = get_logger(__name__)
logger.info("This is an info message")
logger.debug("This is a debug message")
Development Guide
Setup development environment
# Create a virtual environment
conda create -n malclass python=3.10
conda activate malclass
# Install the package in editable mode
pip install -e .
pip install -r requirements.txt
Verify installation
python -c "import MalwareClassifier as MC; MC.setup_logging(); print(MC.__version__)"
Clean build artifacts
rm -rf build/ dist/ *.egg-info
Publishing (PyPI / conda-forge)
Publish to PyPI
pip install build twine
python -m build
twine upload dist/*
Publish to conda-forge (summary)
- Publish to PyPI first.
- Submit a PR to conda-forge/staged-recipes with a
meta.yaml. - Once merged, conda-forge will handle future version tracking automatically.
License
This project is licensed under the terms of the MIT License.
Contact
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file malwareclassifier-0.1.0.tar.gz.
File metadata
- Download URL: malwareclassifier-0.1.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ca6e097409abcbf2b70dabcbaac3e60b27d51e24002217ba08946c692a2a5f4
|
|
| MD5 |
8937b25e9c51bdaf59603740b99c4c79
|
|
| BLAKE2b-256 |
4b3fbec319c25e5ad58cb29d4b3471eb43f9e8aae799341eaa0e9afb2e8d5c16
|
File details
Details for the file malwareclassifier-0.1.0-py3-none-any.whl.
File metadata
- Download URL: malwareclassifier-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23d5c16af7a4a4449429c944f3396276a27f0a3c8b33f1a2e030f3359a95ac51
|
|
| MD5 |
54ab6222bbe45d2972b7d1760bf81105
|
|
| BLAKE2b-256 |
9b0fdddbe18861c098e8f5e54e027f56e66df69d6a3b2073ff7540f1156bba7f
|