Skip to main content

How to Share Information | Process

When you need to share environment variables or settings between pipelines, databases such as SQLite or configuration files offer a practical, efficient solution. This approach is ideal for storing temporary or small amounts of information while keeping things simple and scalable.

Sharing data through a database​

Lightweight databases (SQLite) are recommended for temporary settings or data shared between steps, reducing dependence on variables.

Using SQLite​

  • SQLite offers flexibility, allowing users to add, modify or remove parameters without directly changing pipelines; centralization, making shared data accessible to multiple pipelines; and efficiency, replacing excessive environment variable usage to avoid errors and size limitations.
import sqlite3

def save_parameters():
conn = sqlite3.connect('shared_parameters.db')
cursor = conn.cursor()

cursor.execute('''
CREATE TABLE IF NOT EXISTS parameters (
key TEXT PRIMARY KEY,
value TEXT
)
''')

parameters = [
("api_key", "123abc"),
("batch_size", "100"),
("threshold", "0.8")
]
cursor.executemany('INSERT OR REPLACE INTO parameters (key, value) VALUES (?, ?)', parameters)
conn.commit()
conn.close()

save_parameters()
print("Parâmetros salvos com sucesso!")

Sharing settings through files​

For simple data persistence, a configuration file (such as JSON or YAML) can also be used. It is especially useful for values that change infrequently, such as credentials or default limits.

Using a JSON file​

  • JSON configuration files are simple, flexible and portable, allowing environment variables to be stored in an organized, readable way.
  • They are ideal for static settings, requiring no additional infrastructure and making versioning and sharing across systems easy.
import json

# Salvando parâmetros em um arquivo JSON
with open('parameters.json', 'w') as f:
json.dump({"api_key": "123abc", "batch_size": 100, "threshold": 0.8}, f)

# Carregando parâmetros do arquivo JSON
with open('parameters.json', 'r') as f:
parameters = json.load(f)

print("Parâmetros carregados:", parameters)

When should you use SQLite or configuration files?​

SQLite is ideal when multiple pipelines need shared data and parameters may change dynamically. Configuration files are better suited to static or simple settings that are not updated frequently.