API Documentation for flyfield
This documentation provides a detailed reference to the flyfield Python API for programmatically working with PDF forms that use white box placeholders.
Overview
The flyfield API automates workflows including:
- Extracting white box placeholders from vector PDFs
- Filtering, deduplicating, and grouping detected regions into logical fields
- Generating interactive AcroForm fields in PDFs programmatically
- Filling form fields with data from CSV files
- Capturing data back from filled PDFs into CSV
The API is modular and can be imported into Python projects, offering programmable control beyond the CLI.
Key Modules and Functions
1. Extraction (extract.py
)
extract_boxes(pdf_path: str) -> List[dict]
Extracts all white boxes from a PDF that matchconfig.TARGET_COLOUR
(pure white by default).- Converts coordinates to the standard bottom-left PDF system.
- Returns a list of box dictionaries with metadata such as
page_num
,bbox
,chars
, andfield_type
.
filter_boxes(page: fitz.Page, boxes: List[dict]) -> List[dict]
Filters raw boxes by:- Size (
MIN_BOX_HEIGHT
,MAX_BOX_HEIGHT
) - Allowed text (
utils.allowed_text
) - Retains only candidate placeholders.
- Size (
remove_duplicates(boxes: List[dict]) -> List[dict]
Removes duplicates based on rounded coordinates on each page.sort_boxes(boxes: List[dict], decimal_places: int=0) -> List[dict]
Sorts results top-to-bottom, then left-to-right.-
process_boxes(pdf_path: str, csv_path: str) -> Dict[int, List[dict]]
Full extraction pipeline: -
Extract → Filter → Deduplicate → Sort
- Compute layout fields (
calculate_layout_fields
) - Assign numeric block types (
assign_numeric_blocks
) - Save annotated results to CSV
Returns a dictionary keyed by
page_num
.
2. Layout (layout.py
)
calculate_layout_fields(boxes: List[dict]) -> Dict[int, List[dict]]
Annotates box rows with:- IDs, line numbers, block grouping
- Block length/width
- Concatenated
block_fill
text or formatted money values
assign_numeric_blocks(page_dict: Dict[int, List[dict]]) -> Dict[int, List[dict]]
Merges sequential numeric blocks (e.g.### ### ##
patterns) into currency fields.- Assigns
"Currency"
or"CurrencyDecimal"
where applicable.
- Assigns
3. CSV I/O (io_utils.py
)
load_boxes_from_csv(csv_path: str) -> Dict[int, List[dict]]
Reads CSV data into a page dictionary for further processing.write_csv(data, csv_path: str) -> None
Writes box/page data back to CSV in canonical format.- Ensures only one
fill
column is stored (block_fill
or fallbackfill
).
- Ensures only one
read_csv_rows(filename: str) -> List[dict]
Reads CSV into dictionaries, parsing numeric fills withparse_money_space
orparse_implied_decimal
.save_pdf_form_data_to_csv(pdf_path: str, csv_path: str, boxes: dict=None) -> None
Captures filled AcroForm values from a PDF and writes them to CSV.- Applies
NUMERIC_FIELD_TYPES
parsing rules. - Uppercases strings where applicable.
- Applies
4. Markup and Field Scripts (markup_and_fields.py
)
markup_pdf(pdf_path: str, page_dict: Dict[int,List[dict]], output_pdf: str, mark_color=(0,0,1)) -> None
Creates a debug PDF marking detected fields with circles and rotated field codes.generate_form_fields_script(csv_path: str, input_pdf: str, output_pdf: str, script_path: str) -> str
Generates a standalone Python script that adds AcroForm fields to a given PDF, based on detected CSV data.run_standalone_script(script_path: str) -> None
Executes the generated script in a subprocess to apply fields.run_fill_pdf_fields(csv_path: str, output_pdf: str, template_pdf: str, generator_script: str, boxes: dict=None) -> None
Generates and runs a filler script that populates an interactive PDF with values from a CSV.- Supports monetary formatting via
format_money_space
. - Supports normalization of Currency/CurrencyDecimal values by stripping non-digits.
- Supports monetary formatting via
5. Utilities (utils.py
)
add_suffix_to_filename(filename: str, suffix: str) -> str
Adds a suffix before the file extension.colour_match(color: Tuple, target_color=(1,1,1), tol=1e-3) -> bool
Compares normalized RGB colors with tolerance.int_to_rgb(color_int: int) -> Tuple[float,float,float]
Converts an integer 0xRRGGBB color to normalized floats.clean_fill_string(line_text: str) -> str
Removes single spaces but preserves aligned spacing.allowed_text(text: str, field_type: Optional[str]) -> Tuple[bool, Optional[str]]
Checks whether a string value inside a field is allowed (filters out pre-printed text).format_money_space(amount: Union[float,int], decimal=True) -> str
Formats numeric values with:- Space as thousand separator
- Space as decimal marker (if decimal=True)
parse_money_space(s: str, decimal=True) -> Union[int,float]
Parses strings formatted above back into numbers.parse_implied_decimal(s: str) -> float
Parses numbers treating the last two digits as cents.parse_pages(pages_str: str) -> List[int]
Parses"1,3-5,7"
into[1,3,4,5,7]
.conditional_merge_list(main_list, ref_list, match_key, keys_to_merge)
Merges keys from a reference list into a main list when values ofmatch_key
match.
Field Data Structure
flyfield represents form fields as dictionaries (not classes):
Key | Type | Description |
---|---|---|
code |
str | Unique identifier (page-line-block naming scheme) |
page_num |
int | PDF page number (1-based) |
x0,y0,x1,y1 |
float | Bounding box coordinates (PDF bottom-left system) |
left, right |
float | Rounded left/right coordinates |
top, bottom |
float | Rounded positions |
line |
int | Line number on page |
block |
int | Block number within line |
block_length |
int | Number of boxes in block |
block_width |
float | Width of block in points |
field_type |
str | One of "Dollars" , "DollarCents" , "Currency" , etc. |
chars |
str | Non-black overlay text extracted |
fill |
str/num | Overlay text (user values, may be pre-filled) |
block_fill |
str/num | Aggregated/normalized block fill |
Example Usage
from flyfield.extract import process_boxes
from flyfield.io_utils import save_pdf_form_data_to_csv
from flyfield.markup_and_fields import run_fill_pdf_fields
from flyfield import config
# Process boxes and save CSV
page_dict = process_boxes("example.pdf", "example.csv")
# Generate a markup PDF
from flyfield.markup_and_fields import markup_pdf
markup_pdf("example.pdf", page_dict, "example-markup.pdf")
# Fill fields with values from another CSV
run_fill_pdf_fields("example.csv",
"example-filled.pdf",
"example-fields.pdf",
"example-filler.py",
page_dict)
# Capture back to CSV after filling
save_pdf_form_data_to_csv("example-filled.pdf", "example-capture.csv", page_dict)
Info
- flyfield depends on PyMuPDF (
fitz
) for box extraction and markup, and PyPDFForm for form field creation and filling. - Monetary/Currency parsing is opinionated.
- All generated scripts (
-field-generator.py
,-filler.py
) are standalone and reusable in case of workflow adjustments. - Debug logging (
--debug
) outputs stepwise CSVs for troubleshooting.
Further Resources
- Configuration Reference — adjustable thresholds and suffixes
- Developer Guide — core architecture and extension points
- Worked Example — end-to-end workflow with CSV integration
Automatic documentation from sources by mkdocstrings.
Core Modules
flyfield.extract
Extraction functions for PDF processing.
Provides methods to extract PDF box data and text.
extract_boxes(pdf_path)
Extract filled rectangles (boxes) from a PDF matching a target color.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pdf_path
|
str
|
Path to the input PDF file. |
required |
Returns:
Type | Description |
---|---|
List[Dict]
|
list of dict: Each dict details box coordinates (PDF coordinates, origin bottom-left), |
List[Dict]
|
page number, and other metadata for detected boxes. |
Notes
Converts PyMuPDF coordinates (origin top-left) to PDF standard bottom-left origin. Only boxes filled with the target color are extracted.
Source code in flyfield/extract.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
filter_boxes(page, boxes)
Filter a list of boxes on a PDF page based on height and allowed text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page
|
Page
|
PyMuPDF page object. |
required |
boxes
|
list of dict
|
List of box dictionaries to filter. |
required |
Returns:
Type | Description |
---|---|
List[Dict]
|
list of dict: Filtered boxes that meet size and allowed text criteria. |
Notes
Excludes boxes outside valid height ranges or with disallowed text.
Source code in flyfield/extract.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
remove_duplicates(boxes)
Remove duplicate boxes on the same page based on rounded coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
boxes
|
list of dict
|
List of box dictionaries. |
required |
Returns:
Type | Description |
---|---|
List[Dict]
|
list of dict: Boxes with duplicates removed. |
Source code in flyfield/extract.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
sort_boxes(boxes, decimal_places=0)
Sort boxes by page number, top-to-bottom (descending), then left-to-right.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
boxes
|
list of dict
|
List of boxes to sort. |
required |
decimal_places
|
int
|
Precision for vertical grouping (bottom coordinate rounding). |
0
|
Returns:
Type | Description |
---|---|
List[Dict]
|
list of dict: Sorted boxes. |
Source code in flyfield/extract.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
process_boxes(pdf_path, csv_path)
Full pipeline to extract, filter, deduplicate, sort, layout annotate, and save boxes from a PDF.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pdf_path
|
str
|
Path to input PDF file. |
required |
csv_path
|
str
|
Path to output CSV file for annotated box data. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
Dict[int, List[Dict]]
|
Dictionary keyed by page number containing processed boxes with layout metadata. |
Notes
- Extract filled white boxes matching TARGET_COLOUR.
- Filter boxes by valid height and allowed text content.
- Remove duplicate boxes by coordinate proximity.
- Sort boxes by page, vertical then horizontal order.
- Compute layout fields such as IDs, block grouping, lines.
- Assign numeric block field types using heuristics.
- Write the full annotated box data to CSV.
Source code in flyfield/extract.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
flyfield.io_utils
Utility functions for input/output operations.
Includes CSV reading/writing and data transformation helpers.
load_boxes_from_csv(csv_path)
Load boxes data from a CSV into a dictionary keyed by page number,
applying the specified types to each column in the CSV.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
csv_path
|
str
|
Path to the CSV file. |
required |
Returns:
Type | Description |
---|---|
dict[int, list[dict]]
|
dict[int, list[dict]]: Dictionary mapping page number (int) |
dict[int, list[dict]]
|
to a list of box dictionaries with appropriately typed values. |
Description
The CSV is expected to contain columns:
- page_num (int), id (int), x0 (float), y0 (float), x1 (float), y1 (float),
- left (float), top (float), right (float), bottom (float),
- height (float), width (float), pgap (float), gap (float),
- line (int), block (int), block_length (int), block_width (float),
- code (str), field_type (str), chars (str), fill (str)
Each value from the CSV is converted from string to the appropriate type. Empty or missing values are converted to None for numeric types and empty string for strings. Conversion errors are caught and logged; original strings are kept in those cases.
Source code in flyfield/io_utils.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
write_csv(boxes_or_page_dict, csv_path)
Write box data or page dictionary data to CSV file.
Saves only one 'fill' column: - Uses 'block_fill' if present, - Otherwise falls back to original 'fill'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
boxes_or_page_dict
|
list or dict
|
List of box dicts or dict keyed by page containing lists of boxes. |
required |
csv_path
|
str
|
Output CSV file path. |
required |
Source code in flyfield/io_utils.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
read_csv_rows(filename)
Read CSV rows into a list, converting typed fields and normalizing monetary fills.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
Path to CSV file. |
required |
Returns:
Type | Description |
---|---|
List[Dict[str, str]]
|
list of dict: Rows with typed values and block_fill normalized. |
Source code in flyfield/io_utils.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
save_pdf_form_data_to_csv(pdf_path, csv_path, boxes=None)
Extract PDF form data, convert string values to uppercase and numeric fields to raw numbers, then save as CSV.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pdf_path
|
str
|
Input PDF form file path. |
required |
csv_path
|
str
|
Output CSV path. |
required |
boxes
|
dict
|
Boxes metadata to enrich form data. |
None
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in flyfield/io_utils.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
flyfield.layout
Layout processing for PDFs.
Calculates layout box positions and formatting.
calculate_layout_fields(boxes)
Annotate boxes with layout metadata including IDs, lines, blocks,
block dimensions, monetary formatting, calculate block dimensions and concatenated fill text per block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
boxes
|
list
|
List of boxes sorted by page and vertical order. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
DefaultDict[int, List[Dict]]
|
Mapping page numbers to lists of annotated boxes. |
Notes
- Vertical tolerance epsilon controls grouping boxes into the same line.
- Blocks are formed by grouping boxes separated by large gaps (GAP_THRESHOLD).
- Monetary fills are formatted with spaces and decimals where appropriate.
Source code in flyfield/layout.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
assign_numeric_blocks(page_dict)
Merge and assign numeric block types based on heuristics of adjacency and length.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page_dict
|
dict
|
Keyed by page number with boxes list. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
DefaultDict[int, List[Dict]]
|
Updated page_dict with numeric block types assigned. |
Notes
Modifies the page_dict in place:
- Merges runs of adjacent blocks of length 3 if gaps between them are small.
- Optionally prepends certain preceding blocks to runs.
- Assigns field types "CurrencyDecimal" or "Currency" based on heuristics.
- Aggregates block lengths, widths, and concatenates fill strings.
Source code in flyfield/layout.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
flyfield.markup_and_fields
Functions for PDF markup and form field annotation.
markup_pdf(pdf_path, page_dict, output_pdf_path, mark_color=(0, 0, 1), mark_radius=1)
Mark PDF with circles and codes at block locations for debugging.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pdf_path
|
str
|
Input PDF file. |
required |
page_dict
|
dict
|
Pages and boxes with layout info. |
required |
output_pdf_path
|
str
|
Output marked PDF file path. |
required |
mark_color
|
tuple
|
RGB float tuple for marker color. |
(0, 0, 1)
|
mark_radius
|
int or float
|
Radius of circle marks. |
1
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in flyfield/markup_and_fields.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
adjust_form_boxes(row, width, block_length)
Adjust the position and width of form boxes depending on field type and block length.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row
|
dict
|
Box attributes. |
required |
width
|
float
|
Original block width. |
required |
block_length
|
int
|
Block length in contained boxes. |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
Tuple[float, float, List[str]]
|
(adjusted x, adjusted width, list of extra args) |
Source code in flyfield/markup_and_fields.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
generate_form_fields_script(csv_path, input_pdf, output_pdf_with_fields, script_path)
Generate a standalone Python script to create PDF form fields from CSV block data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
csv_path
|
str
|
CSV data path. |
required |
input_pdf
|
str
|
Input PDF to annotate. |
required |
output_pdf_with_fields
|
str
|
Output annotated PDF. |
required |
script_path
|
str
|
Output script file path. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Path to the generated script file. |
Source code in flyfield/markup_and_fields.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
run_standalone_script(script_path)
Execute a standalone script for PDF form field creation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
script_path
|
str
|
Path to the script to run. |
required |
Source code in flyfield/markup_and_fields.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
run_fill_pdf_fields(csv_path, output_pdf_path, template_pdf_path, generator_script_path, boxes=None)
Generates and runs a standalone Python script to fill PDF form fields using PyPDFForm,
based on data from a CSV file with 'code' and 'fill' columns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
csv_path
|
str
|
Path to the CSV input file. |
required |
output_pdf_path
|
str
|
Path where the filled PDF should be saved. |
required |
template_pdf_path
|
str
|
Path to the input (template) PDF file. |
required |
generator_script_path
|
str
|
Path where the generated fill script will be saved. |
required |
Source code in flyfield/markup_and_fields.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
flyfield.utils
General utility functions.
Helper functions for parsing, formatting, and validation.
add_suffix_to_filename(filename, suffix)
Add a suffix before the file extension in a filename.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
Original filename. |
required |
suffix
|
str
|
Suffix to add. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Filename with suffix added. |
Source code in flyfield/utils.py
14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
colour_match(color, target_color=TARGET_COLOUR, tol=0.001)
Check if a color matches a target within a tolerance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color
|
tuple
|
RGB color tuple. |
required |
target_color
|
tuple
|
RGB target color. |
COLOR_WHITE
|
tol
|
float
|
Allowed tolerance. |
0.001
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if colors match within tolerance. |
Note
If the input color has an alpha channel (RGBA), the alpha component is ignored.
Source code in flyfield/utils.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
int_to_rgb(color_int)
Convert a 24-bit integer color in 0xRRGGBB format to normalized RGB tuple of floats.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color_int
|
int
|
Integer encoding color as 0xRRGGBB. |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
Tuple[float, float, float]
|
Normalized (r, g, b) floats in range [0.0, 1.0]. |
Source code in flyfield/utils.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
clean_fill_string(line_text)
Clean a concatenated fill text string by removing single spaces while preserving double spaces as single spaces.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line_text
|
str
|
Raw line text. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Cleaned fill string. |
Source code in flyfield/utils.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
allowed_text(text, field_type=None)
Determine if text is allowed based on predefined rules and field type.
Helps to filter out pre-filled or invalid box contents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
Text extracted from a box. |
required |
field_type
|
str or None
|
Optional current field type guess to refine allowed patterns. |
None
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
Tuple[bool, Optional[str]]
|
(bool indicating if allowed, detected field type or None) |
Source code in flyfield/utils.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
format_money_space(amount, decimal=True)
Format a numeric amount to a string with space-separated thousands and optional decimal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
amount
|
float or int
|
Numeric amount to format. |
required |
decimal
|
bool
|
Whether to include two decimal places. |
True
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Formatted monetary string. |
Source code in flyfield/utils.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
parse_money_space(money_str, decimal=True)
Parse a monetary string with optional implied decimal space formatting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
money_str
|
str
|
Monetary string to parse (e.g., "12 345" means 123.45 if decimal is True). |
required |
decimal
|
bool
|
Whether the last two digits represent cents (default True). |
True
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Parsed monetary value as a float. |
Source code in flyfield/utils.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
parse_implied_decimal(s)
Parse a numeric string with implied decimal (last two digits as decimals).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Numeric string (e.g., "12345" -> 123.45). |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Parsed float value. |
Source code in flyfield/utils.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
version()
Return the current version string of the library/module.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Version string. |
Source code in flyfield/utils.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
parse_pages(pages_str)
Parse a string specifying pages or page ranges into a list of page integers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pages_str
|
str
|
Pages specified as a comma-separated list or ranges (e.g., "1,3-5"). |
required |
Returns:
Type | Description |
---|---|
List[int]
|
list[int]: List of individual page numbers. |
Source code in flyfield/utils.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
conditional_merge_list(main_list, ref_list, match_key, keys_to_merge)
Conditionally merge dictionaries in a main list with those in a reference list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
main_list
|
list[dict]
|
Primary list of dictionaries. |
required |
ref_list
|
list[dict]
|
Reference list of dictionaries. |
required |
match_key
|
str
|
Key to match dictionaries. |
required |
keys_to_merge
|
list[str]
|
Keys to merge from ref_list into main_list. |
required |
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
Modifies main_list in place. |
Source code in flyfield/utils.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|