Bits & Flames bitsandflames/fyron

Core I/O

fyron.core is the data-boundary layer: environment variables, local tables, JSON sidecars, file summaries, Teable review tables, finished research cohort write-back, and optional S3 object storage. Use it whenever data enters or leaves a reproducible clinical workflow.

When To Use Core Helpers

  • load credentials from .env before creating FHIR, DICOM, Teable, or S3 clients,
  • write analysis-ready tables with explicit file boundaries,
  • store JSON sidecars such as mappings, manifests, and validation reports,
  • read manually curated Teable tables into Python,
  • write locked research cohorts back to Teable for review and audit,
  • read/write cohort tables from S3 or S3-compatible storage.

Imports

python
from fyron import (
    load_env,
    read_table,
    write_table,
    read_json,
    write_json,
    summarize_table,
    describe_file,
)
from fyron.core import DataIO, TeableClient
from fyron.core.s3 import S3Storage

Environment Loading

python
from fyron import load_env

load_env(".env", override=False)
FunctionRequiredOptionalReturns
load_env(path=None, ...)noneoverride=False, warn_if_missing=Trueloaded path or None

Typical variables include FHIR_BASE_URL, DICOM_WEB_URL, TEABLE_TOKEN, S3_BUCKET, and AWS credentials.

Local Table I/O

Use read_table and write_table when a pipeline may receive CSV, TSV, Excel, JSON, or JSONL files.

python
from fyron import read_table, write_table

cohort = read_table("data/reviewed_cohort.csv")
write_table(cohort, "outputs/analysis_ready/cohort.jsonl")
FunctionRequiredOptionalReturns
read_table(path, ...)pathfile_format, pandas kwargsDataFrame
write_table(df, path, ...)DataFrame, pathfile_format, create_parent=True, index=False, pandas kwargsoutput Path
read_csv(path, **kwargs)pathpandas kwargsDataFrame
write_csv(df, path, **kwargs)DataFrame, pathpandas kwargsNone
read_excel(path, **kwargs)pathpandas kwargsDataFrame
write_excel(df, path, **kwargs)DataFrame, pathpandas kwargsNone

Supported table formats: .csv, .tsv, .xlsx, .xls, .json, .jsonl.

JSON Sidecars

python
from fyron import read_json, write_json

mapping = {"code_col": "loinc", "value_col": "value"}
write_json(mapping, "outputs/fhir/observation_mapping.json")
loaded = read_json("outputs/fhir/observation_mapping.json")
FunctionRequiredOptionalReturns
read_json(path, **kwargs)pathJSON load kwargsPython object
write_json(payload, path, ...)payload, pathindent=2, create_parent=Trueoutput Path

File And Table Summaries

python
from fyron import describe_file, summarize_table

summary = summarize_table(cohort, name="analysis_cohort")
file_info = describe_file("outputs/analysis_ready/cohort.csv")
FunctionRequiredOptionalReturns
ensure_parent_dir(path)pathnonePath
summarize_table(df, ...)DataFramenamedict
describe_file(path)pathnonedict

summarize_table reports row count, column count, column names, missing cells, duplicate rows, and memory use.

DataIO Object

DataIO exposes the same helpers as static methods for projects that prefer passing an I/O object.

python
from fyron.core import DataIO

io = DataIO()
df = io.read_table("features.csv")
io.write_json({"rows": len(df)}, "outputs/features.summary.json")

Teable Review Tables And Research Cohorts

Use Teable when curated review tables or locked cohorts need to move between Python and a collaborative workspace.

python
from fyron.core import TeableClient

teable = TeableClient(base_url="https://app.teable.ai", token="YOUR_TOKEN")
reviewed = teable.read_cohort(
    "tbl_reviewed",
    id_col="patient_id",
    required_columns=["patient_id", "outcome", "follow_up_days"],
)

Write a finished research cohort:

python
result = teable.write_research_cohort(
    "tbl_final_cohort",
    cohort,
    mode="append",
    cohort_name="BOA survival cohort",
    version="v1.0",
    id_col="patient_id",
    metadata={"analysis": "body composition survival model"},
)
MethodRequiredOptionalReturns
read_table(table_id, ...)table IDview, projection, max recordsDataFrame
read_cohort(table_id, ...)table IDID column, required columns, view, max recordsvalidated DataFrame
write_dataframe(table_id, df, ...)table ID, DataFrametypecast, chunksrecord IDs
overwrite_table(table_id, df, ...)table ID, DataFramebatch sizes, typecastrecord IDs
write_research_cohort(table_id, df, ...)table ID, DataFramemode, name, version, metadata, ID columnaudit dict
create_research_cohort_table(base_id, name, ...)base ID, nameDataFrame, fields, metadatatable dict
summarize_teable_table(table_id, ...)table IDview, projection, max recordssummary dict

S3 And S3-Compatible Storage

Install the optional extra:

bash
uv add "fyron[s3]"
python
from fyron.core.s3 import S3Storage

s3 = S3Storage(
    bucket="clinical-research",
    prefix="projects/boa-survival",
    endpoint_url=None,  # set for MinIO or other S3-compatible systems
)

s3.write_table("cohorts/final.csv", cohort)
cohort_from_s3 = s3.read_table("cohorts/final.csv")
s3.write_json("manifests/run.json", {"rows": len(cohort)})
MethodRequiredOptionalReturns
S3Storage(...)bucket or S3_BUCKETprefix, endpoint, region, credentialsstorage client
exists(key)keynonebool
list(prefix=None, ...)nonesuffix, max keysobject list
read_bytes(key) / write_bytes(key, data)keycontent typebytes / S3 URI
read_json(key) / write_json(key, payload)keyindentobject / S3 URI
read_table(key, ...) / write_table(key, df, ...)keyformat, pandas kwargsDataFrame / S3 URI
download_file(key, local_path)key, local pathparent creationlocal Path
upload_file(local_path, key=None)local pathkey, content typeS3 URI

Convenience functions:

python
from fyron.core.s3 import read_s3_table, write_s3_table

df = read_s3_table("s3://clinical-research/projects/cohort.csv")
write_s3_table(df, "s3://clinical-research/projects/cohort_clean.csv")

Practical Tips

  • Keep .env files out of git and call load_env() at notebook or CLI startup.
  • Use write_table(..., index=False) unless the index is clinically meaningful.
  • Store JSON mappings and validation reports beside generated FHIR bundles.
  • Use read_cohort for Teable review tables so missing columns and duplicate IDs fail early.
  • Use S3 prefixes as project boundaries, e.g. projects/boa-survival/v1.
  • Parquet is intentionally not part of Core I/O v1.