or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

core-table.mdfactory-functions.mdindex.mdoutput-formats.mdstyling.md

output-formats.mddocs/

0

# Output Formats

1

2

Comprehensive export and output formatting capabilities for generating tables in multiple formats. Supports ASCII text, HTML, CSV, JSON, LaTeX, MediaWiki markup, and pagination for various use cases.

3

4

## Capabilities

5

6

### ASCII Text Output

7

8

Generate formatted ASCII text representation with extensive customization options.

9

10

```python { .api }

11

def get_string(self, **kwargs) -> str:

12

"""

13

Get ASCII text representation of the table.

14

15

Parameters:

16

- start: First row to include (0-based)

17

- end: Last row to include (0-based)

18

- fields: List of field names to include

19

- title: Override table title

20

- sortby: Field name to sort by

21

- reversesort: Reverse sort order

22

- print_empty: Print table even if no data rows

23

- hrules: Horizontal rule style override

24

- vrules: Vertical rule style override

25

- int_format: Format string for integers

26

- float_format: Format string for floats

27

- padding_width: Cell padding width

28

- left_padding_width: Left padding width

29

- right_padding_width: Right padding width

30

- vertical_char: Character for vertical lines

31

- horizontal_char: Character for horizontal lines

32

- junction_char: Character for line junctions

33

- header_style: Header text style

34

- align: Alignment override

35

- valign: Vertical alignment override

36

- max_width: Maximum column width

37

- min_width: Minimum column width

38

- max_table_width: Maximum total table width

39

- min_table_width: Minimum total table width

40

- oldsortslice: Use old sort/slice behavior

41

42

Returns:

43

Formatted ASCII table string

44

"""

45

46

def __str__(self) -> str:

47

"""String representation (calls get_string())."""

48

49

def __repr__(self) -> str:

50

"""String representation (calls get_string())."""

51

```

52

53

Usage examples:

54

55

```python

56

# Basic string output

57

table_str = table.get_string()

58

print(table_str)

59

60

# Output subset of rows and columns

61

subset = table.get_string(start=1, end=5, fields=["Name", "Age"])

62

63

# Sorted output

64

sorted_table = table.get_string(sortby="Age", reversesort=True)

65

66

# Custom formatting

67

formatted = table.get_string(

68

int_format="03d",

69

float_format=".2f",

70

padding_width=3

71

)

72

73

# Using string conversion

74

print(str(table))

75

```

76

77

### HTML Output

78

79

Generate HTML table markup with styling and formatting options.

80

81

```python { .api }

82

def get_html_string(self, **kwargs) -> str:

83

"""

84

Get HTML representation of the table.

85

86

Parameters:

87

- start: First row to include

88

- end: Last row to include

89

- fields: List of field names to include

90

- title: Override table title

91

- sortby: Field name to sort by

92

- reversesort: Reverse sort order

93

- print_empty: Print table even if no data rows

94

- escape: Escape HTML characters in data

95

- format: Apply CSS formatting

96

- table_id: HTML table id attribute

97

- border: Add border attribute

98

- hrules: Horizontal rule style

99

- vrules: Vertical rule style

100

101

Returns:

102

HTML table string

103

"""

104

105

def _repr_html_(self) -> str:

106

"""Jupyter notebook HTML representation."""

107

```

108

109

Usage examples:

110

111

```python

112

# Basic HTML output

113

html_table = table.get_html_string()

114

115

# HTML with custom formatting

116

html_formatted = table.get_html_string(

117

format=True,

118

table_id="data-table",

119

border=1

120

)

121

122

# HTML subset

123

html_subset = table.get_html_string(fields=["Name", "Score"])

124

```

125

126

### CSV Output

127

128

Export table data as comma-separated values with delimiter options.

129

130

```python { .api }

131

def get_csv_string(self, **kwargs) -> str:

132

"""

133

Get CSV representation of the table.

134

135

Parameters:

136

- start: First row to include

137

- end: Last row to include

138

- fields: List of field names to include

139

- sortby: Field name to sort by

140

- reversesort: Reverse sort order

141

- print_empty: Print table even if no data rows

142

- delimiter: Field delimiter character

143

- header: Include header row

144

145

Returns:

146

CSV formatted string

147

"""

148

```

