Chapter 08Lesson 03130–180 min

Collections, String, DateTime, OperatingSystem, Process, and XML Libraries: Configuration, Design Patterns, and Trade-Offs

Choose standard-library boundaries deliberately: structured Process execution over shell text, copies over accidental shared mutation, portable paths, explicit encoding/time conventions, and XML structure over string matching.

Trade-offsProcess vs shellText vs bytesPathsXML design

Learning objectives

  • Choose a standard-library keyword or a custom Python library based on abstraction and ownership rather than convenience.
  • Explain why Process structured execution is safer and more diagnosable than deprecated OperatingSystem Run-style shell commands.
  • Choose copies or intentional mutation for list/dictionary data and document ownership.
  • Select explicit path, text/bytes, encoding, and time-zone conventions for portable automation.
  • Use XML structural APIs when the requirement concerns document meaning rather than raw serialization.

Current compatibility baseline. Verified 2026-08-31: Robot Framework 7.4.2 is the current stable release and requires Python 3.8+. The six libraries in this chapter ship with Robot Framework core. BuiltIn is available automatically, while Collections, String, DateTime, OperatingSystem, Process, and XML must be imported explicitly. Robot Framework 7.4 added type hints across standard libraries, expanded bytes support, and Secret-aware arguments in relevant APIs. This chapter does not require pre-release syntax or third-party libraries.

1. Decision model: use the narrowest explicit capability

Standard libraries are strongest when the operation maps cleanly to their domain: list manipulation, text conversion, date arithmetic, filesystem operations, child execution, or XML queries. Move logic into a custom Python library when the domain rule becomes complex enough that Robot syntax starts describing implementation rather than intent.

2. Standard library keyword versus custom Python library

Prefer standard library when… Prefer custom Python library when…
The operation is one or a few clear transformations or checks. The domain rule needs substantial algorithms, reusable object models, or Python ecosystem APIs.
The keyword name already communicates intent. A sequence of low-level library calls obscures the domain action.
Versioned Robot documentation defines the contract. You need a project-specific typed API with tests and packaging.
No hidden shared state is needed. State must be encapsulated behind a deliberate library instance lifecycle.

3. OperatingSystem Run-style commands versus Process

OperatingSystem.Run, Run And Return RC, and Run And Return RC And Output are deprecated. New suites should use Process. Process accepts command and arguments separately, gives a result object, supports timeouts/background execution/termination, and lets stdout/stderr be configured independently.

Need Recommended pattern Avoid
Run known tool with known arguments Run Process tool arg1 arg2 Concatenated shell string
Need shell pipeline/operator Use shell=True only with fully controlled text and explicit review Interpolating untrusted variables into shell text
Large output Redirect stdout/stderr to owned files Unlimited in-memory capture
Background service fixture Start Process + readiness check + teardown termination Orphan processes

4. In-memory mutation versus copied data

Collections contains both querying and mutating operations. Mutation is efficient and readable when one keyword clearly owns the object. It becomes risky when the same list/dictionary is shared through suite/global scope or passed to parallel workers. Use Copy List/Copy Dictionary at ownership boundaries; use deepcopy=True only when nested mutable items must also be independent.

5. Absolute versus relative paths

Relative paths improve portability only when their base is explicit. Robot automatic variables such as ${CURDIR}, ${EXECDIR}, ${OUTPUT DIR}, and ${TEMPDIR} communicate different ownership. For scratch data, ${TEMPDIR} plus a run-unique suffix is appropriate. For committed fixtures, ${CURDIR} is often appropriate. Do not depend on an accidental current working directory.

6. Text versus bytes and explicit encoding

Robot Framework 7.4 substantially expanded bytes support in String and standard type conversion. That does not mean bytes and text are interchangeable. Decode bytes at a known boundary using the correct encoding; encode text only when a byte-oriented protocol/file requires it. Avoid errors=ignore as a default because silently dropping data can hide corruption.

*** Settings ***
Library    String

*** Test Cases ***
Explicit Encoding Boundary
    ${bytes}=    Encode String To Bytes    café    UTF-8
    ${text}=     Decode Bytes To String    ${bytes}    UTF-8
    Should Be Equal    ${text}    café

7. Local time versus explicit timestamps

Use LOCAL when the requirement is explicitly local-human time. Use UTC for cross-host evidence and machine correlation, and include the convention in the serialized value. DateTime returns naive Python datetime objects when result_format=datetime, so do not infer timezone awareness merely because the source was UTC. For durable interchange, serialize an unambiguous timestamp.

8. XML library versus raw string matching

Requirement Prefer Why
Check element text/attribute XML keyword Expresses document structure directly
Compare semantic XML structure Elements Should Be Equal with appropriate options Avoids incidental serialization differences
Verify exact bytes as a signed artifact Byte/file checksum outside semantic XML comparison Raw representation is itself the requirement
Modify a parsed model XML setters + explicit Save XML Makes persistence an explicit side effect

9. Secret-aware arguments are masking boundaries, not vaults

Robot Framework 7.4 added Secret support to relevant standard-library arguments, including file/environment/process-related values. This helps keep supported values out of normal logs. It does not encrypt files, environment variables, child-process memory, or operating-system process state. Secret creation/storage belongs to a secret-management boundary; standard libraries only consume the values safely where supported.

10. Worked scenario: choose the boundary

Scenario Choice Rationale
Normalize three component names String + Collections Simple in-memory transformation; no custom Python needed
Run a linter and collect rc/stdout/stderr Process Structured child execution and evidence
Delete an owned scratch directory OperatingSystem with normalized-path guard Explicit filesystem ownership and cleanup
Validate XML field values XML Structure matters, not serialization
Implement 200-line dependency graph algorithm Custom Python library Algorithmic implementation belongs below readable Robot orchestration

11. Knowledge check

Why is shell=True not the default recommendation?

When is deepcopy=True useful?

Does Secret make an environment variable encrypted?

Why can raw XML string equality be fragile?

12. Summary and next step

The strongest standard-library design keeps capability boundaries explicit and state ownership narrow. Lesson 4 now applies those choices to realistic failures: injection, deletion mistakes, leaked processes, output/encoding trouble, cross-platform path errors, shared mutable state, and brittle XML comparisons.

Next lesson

Collections, String, DateTime, OperatingSystem, Process, and XML Libraries: Diagnostics, Failure Modes, and Production Practices

Continue with Collections, String, DateTime, OperatingSystem, Process, and XML Libraries: Diagnostics, Failure Modes, and Production Practices. It builds directly on the state, evidence, and operating assumptions established here, so carry those constraints forward rather than treating the next page as an isolated topic.

Further reading

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0 Send only Ethereum/ERC-20 compatible assets to this address.