Skip to main content

Core utilities and types for Spryx projects

Project description

Spryx Core

PyPI version Python versions Documentation Status

Core utilities and types for Spryx projects.

Overview

Spryx Core 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
  • Permission handling utilities

Installation

pip install spryx-core

For development or optional features:

# For ULID support (recommended for ID generation)
pip install "spryx-core[ulid]"

Documentation

The full documentation is available at https://spryx-ai.github.io/spryx-core-py/

Local Documentation

You can also build and view the documentation locally:

# Install documentation dependencies
pip install mkdocs-material "mkdocstrings[python]"

# Serve documentation locally
mkdocs serve

# Build documentation
mkdocs build

Quick Usage

from spryx_core import generate_entity_id, now_utc, to_iso, Page

# 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}")

Development

See the Contributing Guide for instructions on how to set up the development environment and contribute to the project.

License

MIT

Features

spryx-core provides common utilities and type definitions used across Spryx projects, including:

Entity IDs

  • ULID generation and validation (with UUID fallback)
  • Custom EntityId type
from spryx_core import EntityId, generate_entity_id, is_valid_ulid

# Generate a new ID
entity_id = generate_entity_id()

# Validate an ID
if is_valid_ulid(some_string):
    # ...

Time Utilities

  • ISO-8601 UTC formatting and parsing
  • Common time operations (start/end of day, etc.)
from spryx_core import now_utc, to_iso, parse_iso, start_of_day

# Get current UTC time
now = now_utc()

# Format as ISO string
iso_string = to_iso(now)

# Parse ISO string
dt = parse_iso("2023-04-01T12:00:00.000Z")

# Get start of day
day_start = start_of_day(now)

Sentinel Values

  • NotGiven sentinel and related utilities
  • NOT_GIVEN singleton instance
from spryx_core import NOT_GIVEN, NotGivenOr, is_given

def my_function(optional_param: NotGivenOr[str] = NOT_GIVEN):
    if is_given(optional_param):
        # Handle provided value
    else:
        # Handle not provided case

Enumerations

  • Common enum types (Environment, SortOrder, etc.)
from spryx_core import Environment, SortOrder

# Environment types
if env == Environment.PRODUCTION:
    # ...

# Sort order
order = SortOrder.ASC

Documentation

Module: spryx_core.id

Functions for generating and validating entity IDs:

  • generate_entity_id() -> EntityId: Generates a new ULID or UUID
  • is_valid_ulid(value: str) -> bool: Validates a ULID string
  • cast_entity_id(value: str) -> EntityId: Casts a string to an EntityId

Module: spryx_core.time

Date/time utilities with UTC focus:

  • now_utc() -> datetime: Gets current UTC time
  • to_iso(dt: datetime, milliseconds: bool = False) -> str: Formats as ISO-8601
  • parse_iso(value: str) -> datetime: Parses ISO-8601 string
  • utc_from_timestamp(ts: int | float) -> datetime: Converts timestamp to datetime
  • start_of_day(dt: datetime | None = None) -> datetime: Gets day start (00:00:00)
  • end_of_day(dt: datetime | None = None) -> datetime: Gets day end (23:59:59.999999)

Module: spryx_core.types

Type utilities:

  • is_given(obj: NotGivenOr[_T]) -> TypeGuard[_T]: Checks if value is not NotGiven
  • default_or_given(obj: NotGivenOr[_T], default: Any = None) -> Union[_T, None]: Gets value or default

Module: spryx_core.enums

Common enumerations:

  • SortOrder: ASC, DESC
  • Environment: DEV, STAGING, PRODUCTION

Module: spryx_core.sentinels

Sentinel values:

  • NotGiven: Sentinel for unspecified values, distinct from None

Module: spryx_core.constants

Exported constants:

  • NOT_GIVEN: Singleton instance of NotGiven

License

This project is licensed under the MIT License - see the LICENSE file for details.

Requirements

  • Python 3.11+
  • Dependencies:
    • python-ulid (>=3.0.0,<4.0.0)
    • pydantic (>=2.11.3,<3.0.0)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spryx_core-0.1.3.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spryx_core-0.1.3-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file spryx_core-0.1.3.tar.gz.

File metadata

  • Download URL: spryx_core-0.1.3.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for spryx_core-0.1.3.tar.gz
Algorithm Hash digest
SHA256 31fdd12721e3fa437a8ab87b87a5d08b229d4baf7a4db3f5243f0d9a26586f0b
MD5 6651eeb42d8d2ce7c391c0c9c33b51a3
BLAKE2b-256 d010ef6665c39ed52db54b050792c1887d64dedcdd501eca2e7f21c89aff4410

See more details on using hashes here.

File details

Details for the file spryx_core-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: spryx_core-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for spryx_core-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f2b5691b730ed98e73e2a5e8e90b48f923df47d446a3ba7a0ad1b3a2e917dc34
MD5 bc337a4e9982ace18dcc91d9b15a645c
BLAKE2b-256 f3ace932e075310dc9570357e43b60b5fe58f7daa4a09d0fbd4292dd1a8f0295

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page