Skip to content

Instantly share code, notes, and snippets.

View ahopkins's full-sized avatar

Adam Hopkins ahopkins

View GitHub Profile
@ahopkins
ahopkins / flexibly_decorator.py
Last active January 3, 2023 10:00
Decorator to cover all use cases
from abc import ABC, abstractmethod
from functools import partial, wraps
class BaseFlexibleDecorator(ABC):
__name__: str
def __init__(self, func=None, *decorator_args, **decorator_kwargs):
if func:
wraps(func)(self)
from __future__ import annotations
import re
from dataclasses import dataclass, field
from typing import Iterator, List, Optional
from urllib.parse import urlencode
from rich import print

Sanic Live Reload

Uses livereload.js to run a live reload server with Sanic. Startup, with auto-reload enabled. In this example, we also are adding an extra directory to listen to:

sanic server:app --dev -R ./content

Run the example. Open http://127.0.0.1:8000/ in a browser with a livereload extension installed. Make a change to ./content/hello.txt and save. Your browser should now update to the new text.