A simple and efficient Python wrapper for Naver API (Search, Papago Translation)
Project description
Naipy(네이피)
누구나 쉽게 사용할 수 있는 네이버 API 래퍼
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 키를 발급받아 사용하세요.
- 네이버 개발자 센터 방문
- 애플리케이션 등록
- 발급받은 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- 썸네일 URLsizeheight- 이미지 높이sizewidth- 이미지 너비
BlogNaipy
title- 포스트 제목link- 포스트 링크description- 포스트 설명bloggername- 블로거 이름bloggerlink- 블로거 링크postdate- 발행일
ShopNaipy
title- 상품명link- 상품 링크image- 상품 이미지lprice- 최저가hprice- 최고가mallName- 쇼핑몰명productId- 상품 IDbrand- 브랜드명
자세한 사항은 공식 문서를 참고하세요.
에러 처리
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36c713d971cd4aaeb3ea05459bcfdd31b55a2ae0181f732539cf6024c61bd248
|
|
| MD5 |
101b4912f2c3a27fd093a1329d52cd56
|
|
| BLAKE2b-256 |
ff2bb73ea410edc8c9beb96a6369ff97e721f97b7d8556b097258e850861e46f
|
Provenance
The following attestation bundles were made for naipy-3.0.0.tar.gz:
Publisher:
publish.yml on d3vksy/Naipy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
naipy-3.0.0.tar.gz -
Subject digest:
36c713d971cd4aaeb3ea05459bcfdd31b55a2ae0181f732539cf6024c61bd248 - Sigstore transparency entry: 1630619074
- Sigstore integration time:
-
Permalink:
d3vksy/Naipy@41b28bc6e640bf07fc1debdc9ea388b5132ac345 -
Branch / Tag:
refs/tags/v3.0.0 - Owner: https://github.com/d3vksy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@41b28bc6e640bf07fc1debdc9ea388b5132ac345 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83f0ba670c49d937a71361c6b0381beb1070a7f4d0b58fb7f884fd0bccdf43ff
|
|
| MD5 |
f73b90d3bb78d8f3ae184c3664d15b77
|
|
| BLAKE2b-256 |
3a5528e204aa3a30f54dba42adc6b786b26cb0aae9e7ecf1485a1244b400308c
|
Provenance
The following attestation bundles were made for naipy-3.0.0-py3-none-any.whl:
Publisher:
publish.yml on d3vksy/Naipy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
naipy-3.0.0-py3-none-any.whl -
Subject digest:
83f0ba670c49d937a71361c6b0381beb1070a7f4d0b58fb7f884fd0bccdf43ff - Sigstore transparency entry: 1630619104
- Sigstore integration time:
-
Permalink:
d3vksy/Naipy@41b28bc6e640bf07fc1debdc9ea388b5132ac345 -
Branch / Tag:
refs/tags/v3.0.0 - Owner: https://github.com/d3vksy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@41b28bc6e640bf07fc1debdc9ea388b5132ac345 -
Trigger Event:
push
-
Statement type: