stream
Streaming file interface for LucidLink files.
Provides io.RawIOBase-compatible file streams for seamless integration with Python's standard library and third-party libraries (Pandas, LangChain, PyTorch, etc.).
lucidlink.stream.LucidFileStream
LucidFileStream(fs_wrapper: Any, path: str, mode: str = 'rb', lock_type: str = '')Parameter | Description |
|---|---|
| LucidNativeSdk::FileSystem from lucidlink_native module |
| Path to file within filespace |
| File open mode (default: 'rb') |
| Lock type - "" (no lock), "shared" (read), "exclusive" (write). Lock is held for lifetime of file handle and released on close. |
fs_wrapper
Description
LucidNativeSdk::FileSystem from lucidlink_native module
path
Description
Path to file within filespace
mode
Description
File open mode (default: 'rb')
lock_type
Description
Lock type - "" (no lock), "shared" (read), "exclusive" (write). Lock is held for lifetime of file handle and released on close.
Streaming file access for LucidLink files.
Implements Python's io.RawIOBase interface for efficient, streaming access to files in LucidLink filespaces. Compatible with standard Python I/O operations and third-party libraries that expect file-like objects.
This class provides:
Standard file operations: read, write, seek, tell, truncate
Context manager support (with statement)
Iterator support (for line in file)
Optional file locking (on-open locking)
Compatibility with: Pandas, LangChain, PyTorch, Hugging Face, etc.
Example
with filespace.fs.open("/data/file.txt", "rb") as f:data = f.read()with filespace.fs.open("/data/output.csv", "wb") as f:f.write(b"column1,column2\n")f.write(b"value1,value2\n")# With exclusive locking for SQLite-style accesswith filespace.fs.open("/data/db.sqlite", "r+b", lock_type="exclusive") as f:data = f.read()
closed: bool
Return whether the stream is closed.
Returns
True if stream is closed
mode: str
Return the file mode.
Returns
Mode string used to open the file
name: str
Return the file path.
Returns
Path to file within filespace
close() -> None
Close the stream and release resources.
fileno() -> int
Return underlying file descriptor.
Raises
Exception | Condition |
|---|---|
| LucidLink files don't have OS file descriptors |
io.UnsupportedOperation
Condition
LucidLink files don't have OS file descriptors
isatty() -> bool
Return whether this is an interactive stream.
Returns
False (LucidLink files are never TTY devices)
read(size: int = -1) -> bytes
Read up to size bytes from the stream.
Parameters
Parameter | Description |
|---|---|
| Number of bytes to read, or -1 to read entire file |
size
Description
Number of bytes to read, or -1 to read entire file
Returns
Bytes read from file
Raises
Exception | Condition |
|---|---|
| If stream is closed |
| If stream not opened for reading |
ValueError
Condition
If stream is closed
io.UnsupportedOperation
Condition
If stream not opened for reading
readable() -> bool
Return whether the stream supports reading.
Returns
True if stream was opened for reading
readinto(b: bytearray) -> int
Read bytes into a pre-allocated buffer.
Parameters
Parameter | Description |
|---|---|
| Buffer to read into |
b
Description
Buffer to read into
Returns
Number of bytes read; 0 at EOF
seek(offset: int, whence: int = 0) -> int
Change stream position.
Parameters
Parameter | Description |
|---|---|
| Offset in bytes |
| Reference point (0=start, 1=current, 2=end) |
offset
Description
Offset in bytes
whence
Description
Reference point (0=start, 1=current, 2=end)
Returns
New absolute position
seekable() -> bool
Return whether the stream supports random access.
Returns
True (LucidLink files always support seeking)
tell() -> int
Return current stream position.
Returns
Current position in bytes
truncate(size: Optional[int] = None) -> int
Resize the stream to the given size.
Parameters
Parameter | Description |
|---|---|
| New size in bytes, or current position if None |
size
Description
New size in bytes, or current position if None
Returns
New size
Raises
Exception | Condition |
|---|---|
| If stream is closed |
| If stream not opened for writing |
ValueError
Condition
If stream is closed
io.UnsupportedOperation
Condition
If stream not opened for writing
writable() -> bool
Return whether the stream supports writing.
Returns
True if stream was opened for writing
write(b: bytes) -> int
Write bytes to the stream.
Parameters
Parameter | Description |
|---|---|
| Bytes to write |
b
Description
Bytes to write
Returns
Number of bytes written
Raises
Exception | Condition |
|---|---|
| If stream is closed |
| If stream not opened for writing |
ValueError
Condition
If stream is closed
io.UnsupportedOperation
Condition
If stream not opened for writing
lucidlink.stream.open_buffered
open_buffered(fs_wrapper: Any, path: str, mode: str = 'rb', buffer_size: int = io.DEFAULT_BUFFER_SIZE, lock_type: str = '') -> io.BufferedIOBaseOpen a file with buffering for improved performance.
Parameters
Parameter | Description |
|---|---|
| LucidNativeSdk::FileSystem from lucidlink_native module |
| Path to file within filespace |
| File open mode (default: 'rb') |
| Buffer size in bytes (default: 8192) |
| Lock type - "" (no lock), "shared" (read), "exclusive" (write) |
fs_wrapper
Description
LucidNativeSdk::FileSystem from lucidlink_native module
path
Description
Path to file within filespace
mode
Description
File open mode (default: 'rb')
buffer_size
Description
Buffer size in bytes (default: 8192)
lock_type
Description
Lock type - "" (no lock), "shared" (read), "exclusive" (write)
Returns
BufferedReader, BufferedWriter, or BufferedRandom wrapping LucidFileStream
Example
with open_buffered(fs, "/data/large.csv", "rb") as f:for line in f:process(line)
lucidlink.stream.open_text
open_text(fs_wrapper: Any, path: str, mode: str = 'r', encoding: str = 'utf-8', errors: str = 'strict', newline: Optional[str] = None, lock_type: str = '') -> io.TextIOWrapperOpen a file in text mode.
Parameters
Parameter | Description |
|---|---|
| LucidNativeSdk::FileSystem from lucidlink_native module |
| Path to file within filespace |
| File open mode (default: 'r') |
| Text encoding (default: 'utf-8') |
| Error handling strategy (default: 'strict') |
| Newline handling (None, '', 'n', 'r', 'rn') |
| Lock type - "" (no lock), "shared" (read), "exclusive" (write) |
fs_wrapper
Description
LucidNativeSdk::FileSystem from lucidlink_native module
path
Description
Path to file within filespace
mode
Description
File open mode (default: 'r')
encoding
Description
Text encoding (default: 'utf-8')
errors
Description
Error handling strategy (default: 'strict')
newline
Description
Newline handling (None, '', 'n', 'r', 'rn')
lock_type
Description
Lock type - "" (no lock), "shared" (read), "exclusive" (write)
Returns
TextIOWrapper for text-mode access
Example
with open_text(fs, "/data/report.txt", "r") as f:for line in f:print(line.strip())