Skip to content

Instantly share code, notes, and snippets.

from enum import Enum, EnumMeta
from flask import Flask, current_app
from werkzeug.routing import BaseConverter, ValidationError
def setup_enum_converter(enum_to_convert):
if not isinstance(enum_to_convert, (Enum, EnumMeta,)):
@jnhmcknight
jnhmcknight / download_large_file.py
Created October 25, 2023 16:43 — forked from wasi0013/download_large_file.py
how to download large file using python, requests without exhausting device ram.
import requests
chunk_size = 4096
filename = "logo.png"
document_url = "https://wasi0013.files.wordpress.com/2018/11/my_website_logo_half_circle_green-e1546027650125.png"
with requests.get(document_url, stream=True) as r:
with open(filename, 'wb') as f:
for chunk in r.iter_content(chunk_size):
if chunk:
f.write(chunk)
@jnhmcknight
jnhmcknight / click_regex_option.py
Last active September 26, 2024 21:11
Regex Parameter handler for Click
import re
import sys
import typing as t
import click
from click._compat import _get_argv_encoding
class RegexOption(click.ParamType):
@jnhmcknight
jnhmcknight / wrapped_boto3.py
Last active October 29, 2024 17:00
Flask Wrapped Boto3
"""
Include this file in your project, and then import it instead of the real `boto3`,
wherever you need to create a `boto3.client` or `boto3.resource`
i.e.:
import wrapped_boto3
s3 = wrapped_boto3.client('s3')
@jnhmcknight
jnhmcknight / cli.py
Created January 24, 2025 18:17
Show all help for a whole Click command tree
import copy
import os
import click
@click.group()
def cli():
"""A grouping of commands"""