Dep-Logic Python Library

0.5.2 · active · verified Thu Apr 09

Dep-Logic is a Python library that provides a robust API for working with package version specifiers and dependencies, supporting logical operations (AND, OR) on them. It is currently at version 0.5.2 and sees active development with several releases per year.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create `Specifier` and `SpecifierSet` objects, perform logical AND/OR operations on them, check version containment, and define a `Dependency` object.

from dep_logic import Specifier, SpecifierSet, Dependency

# Define specifiers
spec1 = Specifier(">=1.0.0,<2.0.0")
spec2 = Specifier("~=1.5.0") # equivalent to >=1.5.0,==1.*,==1.5.*, <1.6.0 for a minor release

# Perform logical operations
combined_spec_and = spec1 & spec2 # Intersection
combined_spec_or = spec1 | spec2  # Union

print(f"Specifier 1: {spec1}")
print(f"Specifier 2: {spec2}")
print(f"Intersection (AND): {combined_spec_and}")
print(f"Union (OR): {combined_spec_or}")

# Check if a version satisfies a specifier
assert combined_spec_and.contains("1.5.2")
assert not combined_spec_and.contains("1.0.0")

# Define a dependency
my_dependency = Dependency("my_package", Specifier(">=1.0.0,<2.0.0"))
print(f"Dependency: {my_dependency}")

view raw JSON →