--- title: "Python Client" slug: "dataquery-python-client-vpc" updated: 2026-09-17T09:07:29Z published: 2026-09-17T09:07:29Z canonical: "guide.ncloud-docs.com/dataquery-python-client-vpc" --- > ## Documentation Index > Fetch the complete documentation index at: https://guide.ncloud-docs.com/llms.txt > Use this file to discover all available pages before exploring further. # Python Client VPC 환경에서 이용 가능합니다. Data Query에서 제공하는 Python Client 사용 방법을 설명합니다. ## 준비 사항 Python Client를 사용할 환경에 Python 3.9 이상이 설치되어 있어야 합니다. ## 사용 방법 Data Query Python Client 사용 방법을 설명합니다. ### 1. 패키지 설치 [PyPI.org](https://pypi.org) 에 공개되어 있는 [ncp-dataquery](https://pypi.org/project/ncp-dataquery/) 패키지를 설치합니다. ``` # [required] ncp-dataquery 패키지 설치 pip install ncp-dataquery # [optional] sqlalchemy 형식으로 Data Query를 연동하는 경우 해당 패키지 설치 pip install sqlalchemy ``` ### 2. Python Client 연동 예시 #### 인증 방식 `NcpIamAuthentication` 클래스를 사용하여 NCP IAM 인증 방식을 지원합니다. 사용자의 AccessKey 및 SecretKey 입력이 필요합니다. #### 쿼리 제출 및 결과 확인 코드를 작성하여 쿼리를 제출하고 결과를 확인합니다. <예시> ``` # DBAPI from ncp_dataquery.dbapi import connect from ncp_dataquery.auth import NcpIamAuthentication conn = connect( host="", port=443, auth=NcpIamAuthentication("", ""), http_scheme="https", reuse_query_result=True, # optional, default=False reuse_query_max_age=5, # optional, default=60, range=1~10080 (unit: minute) ) cur = conn.cursor() cur.execute("SELECT * FROM public_data.korea_national_railway.subway_seoul_capital_area LIMIT 10") rows = cur.fetchall() for row in rows: print(" ".join(row)) ``` ``` # SQLAlchemy from sqlalchemy import create_engine, text from ncp_dataquery.auth import NcpIamAuthentication engine = create_engine( "trino://:443/", connect_args={ "auth": NcpIamAuthentication("", ""), "http_scheme": "https", "reuse_query_result": True, # optional, default=False "reuse_query_max_age": 5, # optional, default=60, range=1~10080 (unit: minute) } ) with engine.connect() as conn: result = conn.execute(text("SELECT * FROM public_data.korea_national_railway.subway_seoul_capital_area LIMIT 10")) for row in result: print(f"{row}") ``` ``` // 결과 예시 코레일 3호선 대화 126.747756 37.675883 코레일 3호선 대곡 126.811025 37.631629 코레일 3호선 화정 126.832503 37.637837 코레일 3호선 원흥 126.873239 37.650709 코레일 3호선 주엽 126.761232 37.670138 코레일 3호선 정발산 126.773254 37.659709 코레일 3호선 마두 126.777641 126.777641 코레일 3호선 백석 126.788109 37.642973 코레일 3호선 원당 126.842891 37.653103 코레일 3호선 삼송 126.895559 37.653096 ``` #### 사용 가능한 옵션 - DBAPI : `connect()` 의 인자값으로 입력합니다. - SQLAlchemy : `create_engine()`의 connect_args 인자값으로 입력합니다. | 옵션명 | 데이터 타입 | 입력값 | 필수 여부 | 비고 | | --- | --- | --- | --- | --- | | server | String | Data Query Endpoint | Y | 리전별 Data Query Service Endpoint 참고 | | reuse_query_result | Boolean | `true` 또는 `false` | N | * default : `false` | | reuse_query_max_age | Integer | `1` ~ `10,080` | N | * default : `60` * reuse-query-result 값이 `true` 인 경우에만 사용됩니다. (단위: 분) | **리전별 Data Query Service Endpoint** 현재 KR 리전만 사용 가능하며, 리전 확대 예정입니다. | 리전 | Endpoint | | --- | --- | | KR | kr.dataquery.naverncp.com | 참고 dataquery-python-client는 trino-python-client를 기반으로 제공합니다. 위 안내된 옵션 외 추가 내용은 [Trino 문서](https://github.com/trinodb/trino-python-client/tree/0.333.0)를 참조해 주십시오.