gn() - Code Generation

  • Silent Generation – Translates prompts into valid Python code, returning a custom AIResult string wrapper that overrides __repr__ to suppress automatic prints in Jupyter notebooks or Python REPLs.
  • File Auto-Detection – Scans local files (CSV, Excel, JSON) using magika and pandas to extract column schemas and preview rows automatically into the AI context.
Signature
ranno.gn(prompt: str, data: Optional[str] = None, config: Optional[dict] = None) -> AIResult
ParameterTypeRequiredDescription
promptstrYesThe natural language instruction.
datastrNoFile path to target CSV, Excel, or JSON dataset. Reads columns and preview rows automatically.
configdictNoOptional Gemini request configurations.
ReturnsDescription
AIResultSubclass of string containing the generated code block.
gn() - API
from ranno import gn

# Generate code silently code = gn("Create a list of 10 dinosaurs") print(code)
# Generate code with dataset context dataset_code = gn("Find the average salary", data="employees.csv") print(dataset_code)