Skip to main content

Essential utilities that grow smart solutions - shared utilities for the smart* ecosystem

Project description

SmartSeeds Logo

SmartSeeds 🌱

Essential utilities that grow smart solutions

SmartSeeds is a lightweight, zero-dependency Python library providing core utilities for the smart* ecosystem (smartroute, smartasync, etc.). Think of it as the seeds from which smart solutions grow.

PyPI version Tests codecov Documentation LLM Docs Python 3.10+ License: MIT Code style: black

Features

  • extract_kwargs: Decorator for extracting and grouping keyword arguments by prefix
  • SmartOptions: Intelligent options merging with filtering and defaults
  • safe_is_instance: Check instance types by class name without importing
  • ascii_table: Generate beautiful ASCII and Markdown tables with formatting, hierarchies, and type support
  • 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
)

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()

safe_is_instance - Type Checking Without Imports

Check if an object is an instance of a class using only the class name string, without importing the class. Perfect for avoiding circular imports:

from smartseeds import safe_is_instance

# Check instance without importing the class
class MyModel:
    pass

obj = MyModel()

# Traditional isinstance requires import
# from mypackage.models import BaseModel
# isinstance(obj, BaseModel)  # Circular import risk!

# safe_is_instance uses string class name - no import needed
assert safe_is_instance(obj, f"{MyModel.__module__}.{MyModel.__qualname__}")

# Works with inheritance
class Base:
    pass

class Derived(Base):
    pass

obj = Derived()
assert safe_is_instance(obj, f"{Derived.__module__}.{Derived.__qualname__}")
assert safe_is_instance(obj, f"{Base.__module__}.{Base.__qualname__}")  # Parent class!

# Works with builtins
assert safe_is_instance(42, "builtins.int")
assert safe_is_instance("hello", "builtins.str")

ascii_table - Beautiful Tables with Zero Dependencies

Generate formatted ASCII and Markdown tables with type-aware formatting, hierarchies, and text wrapping:

from smartseeds import render_ascii_table, render_markdown_table

# Create a formatted table
data = {
    "title": "Sales Report",
    "headers": [
        {"name": "Region", "type": "str", "align": "left"},
        {"name": "Revenue", "type": "float", "format": ".2f", "align": "right"},
        {"name": "Active", "type": "bool", "align": "center"},
        {"name": "Updated", "type": "date", "format": "dd/mm/yyyy"}
    ],
    "rows": [
        ["North", 125430.50, "yes", "2025-11-24"],
        ["South", 98765.25, "no", "2025-11-23"]
    ]
}

print(render_ascii_table(data))
# Output:
#                     Sales Report
# +--------+-----------+--------+------------+
# | Region |   Revenue | Active | Updated    |
# +--------+-----------+--------+------------+
# | North  | 125430.50 |  true  | 24/11/2025 |
# +--------+-----------+--------+------------+
# | South  |  98765.25 |  false | 23/11/2025 |
# +--------+-----------+--------+------------+

# Export to Markdown
print(render_markdown_table(data))
# Output:
# | Region | Revenue | Active | Updated |
# | --- | --- | --- | --- |
# | North | 125430.50 | true | 24/11/2025 |
# | South | 98765.25 | false | 23/11/2025 |

Features:

  • Type formatting: str, int, float, bool, date, datetime with custom formats
  • Hierarchical data: Automatic indentation for tree structures
  • Text wrapping: Handles long content with configurable max width
  • ANSI colors: Terminal colors don't affect layout
  • Markdown export: Generate documentation-ready tables

Use in smart* Ecosystem

SmartSeeds is designed to be used by other smart* tools:

# In smartroute, smartasync, etc.
from smartseeds import extract_kwargs

class Service:
    @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:

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

smartseeds-0.4.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

smartseeds-0.4.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file smartseeds-0.4.0.tar.gz.

File metadata

  • Download URL: smartseeds-0.4.0.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for smartseeds-0.4.0.tar.gz
Algorithm Hash digest
SHA256 1aa0676eeaa129b5ca03e3108a0541ed4d88dd523b9435c41fce8422a3fc25f5
MD5 2d5e454db6d1f844992834c742b4382b
BLAKE2b-256 36e1b2c73039c57acdc9c1490fb53a33133075f1138ee617e4ce1a86b93aa5ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for smartseeds-0.4.0.tar.gz:

Publisher: publish.yml on genropy/smartseeds

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file smartseeds-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: smartseeds-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for smartseeds-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36d50ff17421f92dfe3e66ae9b892447629e623e23ee6cce655c89c5843dc975
MD5 186f89ee90f69c4a27776f61c7d1f47c
BLAKE2b-256 61ebab057a0f9805e41d9a48ef5ab911611cee3d9188252ff0fcf382bc62e804

See more details on using hashes here.

Provenance

The following attestation bundles were made for smartseeds-0.4.0-py3-none-any.whl:

Publisher: publish.yml on genropy/smartseeds

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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