Essential utilities that grow smart solutions - shared utilities for the smart* ecosystem
Project description
SmartSeeds 🌱
Essential utilities that grow smart solutions
SmartSeeds is a lightweight, zero-dependency Python library providing core utilities for the smart* ecosystem (smartswitch, smartasync, etc.). Think of it as the seeds from which smart solutions grow.
Features
extract_kwargs: Decorator for extracting and grouping keyword arguments by prefixsmartsuper: Decorator for automatic superclass method calls (before/after)SmartOptions: Intelligent options merging with filtering and defaults- Three flexible styles: Prefix style, dict style, and boolean activation
- Zero dependencies: Pure Python standard library
- Full type hints: Complete typing support
Installation
pip install smartseeds
Quick Start
extract_kwargs Decorator
Extract kwargs by prefix into separate parameter groups - supports three convenient styles:
from smartseeds import extract_kwargs
@extract_kwargs(logging=True, cache=True)
def setup_service(name, logging_kwargs=None, cache_kwargs=None, **kwargs):
print(f"Logging config: {logging_kwargs}")
print(f"Cache config: {cache_kwargs}")
print(f"Other: {kwargs}")
# Style 1: Prefix style (most explicit)
setup_service(
name="api",
logging_level="INFO", # → logging_kwargs={'level': 'INFO'}
logging_format="json", # → logging_kwargs={'format': 'json'}
cache_ttl=300, # → cache_kwargs={'ttl': 300}
timeout=30 # → kwargs={'timeout': 30}
)
# Style 2: Dict style (compact)
setup_service(
name="api",
logging={'level': 'INFO', 'format': 'json'},
cache={'ttl': 300}
)
# Style 3: Boolean activation (use defaults)
setup_service(
name="api",
logging=True, # → logging_kwargs={} (empty dict for defaults)
cache=True
)
smartsuper Decorator
Automatically call parent class methods before or after your method - perfect for initialization chains and cleanup:
from smartseeds import smartsuper
# Style 1: Method decorator (BEFORE)
class Base:
def setup(self):
print("Base setup")
class Derived(Base):
@smartsuper # Calls Base.setup() BEFORE Derived.setup()
def setup(self):
print("Derived setup")
d = Derived()
d.setup()
# Output:
# Base setup
# Derived setup
# Style 2: Method decorator (AFTER)
class Base:
def cleanup(self):
print("Base cleanup")
class Derived(Base):
@smartsuper.after # Calls Base.cleanup() AFTER Derived.cleanup()
def cleanup(self):
print("Derived cleanup")
d = Derived()
d.cleanup()
# Output:
# Derived cleanup
# Base cleanup
# Style 3: Class decorator (auto-decorate all overrides)
class Base:
def foo(self):
print("Base.foo")
def bar(self):
print("Base.bar")
@smartsuper # Auto-decorates ALL overridden methods (BEFORE by default)
class Derived(Base):
def foo(self):
print("Derived.foo")
@smartsuper.after # Explicit AFTER takes precedence
def bar(self):
print("Derived.bar")
d = Derived()
d.foo() # Base.foo → Derived.foo
d.bar() # Derived.bar → Base.bar
# Note: Magic methods (__init__, __str__, etc.) are NOT auto-decorated
# You can still explicitly decorate them if needed
SmartOptions - Intelligent Option Merging
Merge incoming options with defaults, with automatic filtering:
from smartseeds import SmartOptions
# Basic merge: incoming overrides defaults
opts = SmartOptions(
incoming={'timeout': 10, 'retries': None},
defaults={'timeout': 5, 'retries': 3, 'debug': False}
)
print(opts.timeout) # 10 (from incoming)
print(opts.retries) # None (from incoming)
print(opts.debug) # False (from defaults)
# Ignore None values
opts = SmartOptions(
incoming={'timeout': None, 'retries': 5},
defaults={'timeout': 30, 'retries': 3},
ignore_none=True # Skip None from incoming
)
print(opts.timeout) # 30 (default kept, None ignored)
print(opts.retries) # 5 (from incoming)
# Ignore empty collections
opts = SmartOptions(
incoming={'tags': [], 'name': ''},
defaults={'tags': ['prod'], 'name': 'default'},
ignore_empty=True # Skip empty strings/lists/dicts
)
print(opts.tags) # ['prod'] (default kept)
print(opts.name) # 'default' (default kept)
# Convert back to dict
config_dict = opts.as_dict()
Use in smart* Ecosystem
SmartSeeds is designed to be used by other smart* tools:
# In smartswitch, smartasync, etc.
from smartseeds import extract_kwargs
class Switcher:
@extract_kwargs(logging=True, async_mode=True)
def __init__(self, name=None, logging_kwargs=None, async_kwargs=None, **kwargs):
# Plugin configuration extracted automatically
if logging_kwargs:
self.plug('logging', **logging_kwargs)
if async_kwargs:
self.plug('async', **async_kwargs)
Why extract_kwargs?
Traditional approaches to nested configuration have problems:
❌ Explicit parameters (verbose)
def connect(host, port, logging_level=None, logging_format=None, logging_file=None):
logger = Logger(level=logging_level, format=logging_format, file=logging_file)
❌ Catch-all kwargs (unclear)
def connect(host, port, **kwargs):
# What kwargs are valid? Users don't know!
logger = Logger(**kwargs)
✅ extract_kwargs (clear + flexible)
@extract_kwargs(logging=True)
def connect(host, port, logging_kwargs=None):
if logging_kwargs:
logger = Logger(**logging_kwargs)
# All these work and are clear:
connect('localhost', 8000, logging_level='INFO')
connect('localhost', 8000, logging={'level': 'INFO'})
connect('localhost', 8000, logging=True)
Documentation
Full documentation available at: https://smartseeds.readthedocs.io
Part of the Smart* Family
SmartSeeds is part of the Genropy smart* toolkit:
- smartswitch - Rule-based function dispatch
- smartasync - Async utilities
- smartpub - Pub/sub messaging
License
MIT License - see LICENSE file for details.
Contributing
Contributions welcome! Please read our Contributing Guidelines first.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smartseeds-0.2.1.tar.gz.
File metadata
- Download URL: smartseeds-0.2.1.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82c297ee83ab84047dbcc4768ec4bd099bc3a3e10a58d728de8ced455db812eb
|
|
| MD5 |
c821471385dcb13a8b945d3972967514
|
|
| BLAKE2b-256 |
7ba5439ffdc54afbd9b45cc80b05fd14096f02da225177aa0a13c9c6ee4fb3ad
|
Provenance
The following attestation bundles were made for smartseeds-0.2.1.tar.gz:
Publisher:
publish.yml on genropy/smartseeds
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smartseeds-0.2.1.tar.gz -
Subject digest:
82c297ee83ab84047dbcc4768ec4bd099bc3a3e10a58d728de8ced455db812eb - Sigstore transparency entry: 707579649
- Sigstore integration time:
-
Permalink:
genropy/smartseeds@b56c494ea89911ee0c403967ec184f7662058f8e -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/genropy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b56c494ea89911ee0c403967ec184f7662058f8e -
Trigger Event:
push
-
Statement type:
File details
Details for the file smartseeds-0.2.1-py3-none-any.whl.
File metadata
- Download URL: smartseeds-0.2.1-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34ffaf6a7427d24fa0622f12942af6575b2879fe1aa0602ad6becc9595717c43
|
|
| MD5 |
12ab47421faa00290a8f384769c5357c
|
|
| BLAKE2b-256 |
bb6501f1e2bd6d14a98199136cfc56d736adbe3fd7aafa0f41cf484d7ece5413
|
Provenance
The following attestation bundles were made for smartseeds-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on genropy/smartseeds
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smartseeds-0.2.1-py3-none-any.whl -
Subject digest:
34ffaf6a7427d24fa0622f12942af6575b2879fe1aa0602ad6becc9595717c43 - Sigstore transparency entry: 707579653
- Sigstore integration time:
-
Permalink:
genropy/smartseeds@b56c494ea89911ee0c403967ec184f7662058f8e -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/genropy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b56c494ea89911ee0c403967ec184f7662058f8e -
Trigger Event:
push
-
Statement type: