Module sktmls.apis.graph_api

Classes

class Edge (**kwargs)

GraphDB의 Edge 클래스입니다.

Args

  • kwargs
    • id: (str) Edge 고유 ID
    • label: (str) Edge 라벨
    • properties: (dict) Edge property 값들

Returns

Edge

Methods

def get(self)
class MLSGraphAPIClient (env: MLSENV = None, runtime_env: MLSRuntimeENV = None)

MLS 그래프 API를 호출할 수 있는 클라이언트입니다.

EDD 환경은 지원하지 않습니다.

Args

아래의 환경 변수가 정의된 경우 해당 파라미터를 생략 가능합니다.

  • $MLS_ENV: env
  • $AWS_ENV: env
  • $MLS_RUNTIME_ENV: runtime_env

Returns

MLSGraphAPIClient

Example

graph_api_client = MLSGraphAPIClient(env=MLSENV.STG, runtime_env=MLSRuntimeENV.YE)

Methods

def add_edge(self, frm: str, to: str, label: str, properties: Dict[str, Any] = {}) ‑> Edge

Edge를 추가합니다.

Args

  • frm: (str) Source Vertex의 고유 ID
  • to: (str) Target Vertex의 고유 ID
  • label: (str) Edge의 라벨
  • properties: (dict) Edge의 property 키와 값

Returns

Edge

Example

edge = graph_api_client.add_edge(
    frm="USER001",
    to="USER002",
    label="follows",
    properties={
        "weight": 3,
        "hello": "world",
    }
)
async def add_edge_async(self, frm: str, to: str, label: str, properties: Dict[str, Any] = {}) ‑> Edge

Edge를 추가합니다.

Args

  • frm: (str) Source Vertex의 고유 ID
  • to: (str) Target Vertex의 고유 ID
  • label: (str) Edge의 라벨
  • properties: (dict) Edge의 property 키와 값

Returns

Edge

Example

edge = await graph_api_client.add_edge_async(
    frm="USER001",
    to="USER002",
    label="follows",
    properties={
        "weight": 3,
        "hello": "world",
    }
)
def add_vertex(self, vertex_id: str, label: str, properties: Dict[str, Any] = {}) ‑> Vertex

Vertex를 추가합니다.

Args

  • vertex_id: (str) Vertex의 고유 ID
  • label: (str) Vertex의 라벨
  • properties: (dict) Vertex의 property 키와 값

Returns

Vertex

Example

vertex = graph_api_client.add_vertex(
    vertex_id="USER001",
    label="user",
    properties={
        "name": "김유저",
        "age": 30,
    }
)
async def add_vertex_async(self, vertex_id: str, label: str, properties: Dict[str, Any] = {}) ‑> Vertex

Vertex를 추가합니다.

Args

  • vertex_id: (str) Vertex의 고유 ID
  • label: (str) Vertex의 라벨
  • properties: (dict) Vertex의 property 키와 값

Returns

Vertex

Example

vertex = await graph_api_client.add_vertex_async(
    vertex_id="USER001",
    label="user",
    properties={
        "name": "김유저",
        "age": 30,
    }
)
def drop_edge(self, edge_id: str) ‑> NoneType

단일 Edge를 삭제합니다.

Args

  • edge_id: (str) Edge의 고유 ID. 보통은 {source_vertex_id}_{label}_{target_vertex_id} 형식을 따릅니다.

Example

edge = graph_api_client.drop_edge("USER001_follows_USER002")
async def drop_edge_async(self, edge_id: str) ‑> NoneType

단일 Edge를 삭제합니다.

Args

  • edge_id: (str) Edge의 고유 ID. 보통은 {source_vertex_id}_{label}_{target_vertex_id} 형식을 따릅니다.

Example

edge = await graph_api_client.drop_edge_async("USER001_follows_USER002")
def drop_edges(self, query_params: Dict[str, Union[str, List[str]]] = {}) ‑> NoneType

