Skip to main content

A flexible Python library for boosting numeric values using the Strategy pattern. Designed for blockchain transactions to flexibly increase gas and gasPrice.

Project description

Test Package version Supported Python versions

Number Booster - Library for Boosting Numeric Values

A flexible Python library for boosting numeric values using the Strategy pattern. Designed for blockchain transactions to flexibly increase gas and gasPrice.

🎯 Overview

Number Booster provides a clean and extensible way to implement different boosting strategies for numeric values. While it's particularly useful for blockchain transactions where you need to adjust gas prices or transaction values, it can be used in any scenario requiring numeric value boosting.

⚡️ Features

  • Multiple boosting strategies:
    • Fixed multiplier boosting
    • Random range boosting
  • Support for both integer and float values
  • Type safety and comprehensive validation
  • Easy to extend with custom strategies
  • Clean Strategy pattern implementation

🚀 Installation

pip install number-booster

📖 Usage

Fixed Booster Strategy

Use when you need a consistent multiplication factor:

from number_booster import FixedBoosterStrategy

# Create a booster that multiplies values by 1.5
booster = FixedBoosterStrategy(multiplier=1.5)

# Boost a value
original_value = 100
boosted_value = booster.boost(original_value)  # Returns 150

Random Booster Strategy

Use when you need random multiplication within a specified range:

from number_booster import RandomBoosterStrategy

# Create a booster that multiplies values by a random factor between 1.1 and 1.5
booster = RandomBoosterStrategy(multiplier_min=1.1, multiplier_max=1.5)

# Boost a value
original_value = 100
boosted_value = booster.boost(original_value)  # Returns a random value between 110 and 150

Blockchain Transaction Example

from number_booster import RandomBoosterStrategy
from web3 import Web3, HTTPProvider

w3 = Web3(HTTPProvider('http://localhost:8545'))

# Initialize booster for gas price
gas_booster = RandomBoosterStrategy(multiplier_min=1.1, multiplier_max=1.3)

# Get current gas price
current_gas_price = w3.eth.gas_price
boosted_gas_price = gas_booster.boost(current_gas_price)

# Use in transaction
transaction = {
    'from': "0x1234567890123456789012345678901234567890",
    'to': "0x0987654321098765432109876543210987654321",
    'value': Web3.to_wei(1, 'ether'),
    'gasPrice': boosted_gas_price
}

🛠 Creating Custom Strategies

You can create your own boosting strategy by inheriting from BaseBoosterStrategy:

from number_booster.base import BaseBoosterStrategy, T

class CustomBoosterStrategy(BaseBoosterStrategy):
    def __init__(self, your_params):
        # Initialize your strategy
        pass

    def boost(self, value: T) -> T:
        # Implement your boosting logic
        return self._apply_multiplier(value, multiplier=your_multiplier)

⚠️ Notes

  • When using integer values with multipliers between 1 and 2, the boosted value might remain unchanged due to rounding
  • The minimum difference between min and max multipliers in RandomBoosterStrategy must be greater than 1e-6
  • Boolean values are not supported and will raise TypeError

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🔗 Links

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

number_booster-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

number_booster-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file number_booster-0.1.0.tar.gz.

File metadata

  • Download URL: number_booster-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.9 Windows/11

File hashes

Hashes for number_booster-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2d4b48220d5ba36e422dda2b3a4af4ed2e14106c73f462e87dd967232eeae67e
MD5 a743ec174364bd6a1c5032f2344cf71d
BLAKE2b-256 c9757f4c630f3d75f5e7fa8b51d6a546429f89774f4b654bbefbcabdff08b1d8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: number_booster-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.9 Windows/11

File hashes

Hashes for number_booster-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d77323456c376aa22fa0c27e9eef6f208b09a3f75d51960eee52be5e0d985f9
MD5 3140a3faf07216244e360a454db9ff0a
BLAKE2b-256 848b549b48b814f48b69b2d572dcd7c0ab0697502b9f78ae6362bf8419895bc7

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