ploomber / ploomber

The fastest ⚡️ way to build data pipelines. Develop iteratively, deploy anywhere. ☁️

Home Page:https://docs.ploomber.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to access params in scripts ? Support global params ?

eromoe opened this issue · comments

commented

I have same variables need use in multiple tasks/scripts .

My code :

# %% tags=["parameters"]
upstream = ['get']
product = None
params = []

# %%

output_path = product['data']
basefreq = params['basefreq']
print(basefreq)

got error :

Exception encountered at "In [4]":
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_43496\3265420907.py in <cell line: 1>()
----> 1 basefreq = params['basefreq']
      2 print(basefreq)
      3
      4 import sys
      5 sys.path.insert(0, 'E:\Workspace\github_me\quant_pipeline_demo\scripts')

TypeError: list indices must be integers or slices, not str

the parameters are injected as new variables in your scripts/notebooks, so assuming that you have something like this in your pipeline.yaml:

tasks:
    - source: script.py
      params:
          basefreq: some_value

then, in your script, you can access it like this:

# %% tags=["parameters"]
upstream = ['get']
product = None

# ploomber will inject basefreq here

# %%

output_path = product['data']
print(basefreq)
commented

@edublancas OOOH, I miss it , directly ! That's cool :)