Skip to main content

Making things easier for developers of all skill levels to develop complex applications.

Project description

Suitkaise

Making things easier for developers of all skill levels to develop complex Python programs.

(pronounced exactly like the word suitcase)

All files in this repository are licensed under the Apache License 2.0, including:

  • source code
  • examples
  • documentation
  • tests
  • site content code
  • and everything else

Installation

pip install suitkaise

Info

Explicitly supported Python versions: 3.11 and above

Currently, suitkaise is version 0.4.0 beta.

suitkaise contains the following modules:

  • cucumber: serialization engine
  • circuits: flow control with the Circuit and BreakingCircuit classes.
  • processing: upgraded multiprocessing with easy shared state
  • paths: upgraded path class and utilities for path ops
  • sk: modifiers for functions and class methods
  • timing: timer class with deep statistics usable in many ways

Documentation

All documentation is available for download.

CLI:

  • downloads to project root
  • cwd must be within project root
suitkaise docs

Python:

from suitkaise import docs

# download to project root
docs.download()

# download to a specific path within your project
docs.download("path/within/project")

To place docs outside your project root, use the Permission context manager.

from suitkaise import docs

with docs.Permission():
    docs.download("/Users/joe/Documents")

You can also view more at suitkaise.info.

Quick Start

Parallel processing with shared state

from suitkaise.processing import Share, Pool, Skprocess
import logging

# put anything on Share — literally anything
share = Share()
share.counter = 0
share.results = []
share.log = logging.getLogger("worker")

class Worker(Skprocess):
    def __init__(self, share, item):
        self.share = share
        self.item = item

    def __run__(self):
        result = self.item * 2
        self.share.results.append(result)       # shared list
        self.share.counter += 1                 # shared counter
        self.share.log.info(f"done: {result}")  # shared logger

pool = Pool(workers=4)
pool.star().map(Worker, [(share, x) for x in range(20)])

print(share.counter)         # 20
print(len(share.results))    # 20
print(share.log.handlers)    # still works

Serialize anything

from suitkaise import cucumber

data = cucumber.serialize(any_object)
restored = cucumber.deserialize(data)

Time anything

from suitkaise.timing import timethis

@timethis()
def my_function():
    do_work()

my_function()
print(my_function.timer.mean)
from suitkaise.timing import TimeThis

with TimeThis() as timer:
    do_this()
    then_this()
    this_too()

# stops timing and records on exit

# get most recent time
print(timer.most_recent)

Add retry, timeout, background execution to any function

from suitkaise import sk

@sk
def fetch(url):
    return requests.get(url).json()

# retry 3 times, timeout after 5 seconds each attempt
data = fetch.retry(3).timeout(5.0)("https://api.example.com")

Cross-platform paths, normalized path types

from suitkaise.paths import Skpath

path = Skpath("data/file.txt")
print(path.rp)  # "data/file.txt" — same on every machine, every OS
from suitkaise.paths import autopath

@autopath()
def process(path: AnyPath):
    print(path.rp)  # always an Skpath, no matter what was passed in

process("data/file.txt")        # str → Skpath
process(Path("data/file.txt"))  # Path → Skpath

Circuit breakers

from suitkaise import Circuit

circuit = Circuit(num_shorts_to_trip=5, sleep_time_after_trip=1.0)

for request in requests:
    try:
        process(request)
    except ServiceError:
        circuit.short()
from suitkaise import BreakingCircuit

breaker = BreakingCircuit(num_shorts_to_trip=3, sleep_time_after_trip=1.0)

while not breaker.broken:
    try:
        result = risky_operation()
        break  # success
    except OperationError:
        breaker.short()  # count the failure

if breaker.broken:
    handle_failure()

For more, see the full documentation at suitkaise.info or download the docs with suitkaise docs in your terminal after installation.

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

suitkaise-0.4.6b0.tar.gz (410.7 kB view details)

Uploaded Source

Built Distribution

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

suitkaise-0.4.6b0-py3-none-any.whl (479.7 kB view details)

Uploaded Python 3

File details

Details for the file suitkaise-0.4.6b0.tar.gz.

File metadata

  • Download URL: suitkaise-0.4.6b0.tar.gz
  • Upload date:
  • Size: 410.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.12

File hashes

Hashes for suitkaise-0.4.6b0.tar.gz
Algorithm Hash digest
SHA256 6d224f1173a47bc0be6e88a04d51c76ba03d264bcfe4aec43b26da7014d0efd8
MD5 406869dd2e1ada72a77253b4e9e21111
BLAKE2b-256 be34d082184bd90975ac079cf79e6f34de170c436a85e8d50658229764a06787

See more details on using hashes here.

File details

Details for the file suitkaise-0.4.6b0-py3-none-any.whl.

File metadata

  • Download URL: suitkaise-0.4.6b0-py3-none-any.whl
  • Upload date:
  • Size: 479.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.12

File hashes

Hashes for suitkaise-0.4.6b0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9ad49a44f6902065dd49aa81d194f0d32f63b11dd4d6722d25f5913c38250a4
MD5 aee496d1b4f6369aab732161a6de302e
BLAKE2b-256 1189f4a20d29f23837eaedb25f648397dc6c7c16270092bd44411ebbfdf51b71

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