Skip to main content

법제처 OpenAPI에서 한국 법령 조문을 수집해 Silver 포맷 JSON으로 저장하는 패키지

Project description

kr-law-extractor

법제처 OpenAPI에서 한국 법령 조문을 수집하여 Silver 레이어 포맷의 JSON 파일로 저장하는 Python 패키지입니다.

설치

pip install kr-law-extractor

사용법

from law_extractor import extract

# 법령명 리스트 → JSON 파일 생성
files = extract(
    ["소득세법", "국세기본법", "근로기준법"],
    output_dir="./output",
    oc="your-oc-key",   # 법제처 API OC 키
)
# ./output/소득세법.json, ./output/국세기본법.json, ... 생성

환경변수로 OC 키를 설정할 수도 있습니다:

export LAW_OC="your-oc-key"
from law_extractor import extract

extract(["소득세법"], output_dir="./output")  # oc 파라미터 생략 가능

출력 포맷

각 법령마다 {법령명}.json 파일이 생성됩니다. 파일 내용은 조문(Article) 단위 레코드의 배열입니다:

[
  {
    "law_mst": "001565",
    "jo_number": "000001",
    "jo_branch_number": null,
    "law_name_ko": "소득세법",
    "law_category": "법률",
    "ministry_name": "기획재정부",
    "enforcement_date": "2024-01-01",
    "jo_title": "목적",
    "jo_content": "이 법은 ...",
    "content_hash": "sha256-hex",
    "has_appendix": false,
    "references": []
  }
]

API OC 키 발급

법제처 오픈API 서비스 에서 이메일 주소를 OC 값으로 사용합니다.

파라미터

파라미터 타입 기본값 설명
law_names list[str] 필수 수집할 법령명 목록
output_dir str | Path "." JSON 저장 디렉토리
oc str | None None 법제처 API OC 키 (없으면 LAW_OC 환경변수)
concurrency int 3 동시 HTTP 요청 수

동작 원리

  1. MST 조회: lawSearch API로 법령명 → 법령ID(MST) 변환
  2. XML 수집: lawService API로 조문 전체 XML 다운로드
  3. 파싱: 조문 단위로 평탄화 (조문 1개 = 레코드 1개, 항/호/목은 본문에 병합)
  4. 해싱: 조문제목 + 조문내용 + 시행일자 기반 SHA-256 해시 계산
  5. 참조 추출: 조문 내 타법 참조(낫표), 내부 조문 참조 그래프 추출
  6. 저장: Silver 레이어 포맷 JSON 파일로 저장

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kr_law_extractor-0.1.0.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kr_law_extractor-0.1.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file kr_law_extractor-0.1.0.tar.gz.

File metadata

  • Download URL: kr_law_extractor-0.1.0.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for kr_law_extractor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0be6231c2bf48ebbde61358e432e1d8875259bf19898d75382170b29253445ff
MD5 c5bc563d0b991b865d51b23a4f364be4
BLAKE2b-256 2424148ef922ae33e3c2cff264dd19d67fbbed19c2401689b3ea2218bceafc23

See more details on using hashes here.

File details

Details for the file kr_law_extractor-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kr_law_extractor-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for kr_law_extractor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e789dde3457e742b231cb0ad1c5e51c8eaee43ff2f26cf15669fb996d9eb8886
MD5 b41f1de563f3988df664b160255c8d0f
BLAKE2b-256 b3e4e0a382b6e69f22ce51a88f19d2af92c91c68a65d3db1163c7d5c174b1c49

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page