Snakepit.Compatibility (Snakepit v0.6.10)
View SourceLibrary 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
:threadprofile - Not thread-safe: Library should only be used with
:processprofile - Conditional: Thread-safe with specific configuration
- Unknown: Thread safety not verified
Sources
Compatibility information is gathered from:
- Official library documentation
- https://py-free-threading.github.io/tracking/
- https://hugovk.github.io/free-threaded-wheels/
- Community testing and reports
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
Functions
@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"}
@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 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 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"
}}
@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", ...]
}