Skip to content

Commit

Permalink
feat: Config and SessionPoolConfig could be omit by default
Browse files Browse the repository at this point in the history
- Readme getting started polished
- Config should be able to omit
- The previous SessionPoolConfig Check mechnism was wrong, fixed it
  • Loading branch information
wey-gu committed Mar 16, 2024
1 parent 54f0237 commit 9f6bc54
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 38 deletions.
68 changes: 35 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,6 @@

If you are about to access NebulaGraph within Jupyter Notebook, you may want to use the [NebulaGraph Jupyter Extension](https://pypi.org/project/ipython-ngql/), which provides a more interactive way to access NebulaGraph. See also this on Google Colab: [NebulaGraph on Google Colab](https://colab.research.google.com/github/wey-gu/ipython-ngql/blob/main/examples/get_started.ipynb).

## Directory Structure Overview

```text
.
└──nebula-python
   │
   ├── nebula3 // client source code
   │   ├── fbthrift // the RPC code generated from thrift protocol
   │   ├── common
   │   ├── data
   │   ├── graph
   │   ├── meta
   │   ├── net // the net code for graph client
   │   ├── storage // the storage client code
   │   ├── Config.py // the pool config
   │   └── Exception.py // the exceptions
   │
   ├── examples
   │   ├── FormatResp.py // the format response example
   │   ├── SessionPoolExample.py // the session pool example
   │   ├── GraphClientMultiThreadExample.py // the multi thread example
   │   ├── GraphClientSimpleExample.py // the simple example
   │   └── ScanVertexEdgeExample.py // the scan vertex and edge example(storage client)
   │
   ├── tests // the test code
   │
   ├── setup.py // used to install or package
└── README.md // the introduction of nebula3-python
```

## Obtaining nebula3-python

### Method 1: Installation via pip
Expand Down Expand Up @@ -361,7 +329,41 @@ See [ScanVertexEdgeExample.py](example/ScanVertexEdgeExample.py) for more detail
| 3.5.0 | >=3.4.0 |
| master | master |

## How to Contribute to Nebula-Python

## Directory Structure Overview

```text
.
└──nebula-python
   │
   ├── nebula3 // client source code
   │   ├── fbthrift // the RPC code generated from thrift protocol
   │   ├── common
   │   ├── data
   │   ├── graph
   │   ├── meta
   │   ├── net // the net code for graph client
   │   ├── storage // the storage client code
   │   ├── Config.py // the pool config
   │   └── Exception.py // the exceptions
   │
   ├── examples
   │   ├── FormatResp.py // the format response example
   │   ├── SessionPoolExample.py // the session pool example
   │   ├── GraphClientMultiThreadExample.py // the multi thread example
   │   ├── GraphClientSimpleExample.py // the simple example
   │   └── ScanVertexEdgeExample.py // the scan vertex and edge example(storage client)
   │
   ├── tests // the test code
   │
   ├── setup.py // used to install or package
└── README.md // the introduction of nebula3-python
```


## Contribute to Nebula-Python

<details>
<summary>Click to expand</summary>
Expand Down
11 changes: 8 additions & 3 deletions nebula3/gclient/net/ConnectionPool.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self):
def __del__(self):
self.close()

def init(self, addresses, configs, ssl_conf=None):
def init(self, addresses, configs=None, ssl_conf=None):
"""init the connection pool
:param addresses: the graphd servers' addresses
Expand All @@ -52,8 +52,13 @@ def init(self, addresses, configs, ssl_conf=None):
if self._close:
logger.error('The pool has init or closed.')
raise RuntimeError('The pool has init or closed.')
assert isinstance(configs, Config)
self._configs = configs
if configs is None:
self._configs = Config()
else:
assert isinstance(
configs, Config
), 'wrong type of Config, try this: `from nebula3.Config import Config`'
self._configs = configs
self._ssl_configs = ssl_conf
for address in addresses:
if address not in self._addresses:
Expand Down
8 changes: 6 additions & 2 deletions nebula3/gclient/net/SessionPool.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, username, password, space_name, addresses):
def __del__(self):
self.close()

def init(self, configs):
def init(self, configs=None):
"""init the session pool
:param username: the username of the session
Expand All @@ -81,6 +81,11 @@ def init(self, configs):
:return: if all addresses are valid, return True else return False.
"""
if configs is not None:
assert isinstance(
configs, SessionPoolConfig
), 'wrong type of SessionPoolConfig, try this: `from nebula3.Config import SessionPoolConfig`'
self._configs = configs
# check configs
try:
self._check_configs()
Expand All @@ -91,7 +96,6 @@ def init(self, configs):
if self._close:
logger.error('The pool has init or closed.')
raise RuntimeError('The pool has init or closed.')
self._configs = configs

# ping all servers
self.update_servers_status()
Expand Down

0 comments on commit 9f6bc54

Please sign in to comment.