Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](https://semver.org/)

## [Unreleased]

### Added

- Documentation regarding the cmem-client usage for the `read_` methods in `file.py`

### Changed

- Bumped `cmem-client` version to `1.0.0`

## [4.19.0] 2026-08-03

### Added
Expand Down
54 changes: 51 additions & 3 deletions cmem_plugin_base/dataintegration/typed_entities/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ def read_stream(
Returns a file-like object (stream) in binary mode.
Caller is responsible for closing the stream.

Pass the context of the plugin to read the file with cmem-client. Passing only a
project ID reads the file with cmempy and requires setup_cmempy_user_access() to
be called beforehand.
Pass the context of the plugin to read a project file with cmem-client. Passing
only a project ID reads it with cmempy and requires setup_cmempy_user_access() to
be called beforehand. Local files are read from the file system and need neither.

Both ways of reading report a missing project file differently: reading with a
context raises a FileNotFoundError, while reading with cmempy raises the
Expand All @@ -166,6 +166,14 @@ def is_text(

Returns True if the file content can be decoded as UTF-8 text, False otherwise.
This method automatically handles gzip decompression if needed.

Pass the context of the plugin to read a project file with cmem-client. Passing
only a project ID reads it with cmempy and requires setup_cmempy_user_access() to
be called beforehand. Local files are read from the file system and need neither.

Both ways of reading report a missing project file differently: reading with a
context raises a FileNotFoundError, while reading with cmempy raises the
requests HTTPError that cmempy itself raises.
"""
with self.read_stream(project_id, context) as stream:
_, is_text = _prepare_stream_for_processing(stream)
Expand All @@ -180,6 +188,14 @@ def is_bytes(

Returns True if the file content is binary (cannot be decoded as UTF-8), False otherwise.
This method automatically handles gzip decompression if needed.

Pass the context of the plugin to read a project file with cmem-client. Passing
only a project ID reads it with cmempy and requires setup_cmempy_user_access() to
be called beforehand. Local files are read from the file system and need neither.

Both ways of reading report a missing project file differently: reading with a
context raises a FileNotFoundError, while reading with cmempy raises the
requests HTTPError that cmempy itself raises.
"""
return not self.is_text(project_id, context)

Expand All @@ -192,6 +208,14 @@ def read_text(

Returns the file content as a string. Automatically handles gzip decompression if needed.
Raises UnicodeDecodeError if the file content is not valid UTF-8 text.

Pass the context of the plugin to read a project file with cmem-client. Passing
only a project ID reads it with cmempy and requires setup_cmempy_user_access() to
be called beforehand. Local files are read from the file system and need neither.

Both ways of reading report a missing project file differently: reading with a
context raises a FileNotFoundError, while reading with cmempy raises the
requests HTTPError that cmempy itself raises.
"""
with self.read_stream(project_id, context) as stream:
processed_stream, is_text = _prepare_stream_for_processing(stream)
Expand All @@ -207,6 +231,14 @@ def read_bytes(
"""Read the file content as bytes.

Returns the file content as bytes. Automatically handles gzip decompression if needed.

Pass the context of the plugin to read a project file with cmem-client. Passing
only a project ID reads it with cmempy and requires setup_cmempy_user_access() to
be called beforehand. Local files are read from the file system and need neither.

Both ways of reading report a missing project file differently: reading with a
context raises a FileNotFoundError, while reading with cmempy raises the
requests HTTPError that cmempy itself raises.
"""
with self.read_stream(project_id, context) as stream:
processed_stream, is_text = _prepare_stream_for_processing(stream)
Expand All @@ -227,6 +259,14 @@ def text_stream(
Automatically handles gzip decompression if needed.
Raises UnicodeDecodeError if the file content is not valid UTF-8 text.

Pass the context of the plugin to read a project file with cmem-client. Passing
only a project ID reads it with cmempy and requires setup_cmempy_user_access() to
be called beforehand. Local files are read from the file system and need neither.

Both ways of reading report a missing project file differently: reading with a
context raises a FileNotFoundError, while reading with cmempy raises the
requests HTTPError that cmempy itself raises.

Example:
```python
with file.text_stream(context=context) as stream:
Expand All @@ -252,6 +292,14 @@ def bytes_stream(
Returns a context manager that yields a binary stream for reading file content.
Automatically handles gzip decompression if needed.

Pass the context of the plugin to read a project file with cmem-client. Passing
only a project ID reads it with cmempy and requires setup_cmempy_user_access() to
be called beforehand. Local files are read from the file system and need neither.

Both ways of reading report a missing project file differently: reading with a
context raises a FileNotFoundError, while reading with cmempy raises the
requests HTTPError that cmempy itself raises.

Example:
```python
with file.bytes_stream(context=context) as stream:
Expand Down
Loading
Loading