Snakepit.Compatibility (Snakepit v0.6.10)

View Source

Library compatibility checking for thread-safe execution.

This module maintains a compatibility matrix of popular Python libraries and their thread safety characteristics. It helps users understand which libraries work well with the :thread worker profile vs :process profile.

Usage

# Check if a library is thread-safe
case Snakepit.Compatibility.check("numpy", :thread) do
  :ok -> "Safe to use"
  {:warning, msg} -> "Warning: " <> msg
  {:unknown, msg} -> "Unknown: " <> msg
end

# Get full library info
{:ok, info} = Snakepit.Compatibility.get_library_info("torch")

Compatibility Status

  • Thread-safe: Library can be used safely with :thread profile
  • Not thread-safe: Library should only be used with :process profile
  • Conditional: Thread-safe with specific configuration
  • Unknown: Thread safety not verified

Sources

Compatibility information is gathered from:

Summary

Functions

Check if a library is compatible with a given worker profile.

Check if a specific Python version is recommended for a library.

Generate a compatibility report for a list of libraries.

Get detailed information about a library's compatibility.

List all libraries in the compatibility matrix.

Types

check_result()

@type check_result() :: :ok | {:warning, String.t()} | {:unknown, String.t()}

profile()

@type profile() :: :process | :thread

thread_safe()

@type thread_safe() :: boolean()

Functions

check(library, profile)

@spec check(library :: String.t(), profile()) :: check_result()

Check if a library is compatible with a given worker profile.

Returns:

  • :ok - Library is safe to use
  • {:warning, message} - Library may have issues
  • {:unknown, message} - Compatibility unknown

Examples

iex> Snakepit.Compatibility.check("numpy", :thread)
:ok

iex> Snakepit.Compatibility.check("pandas", :thread)
{:warning, "Not thread-safe as of v2.0..."}

iex> Snakepit.Compatibility.check("unknown_lib", :thread)
{:unknown, "Compatibility unknown for unknown_lib"}

check_python_version(library, python_version)

@spec check_python_version(String.t(), {integer(), integer(), integer()}) ::
  check_result()

Check if a specific Python version is recommended for a library.

Some libraries require specific Python versions for free-threading support.

Examples

iex> Snakepit.Compatibility.check_python_version("numpy", {3, 13, 0})
:ok

iex> Snakepit.Compatibility.check_python_version("pandas", {3, 13, 0})
{:warning, "Library may not be optimized for Python 3.13 free-threading"}

generate_report(libraries, profile)

@spec generate_report([String.t()], profile()) :: map()

Generate a compatibility report for a list of libraries.

Useful for validating an adapter's dependencies before deployment.

Examples

iex> Snakepit.Compatibility.generate_report(["numpy", "pandas"], :thread)
%{
  compatible: ["numpy"],
  warnings: [{"pandas", "Not thread-safe..."}],
  unknown: []
}

get_library_info(library)

@spec get_library_info(String.t()) :: {:ok, map()} | {:error, :not_found}

Get detailed information about a library's compatibility.

Examples

iex> Snakepit.Compatibility.get_library_info("torch")
{:ok, %{
  thread_safe: true,
  notes: "Thread-safe with proper initialization...",
  recommendation: "Safe for :thread profile with configuration"
}}

list_all()

@spec list_all() :: map()

List all libraries in the compatibility matrix.

Returns a map grouped by thread safety status.

Examples

iex> Snakepit.Compatibility.list_all()
%{
  thread_safe: ["numpy", "torch", ...],
  not_thread_safe: ["pandas", "matplotlib", ...],
  conditional: ["scikit-learn", ...]
}