Spryx Core
Core utilities and types for Spryx projects
Overview
Spryx Core is a Python library that provides common utilities and type definitions used across Spryx projects, including:
- ID generation and validation using ULIDs
- Time manipulation and formatting utilities
- Pagination models for API responses
- Type definitions and sentinel values
- Common error classes
- Security utilities (permissions, token claims validation)
Installation
Quick Usage
from spryx_core import generate_entity_id, now_utc, to_iso, Page, Permission
# Generate unique IDs
entity_id = generate_entity_id()
print(entity_id) # Example: 01HNJG7VWTZA0CGTJ9T7WG9CPB
# Work with UTC timestamps
current_time = now_utc()
iso_timestamp = to_iso(current_time)
print(iso_timestamp) # Example: 2023-12-01T14:32:15.123456Z
# Create paginated responses
page = Page(
items=["item1", "item2"],
page=1,
page_size=10,
total=25
)
print(f"Current page: {page.page}, Total pages: {page.total_pages}")
# Work with permissions
user_perms = [Permission.READ_USERS, Permission.READ_ORDERS]
can_write = Permission.WRITE_USERS in user_perms # False
Features
- Type Safety: Strong typing support with proper annotations
- Performance: Optimized for speed and minimal resource usage
- Flexibility: Utilities that adapt to different project requirements
- Zero External Dependencies: Core library has no third-party dependencies (except for optional ULID support)
Check out the Getting Started guide for detailed usage examples.