149

150

Usage examples:

151

152

```python

153

# Standard CSV output

154

csv_data = table.get_csv_string()

155

156

# CSV with custom delimiter

157

tsv_data = table.get_csv_string(delimiter='\t')

158

159

# CSV without header

160

data_only = table.get_csv_string(header=False)

161

```

162

163

### JSON Output

164

165

Export table data as structured JSON with various formatting options.

166

167

```python { .api }

168

def get_json_string(self, **kwargs) -> str:

169

"""

170

Get JSON representation of the table.

171

172

Parameters:

173

- start: First row to include

174

- end: Last row to include

175

- fields: List of field names to include

176

- sortby: Field name to sort by

177

- reversesort: Reverse sort order

178

- print_empty: Print table even if no data rows

179

- indent: JSON indentation level

180

- separators: JSON separators tuple

181

182

Returns:

183

JSON formatted string

184

"""

185

```

186

187

Usage examples:

188

189

```python

190

# Compact JSON

191

json_compact = table.get_json_string()

192

193

# Pretty-printed JSON

194

json_pretty = table.get_json_string(indent=2)

195

196

# JSON subset

197

json_subset = table.get_json_string(fields=["Name", "Score"])

198

```

199

200

### LaTeX Output

201

202

Generate LaTeX table markup for document integration.

203

204

```python { .api }

205

def get_latex_string(self, **kwargs) -> str:

206

"""

207

Get LaTeX representation of the table.

208

209

Parameters:

210

- start: First row to include

211

- end: Last row to include

212

- fields: List of field names to include

213

- title: Override table title

214

- sortby: Field name to sort by

215

- reversesort: Reverse sort order

216

- print_empty: Print table even if no data rows

217

218

Returns:

219

LaTeX table string

220

"""

221

```

222

223

Usage example:

224

225

```python

226

# LaTeX table

227

latex_table = table.get_latex_string()

228

```

229

230

### MediaWiki Output

231

232

Generate MediaWiki table markup for wiki integration.

233

234

```python { .api }

235

def get_mediawiki_string(self, **kwargs) -> str:

236

"""

237

Get MediaWiki representation of the table.

238

239

Parameters:

240

- start: First row to include

241

- end: Last row to include

242

- fields: List of field names to include

243

- title: Override table title

244

- sortby: Field name to sort by

245

- reversesort: Reverse sort order

246

- print_empty: Print table even if no data rows

247

248

Returns:

249

MediaWiki table markup string

250

"""

251

```

252

253

Usage example:

254

255

```python

256

# MediaWiki table

257

wiki_table = table.get_mediawiki_string()

258

```

259

260

### Generic Format Output

261

262

Unified interface for multiple output formats.

263

264

```python { .api }

265

def get_formatted_string(self, out_format: str, **kwargs) -> str:

266

"""

267

Get formatted output in specified format.

268

269

Parameters:

270

- out_format: Output format ("text", "html", "csv", "json", "latex", "mediawiki")

271

- **kwargs: Format-specific options

272

273

Returns:

274

Formatted string in requested format

275

"""

276

```

277

278

Usage examples:

279

280

```python

281

# Get HTML via generic interface

282

html_output = table.get_formatted_string("html", format=True)

283

284

# Get CSV via generic interface

285

csv_output = table.get_formatted_string("csv", delimiter=';')

286

287

# Dynamic format selection

288

format_type = "json"

289

output = table.get_formatted_string(format_type, indent=2)

290

```

291

292

### Pagination

293

294

Break large tables into pages for better readability.

295

296

```python { .api }

297

def paginate(self, page_length: int = 58, line_break: str = '\f', **kwargs) -> str:

298

"""

299

Get paginated string output.

300

301

Parameters:

302

- page_length: Number of lines per page

303

- line_break: Character sequence for page breaks

304

- **kwargs: Options passed to get_string()

305

306

Returns:

307

Paginated table string with page breaks

308

"""

309

```

310

311

Usage examples:

312

313

```python

314

# Standard pagination

315

paginated = table.paginate()

316

317

# Custom page length

318

paginated_short = table.paginate(page_length=30)

319

320

# Custom page break character

321

paginated_custom = table.paginate(line_break='\n--- PAGE BREAK ---\n')

322

```