조건에 해당하는 모든 Edge를 삭제합니다.

Args

  • query_params: (optional) (dict) 쿼리 파라미터. 아래 예시 참조 (기본값: {})
    • {property_name}={value}: Vertex.Properties[property_name] == str(value)
    • {property_name}__{operator}
      • eq, gt, gte, lt, lte: Vertex.Properties[property_name] {operator} float(value)
      • bw: {property_name}__bw={value1},{value2}: float(value1) < Vertex.Properties[property_name] < float(value2)

Example

# `hello` property가 `world`값을 가지며 `weight` property가 3보다 큰 Edge를 삭제하기
edges = graph_api_client.delete_edges(query_params={
    "hello": "world",
    "weight__gte": 3,
})
async def drop_edges_async(self, query_params: Dict[str, Union[str, List[str]]] = {}) ‑> NoneType

조건에 해당하는 모든 Edge를 삭제합니다.

Args

  • query_params: (optional) (dict) 쿼리 파라미터. 아래 예시 참조 (기본값: {})
    • {property_name}={value}: Vertex.Properties[property_name] == str(value)
    • {property_name}__{operator}
      • eq, gt, gte, lt, lte: Vertex.Properties[property_name] {operator} float(value)
      • bw: {property_name}__bw={value1},{value2}: float(value1) < Vertex.Properties[property_name] < float(value2)

Example

# `hello` property가 `world`값을 가지며 `weight` property가 3보다 큰 Edge를 삭제하기
edges = await graph_api_client.delete_edges_async(query_params={
    "hello": "world",
    "weight__gte": 3,
})
def drop_vertex(self, vertex_id: str) ‑> NoneType

단일 Vertex를 삭제합니다. 연결된 Edge들 역시 삭제됩니다.

Args

  • vertex_id: (str) Vertex의 고유 ID

Example

vertex = graph_api_client.drop_vertex("USER001")
async def drop_vertex_async(self, vertex_id: str) ‑> NoneType

단일 Vertex를 삭제합니다. 연결된 Edge들 역시 삭제됩니다.

Args

  • vertex_id: (str) Vertex의 고유 ID

Example

vertex = await graph_api_client.drop_vertex_async("USER001")
def drop_vertices(self, query_params: Dict[str, Union[str, List[str]]] = {}) ‑> NoneType

조건에 해당하는 모든 Vertex를 삭제합니다.

Args

  • query_params: (optional) (dict) 쿼리 파라미터. 아래 예시 참조 (기본값: {})
    • {property_name}={value}: Vertex.Properties[property_name] == str(value)
    • {property_name}__{operator}
      • eq, gt, gte, lt, lte: Vertex.Properties[property_name] {operator} float(value)
      • bw: {property_name}__bw={value1},{value2}: float(value1) < Vertex.Properties[property_name] < float(value2)

Example

# `hello` property가 `world`값을 가지며 `latitude` property가 33보다 큰 Vertex를 삭제하기
vertices = graph_api_client.delete_vertices(query_params={
    "hello": "world",
    "latitude__gte": 33,
})
async def drop_vertices_async(self, query_params: Dict[str, Union[str, List[str]]] = {}) ‑> NoneType

조건에 해당하는 모든 Vertex를 삭제합니다.

Args

  • query_params: (optional) (dict) 쿼리 파라미터. 아래 예시 참조 (기본값: {})
    • {property_name}={value}: Vertex.Properties[property_name] == str(value)
    • {property_name}__{operator}
      • eq, gt, gte, lt, lte: Vertex.Properties[property_name] {operator} float(value)
      • bw: {property_name}__bw={value1},{value2}: float(value1) < Vertex.Properties[property_name] < float(value2)

Example

# `hello` property가 `world`값을 가지며 `latitude` property가 33보다 큰 Vertex를 삭제하기
vertices = await graph_api_client.delete_vertices_async(query_params={
    "hello": "world",
    "latitude__gte": 33,
})
def get_edge(self, edge_id: str) ‑> Edge

