Skip to content

A powerful runtime validation framework that ensures your Python modules only run in compliant execution environments. Prevent unexpected failures, enforce security policies, and maintain stability across dynamic imports.

License

Notifications You must be signed in to change notification settings

atellaluca/ImportSpy

Repository files navigation

https://static.pepy.tech/badge/importspy https://img.shields.io/github/actions/workflow/status/atellaluca/ImportSpy/python-package.yml?style=flat-square https://img.shields.io/github/license/atellaluca/ImportSpy?style=flat-square Documentation Status

ImportSpy - Intelligent Import Validation πŸ›‘οΈ

Ensure compliance, prevent unexpected failures, and enforce execution rules dynamically.

  • πŸ” Monitor the runtime context before allowing imports.
  • ⚑ Eliminate environment inconsistencies before they break production.
  • πŸ›‘οΈ Enforce strict execution policies for imported modules.

ImportSpy Architecture

What is ImportSpy?

ImportSpy is a powerful runtime validation framework that ensures that external modules only import your code in a compliant execution environment.

Why is this important?

  • βœ… Prevents unexpected failures caused by incorrect dependencies.
  • βœ… Ensures security by blocking unauthorized imports.
  • βœ… Eliminates debugging headaches by validating environments dynamically.
  • βœ… Gives you full control over how and where your code is used.

Why Should You Use ImportSpy? πŸš€

ImportSpy solves real-world problems for Python developers, software architects, and enterprises that need to enforce execution constraints on external modules.

πŸ”΄ Without ImportSpy

  • ❌ Modules may break when imported into the wrong Python version.
  • ❌ Unexpected OS configurations may introduce silent failures.
  • ❌ Dependencies may change, leading to unpredictable execution issues.
  • ❌ No protection against external modules misusing your code.

🟒 With ImportSpy

  • βœ… Prevent misconfigured environments from executing your code.
  • βœ… Block unauthorized imports and enforce runtime policies.
  • βœ… Ensure every imported module meets strict execution requirements.
  • βœ… Gain full visibility into how your code is being used.

How ImportSpy Works

ImportSpy intercepts module imports and ensures they match predefined execution constraints before allowing execution.

The process is simple:

  1. Define execution constraints (e.g., OS, Python version, environment variables).
  2. ImportSpy validates runtime conditions dynamically.
  3. If the environment is compliant, execution proceeds.
  4. If the environment is non-compliant, ImportSpy blocks execution.

Example: Preventing Imports in the Wrong Environment

Imagine you want your module to be imported only in Python 3.10+, on Linux, with a specific environment variable. With ImportSpy, you can enforce this automatically.

from importspy.models import SpyModel, Deployment, Runtime, System, Python
from importspy.constants import Config

class MyModuleSpy(SpyModel):
    deployments = [
        Deployment(
            runtimes=[
                Runtime(
                    arch=Config.ARCH_X86_64,
                    systems=[
                        System(
                            os=Config.OS_LINUX,
                            pythons=[
                                Python(
                                    version="3.10",
                                    interpreter=Config.INTERPRETER_CPYTHON,
                                    modules=[]
                                )
                            ],
                            envs={"CI": True}
                        )
                    ]
                )
            ]
        )
    ]

βœ… If the importing module runs in a compliant environment, execution proceeds. ❌ If the execution environment does not meet these conditions, ImportSpy blocks execution.

Who Should Use ImportSpy?

  • πŸ”Ή Enterprise teams that need strict environment control.
  • πŸ”Ή Developers working with microservices, modular frameworks, or plugin-based architectures.
  • πŸ”Ή Security-conscious projects that want to restrict execution contexts.
  • πŸ”Ή Python package maintainers who need runtime validation for external users.

If your project relies on external modules, ImportSpy is your safeguard against execution chaos. πŸ”₯

Installation & Quickstart

ImportSpy is available on PyPI:

pip install importspy

Check out the Quickstart Guide for step-by-step instructions.

Support & Contribute

ImportSpy is open-source and thrives with your support!

Ways to Help πŸš€

  • ⭐ Star the project on GitHub β†’ Give it a star!
  • πŸ› οΈ Contribute β†’ Open issues, PRs, or improve docs.
  • πŸ“£ Share ImportSpy with developers who need execution control.
  • πŸ’– Sponsor ImportSpy to support development β†’ Become a sponsor.

Every contribution helps make ImportSpy better, stronger, and more useful!

License

ImportSpy is released under the MIT License. πŸ“œ Read the full license: LICENSE

πŸ”₯ Take control of your imports. Start using ImportSpy today! πŸš€