@@ -213,6 +213,60 @@ Runtime configurations
213213
214214 ``PYTHAINLP_READ_MODE=1 `` is equivalent to ``PYTHAINLP_READ_ONLY=1 ``.
215215
216+ Interaction between environment variables
217+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
218+
219+ The table below shows how :envvar: `PYTHAINLP_OFFLINE ` and :envvar: `PYTHAINLP_READ_ONLY `
220+ affect the two main corpus operations:
221+
222+ .. list-table ::
223+ :header-rows: 1
224+ :widths: 35 32 33
225+
226+ * - Operation
227+ - ``PYTHAINLP_OFFLINE=1 ``
228+ - ``PYTHAINLP_READ_ONLY=1 ``
229+ * - :func: `pythainlp.corpus.get_corpus_path ` — corpus already cached locally
230+ - Succeeds (returns path)
231+ - Succeeds (no write needed)
232+ * - :func: `pythainlp.corpus.get_corpus_path ` — corpus **not ** cached locally
233+ - Fails (:exc: `FileNotFoundError `)
234+ - Fails (:exc: `FileNotFoundError `)
235+ * - :func: `pythainlp.corpus.download ` — corpus already in local catalog
236+ - Succeeds (download is an explicit user action)
237+ - Fails (returns ``False ``; all writes are blocked)
238+ * - :func: `pythainlp.corpus.download ` — corpus **not ** in local catalog
239+ - Succeeds (downloads the corpus)
240+ - Fails (returns ``False ``; all writes are blocked)
241+
242+ Key differences:
243+
244+ - :envvar: `PYTHAINLP_OFFLINE ` blocks only **automatic ** downloads.
245+ Explicit calls to :func: `~pythainlp.corpus.download ` (or the
246+ ``thainlp data get `` CLI command) still work, because those are
247+ deliberate user actions.
248+
249+ - :envvar: `PYTHAINLP_READ_ONLY ` is **more restrictive **: it blocks
250+ *all * writes to the data directory, including explicit
251+ :func: `~pythainlp.corpus.download ` calls.
252+ Use this when the data directory is on a read-only file system
253+ (e.g., a read-only Docker volume or a shared cluster mount).
254+
255+ - :envvar: `PYTHAINLP_DATA ` sets the path of the data directory used by
256+ both modes. In read-only mode the directory is not created if it
257+ does not already exist.
258+
259+ Typical use cases:
260+
261+ - **Offline laptop / air-gapped system **: set ``PYTHAINLP_OFFLINE=1 ``
262+ after downloading all required corpora. You can still call
263+ ``download() `` manually if you have network access.
264+
265+ - **Read-only container image with pre-bundled corpora **:
266+ set ``PYTHAINLP_READ_ONLY=1 `` so that no writes occur at all.
267+ Any attempt to download a corpus that is missing from the image
268+ will return ``False `` instead of raising a permission error.
269+
216270Installation FAQ
217271----------------
218272
0 commit comments