단일 Edge를 가져옵니다.

Args

  • edge_id: (str) Edge의 고유 ID. 보통은 {source_vertex_id}_{label}_{target_vertex_id} 형식을 따릅니다.

Returns

Edge

Example

edge = graph_api_client.get_edge("USER001_follows_USER002")
async def get_edge_async(self, edge_id: str) ‑> Edge

단일 Edge를 가져옵니다.

Args

  • edge_id: (str) Edge의 고유 ID. 보통은 {source_vertex_id}_{label}_{target_vertex_id} 형식을 따릅니다.

Returns

Edge

Example

edge = await graph_api_client.get_edge_async("USER001_follows_USER002")
def get_env(self) ‑> MLSENV
def get_runtime_env(self) ‑> MLSRuntimeENV
def get_vertex(self, vertex_id: str) ‑> Vertex

단일 Vertex를 가져옵니다.

Args

  • vertex_id: (str) Vertex의 고유 ID

Returns

Vertex

Example

vertex = graph_api_client.get_vertex("USER001")
async def get_vertex_async(self, vertex_id: str) ‑> Vertex

단일 Vertex를 가져옵니다.

Args

  • vertex_id: (str) Vertex의 고유 ID

Returns

Vertex

Example

vertex = await graph_api_client.get_vertex_async("USER001")
def list_edges(self, query_params: Dict[str, Union[str, List[str]]] = {}) ‑> List[Edge]

조건에 해당하는 모든 Edge의 리스트를 가져옵니다. 300개를 초과하는 경우 300개까지만 가져옵니다.

Args

  • query_params: (optional) (dict) 쿼리 파라미터. 아래 예시 참조 (기본값: {})
    • {property_name}={value}: Vertex.Properties[property_name] == str(value)
    • {property_name}__{operator}
      • eq, gt, gte, lt, lte: Vertex.Properties[property_name] {operator} float(value)
      • bw: {property_name}__bw={value1},{value2}: float(value1) < Vertex.Properties[property_name] < float(value2)

Returns

list(Edge)

Example

# 모든 Edge 가져오기 (최대 300개로 제한)
edges = graph_api_client.list_edges()

# `hello` property가 `world`값을 가지며 `weight` property가 3보다 큰 Edge를 가져오기
edges = graph_api_client.list_edges(query_params={
    "hello": "world",
    "weight__gte": 33,
})
async def list_edges_async(self, query_params: Dict[str, Union[str, List[str]]] = {}) ‑> List[Edge]

조건에 해당하는 모든 Edge의 리스트를 가져옵니다. 300개를 초과하는 경우 300개까지만 가져옵니다.

Args

  • query_params: (optional) (dict) 쿼리 파라미터. 아래 예시 참조 (기본값: {})
    • {property_name}={value}: Vertex.Properties[property_name] == str(value)
    • {property_name}__{operator}
      • eq, gt, gte, lt, lte: Vertex.Properties[property_name] {operator} float(value)
      • bw: {property_name}__bw={value1},{value2}: float(value1) < Vertex.Properties[property_name] < float(value2)

Returns

list(Edge)

Example

# 모든 Edge 가져오기 (최대 300개로 제한)
edges = await graph_api_client.list_edges_async()

# `hello` property가 `world`값을 가지며 `weight` property가 3보다 큰 Edge를 가져오기
edges = await graph_api_client.list_edges_async(query_params={
    "hello": "world",
    "weight__gte": 33,
})
def list_vertices(self, query_params: Dict[str, Union[str, List[str]]] = {}) ‑> List[Vertex]

조건에 해당하는 모든 Vertex의 리스트를 가져옵니다. 300개를 초과하는 경우 300개까지만 가져옵니다.

