No project description provided
Project description
Saboteur
A simple and extensible data mutation library for Chaos Engineering in Python.
🤔 What is Saboteur?
Saboteur is a lightweight Python library designed to test the robustness of your data processing logic. It helps you practice Chaos Engineering by intentionally and randomly injecting faulty or unexpected data into your system.
By "attacking" your data with various mutation strategies, Saboteur helps you uncover hidden bugs, handle edge cases gracefully, and build more resilient applications.
✨ Key Features
- Simple API: Get started in seconds with the intuitive
.attack()method. - Randomized Mutations: Automatically selects a random field and applies a random, applicable mutation to simulate real-world unpredictability.
- Extensible: Easily create and add your own custom mutation strategies to fit your specific needs.
- Lightweighted Dependencies: A pure Python library that can be dropped into any project without extra baggage.
💾 Installation
Install Saboteur directly from PyPI:
# pip
pip install saboteur
# poetry
pip install poetry && poetry add saboteur
🚀 Quick Start
Using Saboteur is straightforward. Import the Saboteur class and the desired strategies, then call the attack method on your data.
from saboteur.application.facade import Saboteur
from saboteur.infrastructure.strategies.injections import NullInjectionStrategy
from saboteur.infrastructure.strategies.flippings import TypeFlipStrategy
from saboteur.domain.mutation.configs import MutationConfig
# 1. Define the strategies you want to use
strategies = [
NullInjectionStrategy(),
TypeFlipStrategy(),
]
# 2. Set configuration what you want
config = MutationConfig(
strategies=strategies,
apply_all_strategies=True,
apply_all_keys=True,
)
# 3. Initialize Saboteur with your configuration
saboteur = Saboteur(config=config)
# 4. Prepare your data
mock_data = {
"user_id": 12345,
"username": "test_user",
"is_active": True,
"score": 987
}
# 5. Attack the data!
# Saboteur will randomly pick one key (e.g., "user_id") and apply one
# applicable strategy (e.g., TypeFlipStrategy).
mutated_data = saboteur.attack(mock_data)
# Example output: {'user_id': '12345', 'username': 'test_user', ...}
# Or: {'user_id': 12345, 'username': None, ...}
print(mutated_data)
🛠️ Available Strategies
Saboteur comes with a set of built-in strategies to get you started.
NullInjectionStrategy
Replaces the original value of a field with None. This is useful for testing how your code handles missing or null data.
- Applicable when: The original value is not
None. - Mutation:
original_value->None
TypeFlipStrategy
Changes the data type of a field. Currently supports int to str and str to int conversions. This helps test for TypeError exceptions and weak typing issues.
- Applicable when: The original value is an
intor astr. - Mutation:
int->str(e.g.,123->'123')str->int(e.g.,'456'->456). If the string is not a digit, it returns-1.
✍️ Creating a Custom Strategy
You can easily create your own strategies by inheriting from MutationStrategy and implementing two methods: is_applicable and apply.
Here's an example of a BooleanFlipStrategy that flips True to False and vice-versa.
# custom_strategies.py
from typing import Any
from saboteur.domain.mutation.strategies import MutationStrategy
from saboteur.domain.mutation.contexts import MutationContext
from saboteur.domain.mutation.configs import MutationConfig
class BooleanFlipStrategy(MutationStrategy):
"""Flips a boolean value."""
def is_applicable(self, context: MutationContext) -> bool:
# This strategy only applies to boolean types
return isinstance(context.original_value, bool)
def apply(self, context: MutationContext) -> Any:
# The mutation logic is simple: flip the boolean
return not context.original_value
# You can then use it with Saboteur:
strategies = [
BooleanFlipStrategy(),
# ... other strategies
]
config = MutationConfig(
strategies=strategies,
... # other options
)
saboteur = Saboteur(config=config)
🤝 Contributing
Contributions are welcome! Whether it's adding new strategies, improving documentation, or fixing bugs, please feel free to open an issue or submit a pull request.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
🗺️ Roadmap
Saboteur is currently focused on data mutation, but we plan to expand its capabilities. Future versions will include logic for API load testing, allowing you to simulate heavy traffic and test the performance and stability of your endpoints under stress.
📄 License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
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 saboteur-0.1.3.tar.gz.
File metadata
- Download URL: saboteur-0.1.3.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.11 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc3f05d3b052eb077bd404c9f85fce71e9ce1fc650a35c5b617b911a9be8ca7d
|
|
| MD5 |
e4c1298c130b7d4588362d72facaf7c2
|
|
| BLAKE2b-256 |
fc7a7e364883f1b416de7fc0d315d2bac9cbb4655ef5aebad692d0c122540582
|
File details
Details for the file saboteur-0.1.3-py3-none-any.whl.
File metadata
- Download URL: saboteur-0.1.3-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.11 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b5faf428fc73918979c339a6517c3f847dbe97ca6eb20f84c707fe08425d8cd
|
|
| MD5 |
8b3620a360fbf3da375e625a35011fbf
|
|
| BLAKE2b-256 |
9d20250187db677031b70fb71c651842eb0792ea6e95e76b0cc7910e45efb182
|