Skip to main content

A simple and efficient Python wrapper for Naver API (Search, Papago Translation)

Project description

Naipy(네이피)

누구나 쉽게 사용할 수 있는 네이버 API 래퍼

image

PyPI version Python 3.10+ License: MIT

2022 공개SW 개발자 대회 이노그리드 대표상 수상 작품

Naipy는 네이버 API를 쉽게 사용할 수 있도록 만든 파이썬 래퍼 라이브러리입니다.

주요 특징

  • 동기/비동기 모두 지원 - 상황에 맞게 선택해서 사용
  • 9가지 검색 API - 이미지, 블로그, 도서, 백과사전 등
  • 번역 기능 - 언어감지 및 다중언어 번역 지원 (Papago API 서비스 종료 2024-02-29)
  • 타입 안정성 - 완벽한 타입 힌팅으로 IDE 자동완성 지원
  • 최신 Python - Python 3.10+ 표준 준수
  • 포괄적 문서 - 명확한 문서화와 예제 제공

설치

pip install naipy

또는 최신 개발 버전을 사용하려면:

pip install git+https://github.com/d3vksy/Naipy.git

빠른 시작

동기 방식

from naipy import sync

# API 키 없이 사용 가능 (샘플키 사용)
search = sync.Search()

# 이미지 검색
result = search.image("강아지")
print(result.title)
print(result.link)
print(result.thumbnail)

# 블로그 검색
blog_result = search.blog("파이썬 튜토리얼")
print(blog_result.bloggername)
print(blog_result.postdate)

비동기 방식

import asyncio
from naipy import client

async def main():
    search = client.Search()

    result = await search.image("고양이")
    print(result.title)
    print(result.link)

asyncio.run(main())

API 키 발급

프로덕션 환경에서는 반드시 본인의 API 키를 발급받아 사용하세요.

  1. 네이버 개발자 센터 방문
  2. 애플리케이션 등록
  3. 발급받은 Client ID와 Client Secret 사용
from naipy import sync

search = sync.Search(
    client_id="YOUR_CLIENT_ID",
    client_secret="YOUR_CLIENT_SECRET"
)

지원되는 API

검색 API

메서드 설명
search.image(query) 이미지 검색
search.blog(query) 블로그 검색
search.book(query) 도서 검색
search.encyc(query) 백과사전 검색
search.cafearticle(query) 카페 글 검색
search.kin(query) 네이버 지식인 검색
search.webkr(query) 웹페이지 검색
search.shop(query) 쇼핑 검색
search.doc(query) 전문자료 검색

번역 API (서비스 종료)

Papago API가 2024-02-29부로 종료되었습니다. 아래 메서드는 더 이상 동작하지 않습니다.

메서드 설명
translator.detect(text) 언어 감지
translator.translation(text, target) 텍스트 번역
translator.dual_translation(text, [targets]) 다중 언어 번역

응답 객체

각 검색 결과는 전문화된 데이터 클래스로 반환됩니다:

ImageNaipy

  • title - 이미지 제목
  • link - 이미지 링크
  • thumbnail - 썸네일 URL
  • sizeheight - 이미지 높이
  • sizewidth - 이미지 너비

BlogNaipy

  • title - 포스트 제목
  • link - 포스트 링크
  • description - 포스트 설명
  • bloggername - 블로거 이름
  • bloggerlink - 블로거 링크
  • postdate - 발행일

ShopNaipy

  • title - 상품명
  • link - 상품 링크
  • image - 상품 이미지
  • lprice - 최저가
  • hprice - 최고가
  • mallName - 쇼핑몰명
  • productId - 상품 ID
  • brand - 브랜드명

자세한 사항은 공식 문서를 참고하세요.

에러 처리

from naipy import sync
from naipy.error import (
    NaipyException,
    AuthenticationError,
    PermissionError,
    RateLimitError,
    ValidationError,
)

try:
    search = sync.Search()
    result = search.image("test")
except AuthenticationError:
    print("API 인증 실패")
except RateLimitError:
    print("요청 한도 초과")
except ValidationError as e:
    print(f"입력값 오류: {e}")
except NaipyException as e:
    print(f"Naipy 오류: {e}")

고급 사용법

다중 언어 번역 (서비스 종료)

Papago API 종료로 인해 동작하지 않습니다.

에러 핸들링 with 재시도

import asyncio
from naipy import client
from naipy.error import RateLimitError

async def search_with_retry(query, max_retries=3):
    search = client.Search()

    for attempt in range(max_retries):
        try:
            return await search.image(query)
        except RateLimitError:
            if attempt < max_retries - 1:
                wait_time = 2 ** attempt
                print(f"{wait_time}초 대기 후 재시도...")
                await asyncio.sleep(wait_time)
            else:
                raise

asyncio.run(search_with_retry("python"))

라이선스

이 프로젝트는 MIT 라이선스 하에서 배포됩니다. - LICENSE 파일 참고

기여

버그 리포트, 기능 제안, PR은 언제나 환영합니다!

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

naipy-3.0.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

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

naipy-3.0.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file naipy-3.0.0.tar.gz.

File metadata

  • Download URL: naipy-3.0.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for naipy-3.0.0.tar.gz
Algorithm Hash digest
SHA256 36c713d971cd4aaeb3ea05459bcfdd31b55a2ae0181f732539cf6024c61bd248
MD5 101b4912f2c3a27fd093a1329d52cd56
BLAKE2b-256 ff2bb73ea410edc8c9beb96a6369ff97e721f97b7d8556b097258e850861e46f

See more details on using hashes here.

Provenance

The following attestation bundles were made for naipy-3.0.0.tar.gz:

Publisher: publish.yml on d3vksy/Naipy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file naipy-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: naipy-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for naipy-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83f0ba670c49d937a71361c6b0381beb1070a7f4d0b58fb7f884fd0bccdf43ff
MD5 f73b90d3bb78d8f3ae184c3664d15b77
BLAKE2b-256 3a5528e204aa3a30f54dba42adc6b786b26cb0aae9e7ecf1485a1244b400308c

See more details on using hashes here.

Provenance

The following attestation bundles were made for naipy-3.0.0-py3-none-any.whl:

Publisher: publish.yml on d3vksy/Naipy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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