Source: https://dev-docs.nebula-graph.io/v5.3.2/clients/python-client/ Documentation version: v5.3.2 # Python SDK guide Set up the [Python SDK](https://github.com/vesoft-inc/nebula-python/tree/v5.3.0) to connect to NebulaGraph Database Developer Edition and run basic queries. For a complete workflow from installing dependencies to verifying an application endpoint, see [Build a service with the Python SDK](https://dev-docs.nebula-graph.io/v5.3.2/app-development/python-sdk/). ## Prerequisites - Python 3.10 or later is installed. - A NebulaGraph Database Developer Edition service group is running. For more information, see [Getting started](https://dev-docs.nebula-graph.io/v5.3.2/get-started/deploy/). ## Steps 1. Install the SDK with either of the following methods: - Install from [PyPI](https://pypi.org/project/nebula5-python/): ```` pip install nebula5_python==5.3.0 ```` - Install from source code: ```` git clone -b dev https://github.com/vesoft-inc/nebula-python.git cd nebula-python pip install -e . ```` 2. Use the SDK to connect to NebulaGraph Database Developer Edition and perform queries as follows: ```` from nebulagraph_python.client import NebulaClient # Create client client = NebulaClient( addresses=":", user_name="", password="", ) query = """ RETURN 1 AS a, 2 AS b """ # Execute query try: result = client.execute(query) finally: client.close() ```` Replace `:`, ``, and `` with the actual connection information. 3. To inspect the query result, refer to the following methods: - Print the result in table style ```` result.print() ```` Return: ```` ╔═══╤═══╗ ║ │ ║ ║ a │ b ║ ║ │ ║ ╟───┼───╢ ║ │ ║ ║ 1 │ 2 ║ ║ │ ║ ╚═══╧═══╝ Summary ├── Rows: 1 └── Latency: 1450μs ```` - Retrieve specific values from the query set ```` # Get one row row = result.one() # Get one value cell = row["a"].cast_primitive() # Print its value print(cell, type(cell)) ```` Return: ```` 1 ```` - Retrieve primitive values from the result set ```` print(result.as_primitive_by_column()) print(list(result.as_primitive_by_row())) ```` Return: ```` {'a': [1], 'b': [2]} [{'a': 1, 'b': 2}] ```` - Retrieve a Pandas DataFrame from the query set ```` result = client.execute(query) df = result.as_pandas_df() ```` Return: ```` a b 0 1 2 ```` ## More information - [Python SDK GitHub repository](https://github.com/vesoft-inc/nebula-python/tree/dev) - [Python SDK API reference](https://vesoft-inc.github.io/nebula-python/5.3.0/annotated.html) - [Multi-process concurrent queries](https://github.com/vesoft-inc/nebula-python/blob/dev/example/MultiProcessAsyncClientExample.py)