Skip to content

Instantly share code, notes, and snippets.

View aaron-ortega's full-sized avatar
🐕
WFH

Aaron Ortega aaron-ortega

🐕
WFH
View GitHub Profile
import boto3
from upath import UPath
def directories_with_boto3(
bucket: str, prefix: str, protocol: str = "s3"
) -> list[UPath] | None:
"""List the top level directories in the S3 bucket relative to the provided prefix."""
path = UPath(bucket + prefix, protocol=protocol)
contents = [content for content in path.iterdir() if content.is_dir()]
@aaron-ortega
aaron-ortega / compose.py
Last active November 27, 2021 03:27
Function Composition in Python
import functools
from typing import Callable
def compose(*functions: Callable) -> Callable:
return functools.reduce(lambda f, g: lambda x: g(f(x)), functions)
def add_four(x):
return x + 4