Skip to main content

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

  • 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.json to 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.json defines default dataset paths, output directories, and behavior flags.

Installation

It is recommended to use a virtual environment (conda or venv).

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.txt for additional dependencies.
  • Example: python-box==7.3.2 (imported as from 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 MalwareClassifier class in MalwareClassifier.py defines the workflow skeleton. Subclass it to override feature(), vectorize(), model(), and predict().

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.json when 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:

    1. Using the log_dir argument in setup_logging
    2. Using the environment variable MALCLASS_LOG_DIR
    3. Defaults to ./output/log/

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)

  1. Publish to PyPI first.
  2. Submit a PR to conda-forge/staged-recipes with a meta.yaml.
  3. 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

malwareclassifier-0.1.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

malwareclassifier-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

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

Hashes for malwareclassifier-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9ca6e097409abcbf2b70dabcbaac3e60b27d51e24002217ba08946c692a2a5f4
MD5 8937b25e9c51bdaf59603740b99c4c79
BLAKE2b-256 4b3fbec319c25e5ad58cb29d4b3471eb43f9e8aae799341eaa0e9afb2e8d5c16

See more details on using hashes here.

File details

Details for the file malwareclassifier-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for malwareclassifier-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23d5c16af7a4a4449429c944f3396276a27f0a3c8b33f1a2e030f3359a95ac51
MD5 54ab6222bbe45d2972b7d1760bf81105
BLAKE2b-256 9b0fdddbe18861c098e8f5e54e027f56e66df69d6a3b2073ff7540f1156bba7f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page