Args

  • query_params: (optional) (dict) 쿼리 파라미터. 아래 예시 참조 (기본값: {})
    • {property_name}={value}: Vertex.Properties[property_name] == str(value)
    • {property_name}__{operator}
      • eq, gt, gte, lt, lte: Vertex.Properties[property_name] {operator} float(value)
      • bw: {property_name}__bw={value1},{value2}: float(value1) < Vertex.Properties[property_name] < float(value2)

Returns

list(Vertex)

Example

# 모든 Vertex 가져오기 (최대 300개로 제한)
vertices = graph_api_client.list_vertices()

# `hello` property가 `world`값을 가지며 `latitude` property가 33보다 큰 Vertex를 가져오기
vertices = graph_api_client.list_vertices(query_params={
    "hello": "world",
    "latitude__gte": 33,
})
async def list_vertices_async(self, query_params: Dict[str, Union[str, List[str]]] = {}) ‑> List[Vertex]

조건에 해당하는 모든 Vertex의 리스트를 가져옵니다. 300개를 초과하는 경우 300개까지만 가져옵니다.

Args

  • query_params: (optional) (dict) 쿼리 파라미터. 아래 예시 참조 (기본값: {})
    • {property_name}={value}: Vertex.Properties[property_name] == str(value)
    • {property_name}__{operator}
      • eq, gt, gte, lt, lte: Vertex.Properties[property_name] {operator} float(value)
      • bw: {property_name}__bw={value1},{value2}: float(value1) < Vertex.Properties[property_name] < float(value2)

Returns

list(Vertex)

Example

# 모든 Vertex 가져오기 (최대 300개로 제한)
vertices = await graph_api_client.list_vertices_async()

# `hello` property가 `world`값을 가지며 `latitude` property가 33보다 큰 Vertex를 가져오기
vertices = await graph_api_client.list_vertices_async(query_params={
    "hello": "world",
    "latitude__gte": 33,
})
def update_edge(self, edge_id: str, properties: Dict[str, Any] = {}) ‑> Edge

단일 Edge의 property를 업데이트합니다.

Args

  • edge_id: (str) Edge의 고유 ID. 보통은 {source_vertex_id}_{label}_{target_vertex_id} 형식을 따릅니다.
  • properties: (dict) Edge의 property 키와 값

Returns

Edge

Example

edge = graph_api_client.update_edge(
    edge_id="USER001_follows_USER002",
    properties={
        "weight": 5,
    }
)
async def update_edge_async(self, edge_id: str, properties: Dict[str, Any] = {}) ‑> Edge

단일 Edge의 property를 업데이트합니다.

Args

  • edge_id: (str) Edge의 고유 ID. 보통은 {source_vertex_id}_{label}_{target_vertex_id} 형식을 따릅니다.
  • properties: (dict) Edge의 property 키와 값

Returns

Edge

Example

edge = await graph_api_client.update_edge_async(
    edge_id="USER001_follows_USER002",
    properties={
        "weight": 5,
    }
)
def update_vertex(self, vertex_id: str, properties: Dict[str, Any] = {}) ‑> Vertex

단일 Vertex의 property를 업데이트합니다.

Args

  • vertex_id: (str) Vertex의 고유 ID
  • properties: (dict) Vertex의 property 키와 값

Returns

Vertex

Example

vertex = graph_api_client.update_vertex(
    vertex_id="USER001",
    properties={
        "age": 35,
    }
)
async def update_vertex_async(self, vertex_id: str, properties: Dict[str, Any] = {}) ‑> Vertex

단일 Vertex의 property를 업데이트합니다.

Args

  • vertex_id: (str) Vertex의 고유 ID
  • properties: (dict) Vertex의 property 키와 값

Returns

Vertex

Example

vertex = await graph_api_client.update_vertex_async(
    vertex_id="USER001",
    properties={
        "age": 35,
    }
)
class Vertex (**kwargs)

GraphDB의 Vertex 클래스입니다.

Args

  • kwargs
    • id: (str) Vertex 고유 ID
    • label: (str) Vertex 라벨
    • properties: (dict) Vertex property 값들

Returns

Vertex

Methods

def get(self)