fsspeckit.common API Reference¶
common
¶
Cross-cutting utilities for fsspeckit.
This package contains utilities that are shared across different components: - Datetime parsing and manipulation utilities - Logging configuration and helpers - General purpose utility functions - Polars DataFrame optimization and manipulation - Type conversion and data transformation utilities
Functions¶
fsspeckit.common.dict_to_dataframe
¶
dict_to_dataframe(
data: Union[dict, list[dict]],
unique: Union[bool, list[str], str] = False,
) -> Any
Convert a dictionary or list of dictionaries to a Polars DataFrame.
Handles various input formats: - Single dict with list values → DataFrame rows - Single dict with scalar values → Single row DataFrame - List of dicts with scalar values → Multi-row DataFrame - List of dicts with list values → DataFrame with list columns
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[dict, list[dict]]
|
Dictionary or list of dictionaries to convert. |
required |
unique
|
Union[bool, list[str], str]
|
If True, remove duplicate rows. Can also specify columns. |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
Polars DataFrame containing the converted data. |
Examples:
Source code in src/fsspeckit/common/types.py
11 12 13 14 15 16 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 | |
fsspeckit.common.get_logger
¶
Get a logger instance for the given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Logger name, typically the module name. |
'fsspeckit'
|
Returns:
| Type | Description |
|---|---|
logger
|
Configured logger instance. |
Source code in src/fsspeckit/common/logging.py
fsspeckit.common.get_partitions_from_path
¶
get_partitions_from_path(
path: str,
partitioning: Union[str, list[str], None] = None,
) -> list[tuple]
Extract dataset partitions from a file path.
Parses file paths to extract partition information based on different partitioning schemes. This is the canonical implementation used across all fsspeckit backends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path potentially containing partition information. |
required |
partitioning
|
Union[str, list[str], None]
|
Partitioning scheme: - "hive": Hive-style partitioning (key=value) - str: Single partition column name - list[str]: Multiple partition column names - None: Return empty list |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple]
|
List of tuples containing (column, value) pairs. |
Examples:
Source code in src/fsspeckit/common/partitions.py
fsspeckit.common.get_timedelta_str
¶
Convert timedelta strings between different formats.
Converts timedelta strings between Polars and DuckDB formats, with graceful fallback for unknown units. Never raises errors for unknown units - instead returns a reasonable string representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timedelta_string
|
str
|
Input timedelta string (e.g., "1h", "2d", "5invalid"). |
required |
to
|
str
|
Target format - "polars" or "duckdb". Defaults to "polars". |
'polars'
|
Returns:
| Type | Description |
|---|---|
str
|
String in the target format. For unknown units, returns "value unit" |
str
|
format without raising errors. |
Examples:
Source code in src/fsspeckit/common/datetime.py
fsspeckit.common.get_timestamp_column
¶
Get timestamp column names from a DataFrame or PyArrow Table.
Automatically detects and normalizes different DataFrame types to work with pandas DataFrames, Polars DataFrames/LazyFrames, and PyArrow Tables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
Any
|
A Polars DataFrame/LazyFrame, PyArrow Table, or pandas DataFrame. The function automatically converts pandas DataFrames and PyArrow Tables to Polars LazyFrames for consistent timestamp detection. |
required |
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
List of strings containing timestamp column names. Returns an empty list |
Union[str, list[str]]
|
if no timestamp columns are found. |
Examples:
Source code in src/fsspeckit/common/datetime.py
fsspeckit.common.opt_dtype_pl
¶
opt_dtype_pl(
df: DataFrame,
include: str | list[str] | None = None,
exclude: str | list[str] | None = None,
time_zone: str | None = None,
shrink_numerics: bool = False,
allow_unsigned: bool = True,
allow_null: bool = True,
sample_size: int | None = 1024,
sample_method: SampleMethod = "first",
strict: bool = False,
*,
force_timezone: str | None = None,
) -> DataFrame
Optimize data types of a Polars DataFrame for performance and memory efficiency.
This function analyzes each column and converts it to the most appropriate data type based on content, handling string-to-type conversions and numeric type downcasting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The Polars DataFrame to optimize. |
required |
include
|
str | list[str] | None
|
Column(s) to include in optimization (default: all columns). |
None
|
exclude
|
str | list[str] | None
|
Column(s) to exclude from optimization. |
None
|
time_zone
|
str | None
|
Optional time zone hint during datetime parsing. |
None
|
shrink_numerics
|
bool
|
Whether to downcast numeric types when possible. |
False
|
allow_unsigned
|
bool
|
Whether to allow unsigned integer types. |
True
|
allow_null
|
bool
|
Whether to allow columns with all null values to be cast to Null type. |
True
|
sample_size
|
int | None
|
Maximum number of cleaned values to inspect for regex-based inference. Use None to inspect the entire column. |
1024
|
sample_method
|
SampleMethod
|
Which subset to inspect ( |
'first'
|
strict
|
bool
|
If True, will raise an error if any column cannot be optimized. |
False
|
force_timezone
|
str | None
|
If set, ensure all parsed datetime columns end up with this timezone. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with optimized data types. |
Source code in src/fsspeckit/common/polars.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
fsspeckit.common.safe_format_error
¶
safe_format_error(
operation: str,
path: str | None = None,
error: BaseException | None = None,
**context: Any,
) -> str
Format an error message with credentials scrubbed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operation
|
str
|
Description of the operation that failed. |
required |
path
|
str | None
|
Optional path involved in the operation. |
None
|
error
|
BaseException | None
|
Optional exception that occurred. |
None
|
**context
|
Any
|
Additional context key-value pairs. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
A formatted, credential-scrubbed error message. |
Source code in src/fsspeckit/common/security.py
fsspeckit.common.scrub_credentials
¶
Remove or mask credential-like values from a string.
This is intended for use before logging error messages that might contain sensitive information like access keys or tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The string to scrub. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The string with credential-like values replaced with [REDACTED]. |
Examples:
Source code in src/fsspeckit/common/security.py
fsspeckit.common.scrub_exception
¶
Scrub credentials from an exception's string representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc
|
BaseException
|
The exception to scrub. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A scrubbed string representation of the exception. |
Source code in src/fsspeckit/common/security.py
fsspeckit.common.setup_logging
¶
setup_logging(
level: Optional[str] = None,
disable: bool = False,
format_string: Optional[str] = None,
) -> None
Configure the Loguru logger for fsspeckit.
Removes the default handler and adds a new one targeting stderr with customizable level and format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
Optional[str]
|
Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL). If None, uses fsspeckit_LOG_LEVEL environment variable or defaults to "INFO". |
None
|
disable
|
bool
|
Whether to disable logging for fsspeckit package. |
False
|
format_string
|
Optional[str]
|
Custom format string for log messages. If None, uses a default comprehensive format. |
None
|
Example
Source code in src/fsspeckit/common/logging.py
fsspeckit.common.sync_dir
¶
sync_dir(
src_fs: AbstractFileSystem,
dst_fs: AbstractFileSystem,
src_path: str = "",
dst_path: str = "",
server_side: bool = True,
chunk_size: int = 8 * 1024 * 1024,
parallel: bool = False,
n_jobs: int = -1,
verbose: bool = True,
) -> dict[str, list[str]]
Sync two directories between different filesystems.
Compares files in the source and destination directories, copies new or updated files from source to destination, and deletes stale files from destination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src_fs
|
AbstractFileSystem
|
Source filesystem (fsspec AbstractFileSystem) |
required |
dst_fs
|
AbstractFileSystem
|
Destination filesystem (fsspec AbstractFileSystem) |
required |
src_path
|
str
|
Path in source filesystem to sync. Default is root (''). |
''
|
dst_path
|
str
|
Path in destination filesystem to sync. Default is root (''). |
''
|
chunk_size
|
int
|
Size of chunks to read/write files (in bytes). Default is 8MB. |
8 * 1024 * 1024
|
parallel
|
bool
|
Whether to perform copy/delete operations in parallel. Default is False. |
False
|
n_jobs
|
int
|
Number of parallel jobs if parallel=True. Default is -1 (all cores). |
-1
|
verbose
|
bool
|
Whether to show progress bars. Default is True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, list[str]]
|
Summary of added and deleted files |
Source code in src/fsspeckit/common/misc.py
fsspeckit.common.sync_files
¶
sync_files(
add_files: list[str],
delete_files: list[str],
src_fs: AbstractFileSystem,
dst_fs: AbstractFileSystem,
src_path: str = "",
dst_path: str = "",
server_side: bool = False,
chunk_size: int = 8 * 1024 * 1024,
parallel: bool = False,
n_jobs: int = -1,
verbose: bool = True,
) -> dict[str, list[str]]
Sync files between two filesystems by copying new files and deleting old ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
add_files
|
list[str]
|
List of file paths to add (copy from source to destination) |
required |
delete_files
|
list[str]
|
List of file paths to delete from destination |
required |
src_fs
|
AbstractFileSystem
|
Source filesystem (fsspec AbstractFileSystem) |
required |
dst_fs
|
AbstractFileSystem
|
Destination filesystem (fsspec AbstractFileSystem) |
required |
src_path
|
str
|
Base path in source filesystem. Default is root (''). |
''
|
dst_path
|
str
|
Base path in destination filesystem. Default is root (''). |
''
|
server_side
|
bool
|
Whether to use server-side copy if supported. Default is False. |
False
|
chunk_size
|
int
|
Size of chunks to read/write files (in bytes). Default is 8MB. |
8 * 1024 * 1024
|
parallel
|
bool
|
Whether to perform copy/delete operations in parallel. Default is False. |
False
|
n_jobs
|
int
|
Number of parallel jobs if parallel=True. Default is -1 (all cores). |
-1
|
verbose
|
bool
|
Whether to show progress bars. Default is True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, list[str]]
|
Summary of added and deleted files |
Source code in src/fsspeckit/common/misc.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 | |
fsspeckit.common.timestamp_from_string
cached
¶
timestamp_from_string(
timestamp_str: str,
tz: Union[str, None] = None,
naive: bool = False,
) -> Union[datetime, date, time]
Converts a timestamp string (ISO 8601 format) into a datetime, date, or time object using only standard Python libraries.
Handles strings with or without timezone information (e.g., '2023-01-01T10:00:00+02:00', '2023-01-01', '10:00:00'). Supports timezone offsets like '+HH:MM' or '+HHMM'. For named timezones (e.g., 'Europe/Paris'), requires Python 3.9+ and the 'tzdata' package to be installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp_str
|
str
|
The string representation of the timestamp (ISO 8601 format). |
required |
tz
|
str
|
Target timezone identifier (e.g., 'UTC', '+02:00', 'Europe/Paris'). If provided, the output datetime/time will be localized or converted to this timezone. Defaults to None. |
None
|
naive
|
bool
|
If True, return a naive datetime/time (no timezone info),
even if the input string or |
False
|
Returns:
| Type | Description |
|---|---|
Union[datetime, date, time]
|
Union[dt.datetime, dt.date, dt.time]: The parsed datetime, date, or time object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the timestamp string format is invalid or the timezone is invalid/unsupported. |
Source code in src/fsspeckit/common/datetime.py
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 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 | |
fsspeckit.common.to_pyarrow_table
¶
to_pyarrow_table(
data: Union[Any, dict, list[Any]],
concat: bool = False,
unique: Union[bool, list[str], str] = False,
) -> Any
Convert various data formats to PyArrow Table.
Handles conversion from Polars DataFrames, Pandas DataFrames, dictionaries, and lists of these types to PyArrow Tables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[Any, dict, list[Any]]
|
Input data to convert. |
required |
concat
|
bool
|
Whether to concatenate multiple inputs into single table. |
False
|
unique
|
Union[bool, list[str], str]
|
Whether to remove duplicates. Can specify columns. |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
PyArrow Table containing the converted data. |
Example
Source code in src/fsspeckit/common/types.py
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 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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
fsspeckit.common.validate_columns
¶
Validate that requested columns exist in the schema.
This is a helper to prevent column injection in SQL-like operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
list[str] | None
|
List of column names to validate, or None. |
required |
valid_columns
|
list[str]
|
List of valid column names from the schema. |
required |
Returns:
| Type | Description |
|---|---|
list[str] | None
|
The validated columns list, or None if columns was None. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any column is not in the valid set. |
Source code in src/fsspeckit/common/security.py
fsspeckit.common.validate_compression_codec
¶
Validate that a compression codec is in the allowed set.
This prevents injection of arbitrary values into SQL queries or filesystem operations that accept codec parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
codec
|
str
|
The compression codec name to validate. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The validated codec name (lowercased). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the codec is not in the allowed set. |
Examples:
Source code in src/fsspeckit/common/security.py
fsspeckit.common.validate_path
¶
Validate a filesystem path for security issues.
Checks for: - Embedded null bytes and control characters - Path traversal attempts (../ sequences escaping base_dir) - Empty or whitespace-only paths
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The path to validate. |
required |
base_dir
|
str | None
|
Optional base directory. If provided, the path must resolve to a location within this directory (prevents path traversal). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The validated path (unchanged if valid). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the path contains forbidden characters, is empty, or escapes the base directory. |
Examples:
Source code in src/fsspeckit/common/security.py
Modules¶
fsspeckit.common.datetime
¶
Functions¶
fsspeckit.common.datetime.get_timedelta_str
¶
Convert timedelta strings between different formats.
Converts timedelta strings between Polars and DuckDB formats, with graceful fallback for unknown units. Never raises errors for unknown units - instead returns a reasonable string representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timedelta_string
|
str
|
Input timedelta string (e.g., "1h", "2d", "5invalid"). |
required |
to
|
str
|
Target format - "polars" or "duckdb". Defaults to "polars". |
'polars'
|
Returns:
| Type | Description |
|---|---|
str
|
String in the target format. For unknown units, returns "value unit" |
str
|
format without raising errors. |
Examples:
Source code in src/fsspeckit/common/datetime.py
fsspeckit.common.datetime.get_timestamp_column
¶
Get timestamp column names from a DataFrame or PyArrow Table.
Automatically detects and normalizes different DataFrame types to work with pandas DataFrames, Polars DataFrames/LazyFrames, and PyArrow Tables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
Any
|
A Polars DataFrame/LazyFrame, PyArrow Table, or pandas DataFrame. The function automatically converts pandas DataFrames and PyArrow Tables to Polars LazyFrames for consistent timestamp detection. |
required |
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
List of strings containing timestamp column names. Returns an empty list |
Union[str, list[str]]
|
if no timestamp columns are found. |
Examples:
Source code in src/fsspeckit/common/datetime.py
fsspeckit.common.datetime.timestamp_from_string
cached
¶
timestamp_from_string(
timestamp_str: str,
tz: Union[str, None] = None,
naive: bool = False,
) -> Union[datetime, date, time]
Converts a timestamp string (ISO 8601 format) into a datetime, date, or time object using only standard Python libraries.
Handles strings with or without timezone information (e.g., '2023-01-01T10:00:00+02:00', '2023-01-01', '10:00:00'). Supports timezone offsets like '+HH:MM' or '+HHMM'. For named timezones (e.g., 'Europe/Paris'), requires Python 3.9+ and the 'tzdata' package to be installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp_str
|
str
|
The string representation of the timestamp (ISO 8601 format). |
required |
tz
|
str
|
Target timezone identifier (e.g., 'UTC', '+02:00', 'Europe/Paris'). If provided, the output datetime/time will be localized or converted to this timezone. Defaults to None. |
None
|
naive
|
bool
|
If True, return a naive datetime/time (no timezone info),
even if the input string or |
False
|
Returns:
| Type | Description |
|---|---|
Union[datetime, date, time]
|
Union[dt.datetime, dt.date, dt.time]: The parsed datetime, date, or time object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the timestamp string format is invalid or the timezone is invalid/unsupported. |
Source code in src/fsspeckit/common/datetime.py
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 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 | |
fsspeckit.common.logging
¶
Logging configuration utilities for fsspeckit.
Functions¶
fsspeckit.common.logging.get_logger
¶
Get a logger instance for the given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Logger name, typically the module name. |
'fsspeckit'
|
Returns:
| Type | Description |
|---|---|
logger
|
Configured logger instance. |
Source code in src/fsspeckit/common/logging.py
fsspeckit.common.logging.setup_logging
¶
setup_logging(
level: Optional[str] = None,
disable: bool = False,
format_string: Optional[str] = None,
) -> None
Configure the Loguru logger for fsspeckit.
Removes the default handler and adds a new one targeting stderr with customizable level and format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
Optional[str]
|
Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL). If None, uses fsspeckit_LOG_LEVEL environment variable or defaults to "INFO". |
None
|
disable
|
bool
|
Whether to disable logging for fsspeckit package. |
False
|
format_string
|
Optional[str]
|
Custom format string for log messages. If None, uses a default comprehensive format. |
None
|
Example
Source code in src/fsspeckit/common/logging.py
fsspeckit.common.logging_config
¶
Logging configuration utilities for fsspeckit using Python's standard logging module.
Functions¶
fsspeckit.common.logging_config.get_logger
¶
Get a properly configured logger for a module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Module name (typically name) |
required |
Returns:
| Type | Description |
|---|---|
Logger
|
Configured logger instance |
Source code in src/fsspeckit/common/logging_config.py
fsspeckit.common.logging_config.setup_logging
¶
setup_logging(
level: str = "INFO",
format_string: Optional[str] = None,
include_timestamp: bool = True,
enable_console: bool = True,
enable_file: bool = False,
file_path: Optional[str] = None,
) -> None
Configure logging for the fsspeckit package.
This should be called once at application startup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
str
|
Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
'INFO'
|
format_string
|
Optional[str]
|
Custom log format string |
None
|
include_timestamp
|
bool
|
Whether to include timestamp in logs |
True
|
enable_console
|
bool
|
Whether to output to console |
True
|
enable_file
|
bool
|
Whether to output to file |
False
|
file_path
|
Optional[str]
|
Path for log file output |
None
|
Source code in src/fsspeckit/common/logging_config.py
fsspeckit.common.misc
¶
Miscellaneous utility functions for fsspeckit.
Functions¶
fsspeckit.common.misc.check_fs_identical
¶
Check if two fsspec filesystems are identical.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fs1
|
AbstractFileSystem
|
First filesystem (fsspec AbstractFileSystem) |
required |
fs2
|
AbstractFileSystem
|
Second filesystem (fsspec AbstractFileSystem) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if filesystems are identical, False otherwise |
Source code in src/fsspeckit/common/misc.py
fsspeckit.common.misc.get_partitions_from_path
¶
get_partitions_from_path(
path: str, partitioning: Union[str, list, None] = None
) -> Dict[str, str]
Extract dataset partitions from a file path.
Parses file paths to extract partition information based on different partitioning schemes. By default, uses Hive-style partitioning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path potentially containing partition information. |
required |
partitioning
|
Union[str, list, None]
|
Partitioning scheme: - "hive": Hive-style partitioning (key=value) - str: Single partition column name - list[str]: Multiple partition column names - None: Default to Hive-style partitioning |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dictionary mapping partition keys to their values. |
Examples:
Source code in src/fsspeckit/common/misc.py
fsspeckit.common.misc.path_to_glob
¶
Convert a path to a glob pattern for file matching.
Intelligently converts paths to glob patterns that match files of the specified format, handling various directory and wildcard patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Base path to convert. Can include wildcards (* or ). Examples: "data/", "data/*.json", "data/" |
required |
format
|
Union[str, None]
|
File format to match (without dot). If None, inferred from path. Examples: "json", "csv", "parquet" |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Glob pattern that matches files of specified format. Examples: "data/**/.json", "data/.csv" |
Example
Source code in src/fsspeckit/common/misc.py
fsspeckit.common.misc.sync_dir
¶
sync_dir(
src_fs: AbstractFileSystem,
dst_fs: AbstractFileSystem,
src_path: str = "",
dst_path: str = "",
server_side: bool = True,
chunk_size: int = 8 * 1024 * 1024,
parallel: bool = False,
n_jobs: int = -1,
verbose: bool = True,
) -> dict[str, list[str]]
Sync two directories between different filesystems.
Compares files in the source and destination directories, copies new or updated files from source to destination, and deletes stale files from destination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src_fs
|
AbstractFileSystem
|
Source filesystem (fsspec AbstractFileSystem) |
required |
dst_fs
|
AbstractFileSystem
|
Destination filesystem (fsspec AbstractFileSystem) |
required |
src_path
|
str
|
Path in source filesystem to sync. Default is root (''). |
''
|
dst_path
|
str
|
Path in destination filesystem to sync. Default is root (''). |
''
|
chunk_size
|
int
|
Size of chunks to read/write files (in bytes). Default is 8MB. |
8 * 1024 * 1024
|
parallel
|
bool
|
Whether to perform copy/delete operations in parallel. Default is False. |
False
|
n_jobs
|
int
|
Number of parallel jobs if parallel=True. Default is -1 (all cores). |
-1
|
verbose
|
bool
|
Whether to show progress bars. Default is True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, list[str]]
|
Summary of added and deleted files |
Source code in src/fsspeckit/common/misc.py
fsspeckit.common.misc.sync_files
¶
sync_files(
add_files: list[str],
delete_files: list[str],
src_fs: AbstractFileSystem,
dst_fs: AbstractFileSystem,
src_path: str = "",
dst_path: str = "",
server_side: bool = False,
chunk_size: int = 8 * 1024 * 1024,
parallel: bool = False,
n_jobs: int = -1,
verbose: bool = True,
) -> dict[str, list[str]]
Sync files between two filesystems by copying new files and deleting old ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
add_files
|
list[str]
|
List of file paths to add (copy from source to destination) |
required |
delete_files
|
list[str]
|
List of file paths to delete from destination |
required |
src_fs
|
AbstractFileSystem
|
Source filesystem (fsspec AbstractFileSystem) |
required |
dst_fs
|
AbstractFileSystem
|
Destination filesystem (fsspec AbstractFileSystem) |
required |
src_path
|
str
|
Base path in source filesystem. Default is root (''). |
''
|
dst_path
|
str
|
Base path in destination filesystem. Default is root (''). |
''
|
server_side
|
bool
|
Whether to use server-side copy if supported. Default is False. |
False
|
chunk_size
|
int
|
Size of chunks to read/write files (in bytes). Default is 8MB. |
8 * 1024 * 1024
|
parallel
|
bool
|
Whether to perform copy/delete operations in parallel. Default is False. |
False
|
n_jobs
|
int
|
Number of parallel jobs if parallel=True. Default is -1 (all cores). |
-1
|
verbose
|
bool
|
Whether to show progress bars. Default is True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, list[str]]
|
Summary of added and deleted files |
Source code in src/fsspeckit/common/misc.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 | |
fsspeckit.common.optional
¶
Optional dependency management utilities.
This module provides utilities for managing optional dependencies in fsspeckit, implementing lazy loading patterns that allow core functionality to work without requiring all optional dependencies to be installed.
Functions¶
fsspeckit.common.optional.check_optional_dependency
¶
Check if an optional dependency is available and raise helpful error if not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
Name of the required package |
required |
feature_name
|
Optional[str]
|
Name of the feature that requires this package (optional) |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If the package is not available |
Source code in src/fsspeckit/common/optional.py
fsspeckit.common.partitions
¶
Shared partition utilities for fsspeckit.
This module provides canonical implementations for partition parsing and related operations across all backends. It consolidates partition-related logic that was previously scattered across different modules.
Key responsibilities: 1. Partition extraction from file paths 2. Support for multiple partitioning schemes (Hive, directory-based) 3. Partition validation and normalization 4. Path manipulation for partitioned datasets
Architecture: - Functions are designed to work with string paths and fsspec filesystems - Support for common partitioning patterns used in data lakes - Consistent behavior across all backends - Extensible design for custom partitioning schemes
Usage: Backend implementations should delegate to this module rather than implementing their own partition parsing logic. This ensures consistent behavior across DuckDB, PyArrow, and future backends.
Functions¶
fsspeckit.common.partitions.apply_partition_pruning
¶
apply_partition_pruning(
paths: list[str],
partition_filters: dict[str, Any],
partitioning: str | list[str] | None = None,
) -> list[str]
Apply partition pruning to reduce the set of files to scan.
This is an optimization that eliminates files based on partition values before any I/O operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
list[str]
|
List of all file paths. |
required |
partition_filters
|
dict[str, Any]
|
Dictionary of partition filters to apply. |
required |
partitioning
|
str | list[str] | None
|
Partitioning scheme. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Pruned list of paths. |
Source code in src/fsspeckit/common/partitions.py
fsspeckit.common.partitions.build_partition_path
¶
build_partition_path(
base_path: str,
partitions: list[tuple[str, str]],
partitioning: str = "hive",
) -> str
Build a file path with partition directories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
str
|
Base directory path. |
required |
partitions
|
list[tuple[str, str]]
|
List of (column, value) tuples. |
required |
partitioning
|
str
|
Partitioning scheme ("hive" or "directory"). |
'hive'
|
Returns:
| Type | Description |
|---|---|
str
|
Path string with partition directories. |
Source code in src/fsspeckit/common/partitions.py
fsspeckit.common.partitions.create_partition_expression
¶
Create a partition filter expression for different backends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
partitions
|
list[tuple[str, str]]
|
List of (column, value) tuples. |
required |
backend
|
str
|
Target backend ("pyarrow", "duckdb"). |
'pyarrow'
|
Returns:
| Type | Description |
|---|---|
Any
|
Backend-specific filter expression. |
Source code in src/fsspeckit/common/partitions.py
fsspeckit.common.partitions.extract_partition_filters
¶
extract_partition_filters(
paths: list[str],
partitioning: str | list[str] | None = None,
) -> dict[str, set[str]]
Extract unique partition values from a list of paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
list[str]
|
List of file paths. |
required |
partitioning
|
str | list[str] | None
|
Partitioning scheme. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, set[str]]
|
Dictionary mapping column names to sets of unique values. |
Source code in src/fsspeckit/common/partitions.py
fsspeckit.common.partitions.filter_paths_by_partitions
¶
filter_paths_by_partitions(
paths: list[str],
partition_filters: dict[str, str | list[str]],
partitioning: str | list[str] | None = None,
) -> list[str]
Filter paths based on partition values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
list[str]
|
List of file paths to filter. |
required |
partition_filters
|
dict[str, str | list[str]]
|
Dictionary mapping column names to filter values. |
required |
partitioning
|
str | list[str] | None
|
Partitioning scheme. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Filtered list of paths. |
Source code in src/fsspeckit/common/partitions.py
fsspeckit.common.partitions.get_partition_columns_from_paths
¶
get_partition_columns_from_paths(
paths: list[str],
partitioning: str | list[str] | None = None,
) -> list[str]
Get all unique partition column names from a list of paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
list[str]
|
List of file paths. |
required |
partitioning
|
str | list[str] | None
|
Partitioning scheme. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of unique partition column names. |
Source code in src/fsspeckit/common/partitions.py
fsspeckit.common.partitions.get_partitions_from_path
¶
get_partitions_from_path(
path: str,
partitioning: Union[str, list[str], None] = None,
) -> list[tuple]
Extract dataset partitions from a file path.
Parses file paths to extract partition information based on different partitioning schemes. This is the canonical implementation used across all fsspeckit backends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path potentially containing partition information. |
required |
partitioning
|
Union[str, list[str], None]
|
Partitioning scheme: - "hive": Hive-style partitioning (key=value) - str: Single partition column name - list[str]: Multiple partition column names - None: Return empty list |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple]
|
List of tuples containing (column, value) pairs. |
Examples:
Source code in src/fsspeckit/common/partitions.py
fsspeckit.common.partitions.infer_partitioning_scheme
¶
Infer the partitioning scheme from a sample of paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
list[str]
|
List of file paths to analyze. |
required |
max_samples
|
int
|
Maximum number of paths to sample. |
100
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with inferred scheme information. |
Source code in src/fsspeckit/common/partitions.py
fsspeckit.common.partitions.normalize_partition_value
¶
Normalize a partition value for consistent comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Raw partition value from path. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Normalized partition value. |
Source code in src/fsspeckit/common/partitions.py
fsspeckit.common.partitions.validate_partition_columns
¶
validate_partition_columns(
partitions: list[tuple[str, str]],
expected_columns: list[str] | None = None,
) -> bool
Validate partition columns against expected schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
partitions
|
list[tuple[str, str]]
|
List of (column, value) tuples. |
required |
expected_columns
|
list[str] | None
|
Optional list of expected column names. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if partitions are valid, False otherwise. |
Source code in src/fsspeckit/common/partitions.py
fsspeckit.common.polars
¶
Functions¶
fsspeckit.common.polars.drop_null_columns
¶
Remove columns with all null values from the DataFrame.
fsspeckit.common.polars.opt_dtype
¶
opt_dtype(
df: DataFrame,
include: str | list[str] | None = None,
exclude: str | list[str] | None = None,
time_zone: str | None = None,
shrink_numerics: bool = False,
allow_unsigned: bool = True,
allow_null: bool = True,
sample_size: int | None = 1024,
sample_method: SampleMethod = "first",
strict: bool = False,
*,
force_timezone: str | None = None,
) -> DataFrame
Optimize data types of a Polars DataFrame for performance and memory efficiency.
This function analyzes each column and converts it to the most appropriate data type based on content, handling string-to-type conversions and numeric type downcasting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The Polars DataFrame to optimize. |
required |
include
|
str | list[str] | None
|
Column(s) to include in optimization (default: all columns). |
None
|
exclude
|
str | list[str] | None
|
Column(s) to exclude from optimization. |
None
|
time_zone
|
str | None
|
Optional time zone hint during datetime parsing. |
None
|
shrink_numerics
|
bool
|
Whether to downcast numeric types when possible. |
False
|
allow_unsigned
|
bool
|
Whether to allow unsigned integer types. |
True
|
allow_null
|
bool
|
Whether to allow columns with all null values to be cast to Null type. |
True
|
sample_size
|
int | None
|
Maximum number of cleaned values to inspect for regex-based inference. Use None to inspect the entire column. |
1024
|
sample_method
|
SampleMethod
|
Which subset to inspect ( |
'first'
|
strict
|
bool
|
If True, will raise an error if any column cannot be optimized. |
False
|
force_timezone
|
str | None
|
If set, ensure all parsed datetime columns end up with this timezone. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with optimized data types. |
Source code in src/fsspeckit/common/polars.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
fsspeckit.common.schema
¶
Shared schema utilities for fsspeckit.
This module provides canonical implementations for schema compatibility, unification, timezone handling, and type optimization across all backends. It consolidates schema-related logic that was previously scattered across dataset-specific modules.
Key responsibilities: 1. Schema unification with intelligent conflict resolution 2. Timezone standardization and detection 3. Large type conversion to standard types 4. Schema casting and validation 5. Data type optimization 6. Empty column handling
Architecture: - Functions are designed to work with PyArrow schemas and tables - All operations preserve metadata when possible - Timezone handling supports multiple strategies (auto, explicit, removal) - Type optimization includes safety checks and fallback strategies - Schema unification uses multiple fallback strategies for maximum compatibility
Usage: Backend implementations should delegate to this module rather than implementing their own schema logic. This ensures consistent behavior across DuckDB, PyArrow, and future backends.
Functions¶
fsspeckit.common.schema.cast_schema
¶
Cast a PyArrow table to a given schema, updating the schema to match the table's columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
The PyArrow table to cast. |
required |
schema
|
Schema
|
The target schema to cast table to. |
required |
Returns:
| Type | Description |
|---|---|
Table
|
pa.Table: A new PyArrow table with the specified schema. |
Source code in src/fsspeckit/common/schema.py
fsspeckit.common.schema.convert_large_types_to_normal
¶
Convert large types in a PyArrow schema to their standard types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
The PyArrow schema to convert. |
required |
Returns:
| Type | Description |
|---|---|
Schema
|
pa.Schema: A new PyArrow schema with large types converted to standard types. |
Source code in src/fsspeckit/common/schema.py
fsspeckit.common.schema.dominant_timezone_per_column
¶
For each timestamp column (by name) across all schemas, detect the most frequent timezone (including None). If None and a timezone are tied, prefer the timezone. Returns a dict: {column_name: dominant_timezone}
Source code in src/fsspeckit/common/schema.py
fsspeckit.common.schema.remove_empty_columns
¶
Remove columns that are entirely empty from a PyArrow table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
Table
|
The PyArrow table to process. |
required |
Returns:
| Type | Description |
|---|---|
Table
|
pa.Table: A new PyArrow table with empty columns removed. |
Source code in src/fsspeckit/common/schema.py
fsspeckit.common.schema.standardize_schema_timezones
¶
standardize_schema_timezones(
schemas: Schema | list[Schema],
timezone: str | None = None,
) -> Schema | list[Schema]
Standardize timezone info for all timestamp columns in a list of PyArrow schemas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schemas
|
list of pa.Schema
|
List of PyArrow schemas. |
required |
timezone
|
str or None
|
If None, remove timezone from all timestamp columns. If str, set this timezone for all timestamp columns. If "auto", use the most frequent timezone across schemas. |
None
|
Returns:
| Type | Description |
|---|---|
Schema | list[Schema]
|
list of pa.Schema: New schemas with standardized timezone info. |
Source code in src/fsspeckit/common/schema.py
fsspeckit.common.schema.standardize_schema_timezones_by_majority
¶
For each timestamp column (by name) across all schemas, set the timezone to the most frequent (with tie-breaking). Returns a new list of schemas with updated timestamp timezones.
Source code in src/fsspeckit/common/schema.py
fsspeckit.common.schema.unify_schemas
¶
unify_schemas(
schemas: list[Schema],
use_large_dtypes: bool = False,
timezone: str | None = None,
standardize_timezones: bool = True,
verbose: bool = False,
remove_conflicting_columns: bool = False,
) -> Schema
Unify a list of PyArrow schemas into a single schema using intelligent conflict resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schemas
|
list[Schema]
|
List of PyArrow schemas to unify. |
required |
use_large_dtypes
|
bool
|
If True, keep large types like large_string. |
False
|
timezone
|
str | None
|
If specified, standardize all timestamp columns to this timezone. If "auto", use the most frequent timezone across schemas. If None, remove timezone from all timestamp columns. |
None
|
standardize_timezones
|
bool
|
If True, standardize all timestamp columns to most frequent timezone. |
True
|
verbose
|
bool
|
If True, print conflict resolution details for debugging. |
False
|
remove_conflicting_columns
|
bool
|
If True, allows removal of columns with type conflicts as a fallback strategy instead of converting them. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Schema
|
pa.Schema: A unified PyArrow schema. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no schemas are provided. |
Source code in src/fsspeckit/common/schema.py
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 | |
fsspeckit.common.security
¶
Security validation helpers for fsspeckit.
This module provides basic validation for paths, codecs, and credential scrubbing to prevent common security issues like path traversal and credential leakage in logs.
Functions¶
fsspeckit.common.security.safe_format_error
¶
safe_format_error(
operation: str,
path: str | None = None,
error: BaseException | None = None,
**context: Any,
) -> str
Format an error message with credentials scrubbed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operation
|
str
|
Description of the operation that failed. |
required |
path
|
str | None
|
Optional path involved in the operation. |
None
|
error
|
BaseException | None
|
Optional exception that occurred. |
None
|
**context
|
Any
|
Additional context key-value pairs. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
A formatted, credential-scrubbed error message. |
Source code in src/fsspeckit/common/security.py
fsspeckit.common.security.scrub_credentials
¶
Remove or mask credential-like values from a string.
This is intended for use before logging error messages that might contain sensitive information like access keys or tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The string to scrub. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The string with credential-like values replaced with [REDACTED]. |
Examples:
Source code in src/fsspeckit/common/security.py
fsspeckit.common.security.scrub_exception
¶
Scrub credentials from an exception's string representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc
|
BaseException
|
The exception to scrub. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A scrubbed string representation of the exception. |
Source code in src/fsspeckit/common/security.py
fsspeckit.common.security.validate_columns
¶
Validate that requested columns exist in the schema.
This is a helper to prevent column injection in SQL-like operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
list[str] | None
|
List of column names to validate, or None. |
required |
valid_columns
|
list[str]
|
List of valid column names from the schema. |
required |
Returns:
| Type | Description |
|---|---|
list[str] | None
|
The validated columns list, or None if columns was None. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any column is not in the valid set. |
Source code in src/fsspeckit/common/security.py
fsspeckit.common.security.validate_compression_codec
¶
Validate that a compression codec is in the allowed set.
This prevents injection of arbitrary values into SQL queries or filesystem operations that accept codec parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
codec
|
str
|
The compression codec name to validate. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The validated codec name (lowercased). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the codec is not in the allowed set. |
Examples:
Source code in src/fsspeckit/common/security.py
fsspeckit.common.security.validate_path
¶
Validate a filesystem path for security issues.
Checks for: - Embedded null bytes and control characters - Path traversal attempts (../ sequences escaping base_dir) - Empty or whitespace-only paths
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The path to validate. |
required |
base_dir
|
str | None
|
Optional base directory. If provided, the path must resolve to a location within this directory (prevents path traversal). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The validated path (unchanged if valid). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the path contains forbidden characters, is empty, or escapes the base directory. |
Examples:
Source code in src/fsspeckit/common/security.py
fsspeckit.common.types
¶
Type conversion and data transformation utilities.
Functions¶
fsspeckit.common.types.dict_to_dataframe
¶
dict_to_dataframe(
data: Union[dict, list[dict]],
unique: Union[bool, list[str], str] = False,
) -> Any
Convert a dictionary or list of dictionaries to a Polars DataFrame.
Handles various input formats: - Single dict with list values → DataFrame rows - Single dict with scalar values → Single row DataFrame - List of dicts with scalar values → Multi-row DataFrame - List of dicts with list values → DataFrame with list columns
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[dict, list[dict]]
|
Dictionary or list of dictionaries to convert. |
required |
unique
|
Union[bool, list[str], str]
|
If True, remove duplicate rows. Can also specify columns. |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
Polars DataFrame containing the converted data. |
Examples:
Source code in src/fsspeckit/common/types.py
11 12 13 14 15 16 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 | |
fsspeckit.common.types.to_pyarrow_table
¶
to_pyarrow_table(
data: Union[Any, dict, list[Any]],
concat: bool = False,
unique: Union[bool, list[str], str] = False,
) -> Any
Convert various data formats to PyArrow Table.
Handles conversion from Polars DataFrames, Pandas DataFrames, dictionaries, and lists of these types to PyArrow Tables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[Any, dict, list[Any]]
|
Input data to convert. |
required |
concat
|
bool
|
Whether to concatenate multiple inputs into single table. |
False
|
unique
|
Union[bool, list[str], str]
|
Whether to remove duplicates. Can specify columns. |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
PyArrow Table containing the converted data. |
Example
Source code in src/fsspeckit/common/types.py
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 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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |