Metadata-Version: 2.5
Name: ibm5250
Version: 0.1.0.dev16
Summary: IBM 5250 terminal automation library
Project-URL: Repository, https://github.com/bengieeee/python5250
Project-URL: Issues, https://github.com/bengieeee/python5250/issues
Author: Ben Goldsmith
License-Expression: MPL-2.0
License-File: LICENSE
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# python5250

`ibm5250` is a pure-Python library for automating IBM 5250 terminal sessions
against IBM i (AS/400) systems over TN5250/TN5250E. It speaks the Telnet
negotiation, 5250 data stream, and screen/field model directly — no green-screen
emulator or external dependencies required — so you can script sign-on,
navigation, and data entry against a 5250 host from plain Python.

See [`src/ibm5250/data-stream-logic.md`](src/ibm5250/data-stream-logic.md) for
a detailed walkthrough of how the library parses the wire protocol into screen
state.

## Installation

```bash
pip install ibm5250
```

Requires Python >= 3.11.

## Usage

```python
from ibm5250 import Terminal, AID

with Terminal("as400.example.com") as t:
    t.wait_for_text("Sign On")
    t.find_field_by_label("User").value = "MYUSER"
    t.find_field_by_label("Password").value = "SECRET"
    t.send_key(AID.ENTER)
    t.wait_for_text("Main Menu")
    print(t.screen.get_screen_text())
```

`send_key` blocks until the host has finished replying (the keyboard unlocks),
however many records that takes.

### Connection options

```python
Terminal(
    "as400.example.com",
    port=992,
    use_tls=True,         # certificate and hostname are verified by default
    timeout=5.0,          # deadline for send_key / wait_for_* (seconds)
    socket_timeout=30.0,  # connect, negotiation and per-read socket limit
)
```

- **Device name**: the host assigns one (e.g. `QPADEV0008`) unless you pass
  `device_name="MYDEV"`.
- **TLS**: pass your own `tls_context=` (e.g. with a private CA loaded), or
  `tls_verify=False` to skip certificate checks (insecure; logs a warning).

### Keys and errors

- `send_attn()` and `send_sysreq()` send Attn and System Request. They are not
  AID keys, so `send_key(AID.ATTN)` / `send_key(AID.SYSREQ)` raise `ValueError`.
  SysReq needs a TN5250E session.
- When the host shows an operator error on the status line (Write Error Code),
  `send_key` and every `wait_for_*` raise `OperatorError`. The host text is in
  `err.message` (it is kept out of `str(err)`). Call `reset()` — the Reset key —
  to clear it before sending another key.
- Writing text longer than a field raises `FieldOverflow`; nothing is written.
- `type_into` returns `True` when filling an Auto-Enter field sent Enter.

### Upgrading from 0.1.x

These changes can break existing code:

- No default device name: it was `PYTERM01`; pass `device_name="PYTERM01"` to
  keep it.
- TLS verifies certificates by default: pass `tls_verify=False` (or a
  `tls_context`) for hosts with self-signed certificates.
- `timeout` is now only the wait deadline; the socket uses `socket_timeout`
  (default 30 s). `poll_interval` is accepted but unused.
- `send_key` waits for the keyboard to unlock instead of reading one record,
  and raises `ScreenWaitTimeout` if it stays locked.
- Over-long field text raises `FieldOverflow` instead of being truncated, and
  shorter text now replaces the whole previous field content.
- `wait_for_text` no longer prints the screen.

## Contributing

1. Clone the repo and install dependencies with [`uv`](https://docs.astral.sh/uv/):

   ```bash
   uv sync --locked
   ```

2. Make your changes under `src/ibm5250/`.
3. Lint and run the test suite before opening a PR:

   ```bash
   uv run ruff check .
   uv run pytest
   ```

4. Branch off `develop` and open your pull request **against `develop`**
   (not `main` — see [Branching & releases](#branching--releases) below).

There's no separate contribution guide configured in this repo — just make
sure `ruff check` and `pytest` both pass.

## Branching & releases

Every push runs the test suite in CI. What gets built and published to PyPI
depends on the branch:

| Branch           | Tested | Built |    Published to PyPI     | Version format                                           |
| ---------------- | :----: | :---: | :----------------------: | -------------------------------------------------------- |
| `main`           |   ✅   |  ✅   |      ✅ production       | `X.Y.Z` (patch auto-incremented from the latest release) |
| `develop`        |   ✅   |  ✅   |      ✅ development      | `X.Y.Z.devN`                                             |
| any other branch |   ✅   |  ✅   | ❌ (build artifact only) | n/a                                                      |

- Contribute by branching off `develop` and opening PRs into `develop`.
  `develop` publishes `.devN` releases so changes can be tried out before
  they're promoted to `main`.
- `main` is production — merges there are published as real, patch-bumped
  releases on PyPI.
- The version in `pyproject.toml` is a base version only and is **never
  hand-bumped** for a release; `scripts/compute_version.py` computes the
  actual published version from what's already on PyPI at build time. See
  [`.github/workflows/README.md`](.github/workflows/README.md) for the full
  CI/publishing setup.

## License

Licensed under the [Mozilla Public License 2.0](LICENSE).
