Skip to content

API Reference parrot.tools.dataset_manager.sources.query_slug

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.dataset_manager.sources.query_slug

View source

QuerySlugSource and MultiQuerySlugSource implementations.

Wraps the QuerySource (QS) and MultiQS patterns as proper DataSource implementations, replacing the inline _call_qs() / _call_multiquery() logic that previously lived in DatasetManager.

Alias DataSource

Re-exported from parrot.tools.dataset_manager.sources.base.DataSource.

Attribute MultiQS

Class MultiQuerySlugSource

DataSource backed by multiple QuerySource slugs whose results are merged.

Fetches each slug independently and concatenates the resulting DataFrames. Schema prefetch performs a 1-row fetch per slug and merges the schema dicts.

Parameter Type Default Description
slugs List[str] List of QuerySource slug identifiers to merge.

Attributes:

Attribute Type Description
has_builtin_cache bool
cache_key str Stable Redis cache key for this multi-slug source.

Method MultiQuerySlugSource.describe

Human-readable description for the LLM.

describe() -> str

Returns: str — Description string listing all QuerySource slugs.

Method MultiQuerySlugSource.prefetch_schema

Fetch one row per slug and merge the inferred schemas.

Returns an empty dict silently for any slug that fails.

prefetch_schema() -> Dict[str, str]

Returns: Dict[str, str] — Merged dictionary mapping column names to their dtype strings.

Method MultiQuerySlugSource.fetch

Execute all slugs and concatenate the resulting DataFrames.

Pops force_refresh from params and, when True, injects refresh=True into each QS conditions dict so that QS bypasses its own cache for every slug.

fetch(**params) -> pd.DataFrame

Parameter Type Default Description
**params {} Passed as the conditions dict to each QS call. force_refresh (bool): If True, tell QS to skip its cache.

Returns: pd.DataFrame — Concatenated DataFrame from all slugs.

Raises:

  • RuntimeError — If no slug returns a valid DataFrame.

Alias PermissionContext

Re-exported from parrot.auth.permission.PermissionContext.

Attribute QS

Class QuerySlugSource

DataSource backed by a single QuerySource slug.

Wraps QS(slug=..., conditions=params) and exposes it as a lazy DataSource. Schema prefetch performs a 1-row query to infer column names and dtypes.

Parameter Type Default Description
slug str The QuerySource slug identifier.
prefetch_schema_enabled bool True When True, prefetch_schema() will call QS with querylimit=1 to infer the schema. Defaults to True.
permanent_filter Optional[Dict[str, Any]] None Optional dict of conditions that are always merged into every fetch() call. Permanent filter keys take precedence over runtime params (cannot be overridden by the caller).
tenant Optional[str] None Optional QuerySource tenant selector, forwarded to QS/MultiQS so the slug is resolved against the right tenant schema instead of silently falling back to public.queries (spec AC4).
is_multiquery bool False When True, fetch() dispatches MultiQS instead of QS and normalises its DataFrame | dict[str, DataFrame] output to a single frame (spec S4).
multi_output Optional[str] None When is_multiquery is True, the name of the output frame to select from a MultiQS dict result. Falls back to "result", then to the single frame when there is only one.
principal Optional['QSPrincipal'] None Optional FEAT-150 QSPrincipal forwarded to QS/MultiQS for in-process slug PBAC enforcement. Never part of cache_key.
definition Optional['LoadedDefinition'] None Optional pre-resolved QuerySource LoadedDefinition, forwarded to QS/MultiQS.

Attributes:

Attribute Type Description
has_builtin_cache bool
cache_key str Stable Redis cache key for this source.

Method QuerySlugSource.describe

Human-readable description for the LLM.

describe() -> str

Returns: str — Description string identifying the QuerySource slug.

Method QuerySlugSource.prefetch_schema

Fetch one row to infer column names and dtypes.

Calls QS with querylimit=1. Returns an empty dict silently if the call fails or schema prefetch is disabled.

prefetch_schema() -> Dict[str, str]

Returns: Dict[str, str] — Dictionary mapping column names to their dtype strings.

Method QuerySlugSource.fetch

Execute the QuerySource (or MultiQS) and return a DataFrame.

Pops force_refresh from params (not a QS condition) and, when True, injects refresh=True into the QS conditions so that QS bypasses its own cache. When is_multiquery is True, dispatches MultiQS instead and normalises its output to a single frame (S4). The underlying QS/MultiQS instance is always closed, even on failure (S8).

fetch(**params) -> pd.DataFrame

Parameter Type Default Description
**params {} Passed as the conditions dict to QS/MultiQS. force_refresh (bool): If True, tell QS to skip its cache.

Returns: pd.DataFrame — DataFrame with the query results.

Raises:

  • RuntimeError — If QS/MultiQS fails or returns no DataFrame.

Alias lazy_import

Re-exported from parrot._imports.lazy_import.

Function to_qs_principal

Map a parrot PermissionContext to a QuerySource QSPrincipal (FEAT-150).

Mirrors parrot.auth.permission.to_eval_context: identity from the session, groups/programs/ superuser from session.metadata. tenant_id is informational only — it never selects a QuerySource store (the descriptor's tenant does, spec AC4).

to_qs_principal(pctx: 'PermissionContext', *, channel: str = 'ui_surfaces') -> 'QSPrincipal'

Parameter Type Default Description
pctx 'PermissionContext' The acting user's permission context (the surface OWNER on ui_surfaces lanes).
channel str 'ui_surfaces' Log-only channel label carried by the principal.

Returns: 'QSPrincipal' — A frozen QSPrincipal.

Raises:

  • ImportError — When querysource is not installed.
  • ValueError — When the context carries a blank user id (QSPrincipal.post_init).

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally