Skip to main content

bareun-baropy

Bareun Korean morphological analyzer as a Python package. 한국어 형태소 분석기 바른(Bareun)을 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

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; 3.4.2 adds the truncation result fields).

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.

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):

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.

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.

Very long text

The Bareun engine itself has no limit on text length. The cloud service (api.bareun.ai) processes up to 5,000 characters per request for capacity reasons. Beyond that it analyzes only the first part (cut at a sentence end, else a space) and reports what it left out in truncation. The limit can change, so judge by the truncation field, not by a number. Offsets in the result still count from the start of your text. The installed server (the one bundled in this package) has no limit by default; you can set one with requestCharLimit in the server configuration.

res = b.analyze(long_text)
if res.truncated:                                     # False when nothing was cut
    t = res.truncation
    print(t.original_chars, t.processed_chars, t.dropped_chars)   # e.g. 9001 4991 4010
    print(t.message)                                  # human-readable notice
    rest = t.dropped_text(long_text)                  # the part that was not analyzed; analyze it again to continue
    if t.cut_mid_word:                                # no sentence end or space found: the last eojeol is unreliable
        ...
  • tokenize() returns a list with the same .truncated and .truncation.
  • For a list input (analyze([s1, s2, ...])) the result still has one sentence per input; the unprocessed sentences are empty. res.dropped_begin_sentence_index is the sentence where the cut starts, and truncation.dropped_begin_offset is the position inside that sentence.
  • Existing code keeps working: these are new attributes only.

Custom dictionaries

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

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

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

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

Metadata

Release files for bareun-baropy 3.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for bareun-baropy 3.4.2
File Actions
bareun_baropy-3.4.2-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details for bareun_baropy-3.4.2-py3-none-win_arm64.whl
bareun_baropy-3.4.2-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for bareun_baropy-3.4.2-py3-none-win_amd64.whl
bareun_baropy-3.4.2-py3-none-manylinux_2_34_aarch64.whl Python 3 none Linux glibc 2.34+ ARM64 Details for bareun_baropy-3.4.2-py3-none-manylinux_2_34_aarch64.whl
bareun_baropy-3.4.2-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for bareun_baropy-3.4.2-py3-none-manylinux_2_28_x86_64.whl
bareun_baropy-3.4.2-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for bareun_baropy-3.4.2-py3-none-macosx_11_0_arm64.whl

Total release size: 74.5 MB

Release files / bareun_baropy-3.4.2-py3-none-win_arm64.whl

Download URL bareun_baropy-3.4.2-py3-none-win_arm64.whl
Size 11.6 MB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
c4740ca5e5f7283ee340ee65c2c4684fb8e0656258ccbe386dd3f85594f816c5
BLAKE2b-256 checksum
How to use checksums
a9535044d60713beba512d2b9c1e220bd3ad7c5e059e5f806f454de708d836b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-142-generic

Release files / bareun_baropy-3.4.2-py3-none-win_amd64.whl

Download URL bareun_baropy-3.4.2-py3-none-win_amd64.whl
Size 12.4 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
caef0a39482702ef5f0ca7c105ab8b1fe025bad4ff1b5cf85af4f0293dffbe88
BLAKE2b-256 checksum
How to use checksums
e8073e86a217a413a80fd9f7d4605861326ab81db1f22cdeba4e7209d873baa1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-142-generic

Release files / bareun_baropy-3.4.2-py3-none-manylinux_2_34_aarch64.whl

Download URL bareun_baropy-3.4.2-py3-none-manylinux_2_34_aarch64.whl
Size 15.4 MB
Tags Linux glibc 2.34+ ARM64 Python 3
SHA-256 checksum
How to use checksums
1f1a396ea54192f01b3f15bf692622d1e717af6b43222a7073f155a01e7f7976
BLAKE2b-256 checksum
How to use checksums
9106742c2a4a2588e7d89d1320dc61729d32444876b710e87e46537376f9f962
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-142-generic

Release files / bareun_baropy-3.4.2-py3-none-manylinux_2_28_x86_64.whl

Download URL bareun_baropy-3.4.2-py3-none-manylinux_2_28_x86_64.whl
Size 17.1 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
a64b09b3c05aa790a38f7cf117acfe6584c8aff331b6a77a47bbbde437bab524
BLAKE2b-256 checksum
How to use checksums
78723771fa8fcd1e11e29e70bd88eea5ff8a6ffe54373fd76b7828b4ac080f96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-142-generic

Release files / bareun_baropy-3.4.2-py3-none-macosx_11_0_arm64.whl

Download URL bareun_baropy-3.4.2-py3-none-macosx_11_0_arm64.whl
Size 18.1 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
03db32e7fcfeaef0b8877ae8b8da89c55901a0dae5c16314e5dd5bb2bf06023c
BLAKE2b-256 checksum
How to use checksums
b8ce96b4cbb8f28953f4e5a3a4a4ec6013546cc51d3463946ca954b1d3b2b4a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-142-generic

Security for bareun-baropy 3.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.4.2 This release

5 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page