Metadata-Version: 2.1
Name: bareun-baropy
Version: 3.4.1
Summary: Bareun Korean morphological analyzer as a Python package (server binary included)
Home-page: https://bareun.ai/
License: Proprietary. See https://bareun.ai/en/service
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# bareun-baropy

**Bareun Korean morphological analyzer as a Python package.**
한국어 형태소 분석기 [바른(Bareun)](https://bareun.ai/)을 `pip install` 한 번으로 쓰는 파이썬 패키지입니다.

The analysis server binary is bundled in the wheel, so there is nothing else to install and no server to run.
The package starts the server for you, analyzes text, and shuts it down when you are done.
This release covers **morphological analysis only** (no spelling correction API).

## Install

```bash
pip install bareun-baropy
```

- Python 3.10 or later.
- Platforms (CPU only):
  - Linux x86_64 (glibc 2.28+) and Linux aarch64 (glibc 2.34+)
  - macOS on Apple silicon (arm64, signed and notarized)
  - Windows x64 (tested) and Windows ARM64 (built for ARM64 but not yet tested on real hardware; please report problems)
- The package version follows the Bareun release it ships. `3.4.x` contains the Bareun 3.4.0 server (3.4.1 only fixes the package description).

## Quick start

An API key is required. Get one at <https://bareun.ai/>. It is registered automatically on the first call.
Pass it as `api_key=` or set the `BAREUN_API_KEY` environment variable.

```python
import baropy

with baropy.Bareun(api_key="koba-...") as b:          # or: export BAREUN_API_KEY=koba-...
    res = b.analyze("나는 책을 읽었다.")
    print(res.morphemes.pairs())                      # [('나', 'NP'), ('는', 'JX'), ('책', 'NNG'), ...]
    print(res.morphemes.nouns().texts())              # ['책']
```

The first call downloads the model into your user cache folder (it is not part of the wheel) and can take a while.
Later calls start in seconds. `baropy fetch` downloads the model ahead of time.

For one-off scripts, module-level functions share a single default object (the key comes from `BAREUN_API_KEY`):

```python
import baropy
print(baropy.analyze("바른 형태소 분석기").morphemes.pairs())
baropy.release()                                      # unload the model when finished
```

## Results

`analyze()` returns an `Analysis` > `Sentence` > `Token` (eojeol) > `Morpheme` tree. All objects are read-only.

```python
res = b.analyze("하늘이 맑다. 구름이 없다.")
for sent in res.sentences:
    for tok in sent.tokens:
        print(tok.text, tok.morphemes.tagged())       # e.g. 하늘이 하늘/NNG 이/JKS

res.morphemes.verbs().texts()                         # filter by part of speech
res.morphemes.frequency(top=5)                        # most frequent morphemes: [(text, count), ...]
```

- `b.analyze(["문장 하나", "문장 둘"])` takes a list; `res.sentences[i]` matches input `i`.
- `b.analyze(text, sense=True)` adds word sense (WSD) results to each morpheme.
- `b.tokenize(text)` splits text into eojeol only.
- `MorphemeSeq` helpers: `texts`, `pairs`, `tagged`, `select`, `where`, `nouns`, `verbs`, `adjectives`, `adverbs`, `tokens`, `stats`, `tag_counts`, `frequency`.

## Custom dictionaries

Add your own words by domain name, then use them per call or as defaults.

```python
b.dicts.put("lab", np=["바른"], cp=["형태소분석기"])    # replaces the whole dictionary "lab"
b.analyze("바른 형태소분석기", dicts="lab")
b.default_dicts = ["lab"]                             # use it on every call
b.dicts.list()                                        # see what is registered
b.dicts.remove("lab")
```

Kinds: `np`, `cp`, `cp_caret` (compound split), `vv`, `va`, `mm`, `mag`, `ic`.
Names may contain only letters, digits, `_` and `-` (lower-cased).

## Options

```python
baropy.Bareun(
    api_key=None,            # or BAREUN_API_KEY
    idle_timeout=3600.0,     # unload the model after this many idle seconds (None: never)
    session_timeout=None,    # hard limit for one session
    background=False,        # True: leave a detached server running (server mode)
    cache_dir=None,          # model and runtime files (default: user cache folder)
    threads=4,
    start_timeout=1800.0,    # how long to wait for the first model download
)
```

By default the server is a hidden child process bound to `127.0.0.1` on a random port. It is tied to your Python
process and exits with it. With `background=True` it runs as a detached server on a fixed port instead; in that mode
anyone on the machine who can reach the port can use the registered key, so use it only on machines you trust.

Cache folders: Linux `~/.cache/bareun`, macOS `~/Library/Caches/bareun`, Windows `%LOCALAPPDATA%\bareun\Cache`.

## Command line

```text
baropy help       open the documentation for the installed version
baropy version    print the package version
baropy fetch      download the model ahead of time (key from BAREUN_API_KEY)
baropy serve      run server mode in this terminal (Ctrl-C to stop)
baropy stop       stop a server started in server mode
baropy register   register BAREUN_API_KEY with a running server
```

## Errors

All errors derive from `baropy.BaropyError`: `AuthError` (key rejected), `ModelFetchError` (model download failed),
`ServerStartError` (server did not start), `AnalysisError` (the call failed).

## Documentation and license

- Documentation: run `baropy help`, or see <https://bareun.ai/>.
- License: proprietary, see <https://bareun.ai/en/service>. The source repository is private.
