Skip to content

Add project creation capabilities #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,27 @@ from nocodb.infra.requests_client import NocoDBRequestsClient

# Usage with API Token
client = NocoDBRequestsClient(
# Your nocodb root path
"http://localhost:8080",
# Your API Token retrieved from NocoDB conf
APIToken("YOUR-API-TOKEN"),
# Your nocodb root path
"http://localhost:8080"
)

# Usage with JWT Token
client = NocoDBRequestsClient(
# Your nocodb root path
"http://localhost:8080",
# Your API Token retrieved from NocoDB conf
JWTAuthToken("your.jwt.token"),
)

# Usage with email and password
client = NocoDBRequestsClient(
# Your nocodb root path
"http://localhost:8080"
"http://localhost:8080",
# Your profile credentials
email="[email protected]",
password="123qwe123!"
)
```

Expand Down
11 changes: 11 additions & 0 deletions nocodb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
class NocoDBAPIUris(Enum):
V1_DB_DATA_PREFIX = "api/v1/db/data"
V1_DB_META_PREFIX = "api/v1/db/meta"
V1_AUTH_USER_PREFIX = "api/v1/auth/user"



class NocoDBAPI:
Expand All @@ -14,6 +16,15 @@ def __init__(self, base_uri: str):
)
self.__base_meta_uri = (
f"{base_uri}/{NocoDBAPIUris.V1_DB_META_PREFIX.value}"
self.__base_auth_uri = (
f"{base_uri}/{NocoDBAPIUris.V1_AUTH_USER_PREFIX.value}"
)
def get_auth_uri(self):
return "/".join(
(
self.__base_auth_uri,
"signin"
)
)

def get_table_uri(self, project: NocoDBProject, table: str) -> str:
Expand Down
29 changes: 25 additions & 4 deletions nocodb/infra/requests_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Optional
from ..nocodb import (
JWTAuthToken,
NocoDBClient,
NocoDBProject,
AuthToken,
Expand All @@ -12,13 +13,33 @@


class NocoDBRequestsClient(NocoDBClient):
def __init__(self, auth_token: AuthToken, base_uri: str):
def __init__(
self,
base_uri: str,
auth_token: AuthToken = None,
email: str = None,
password: str = None,
):
self.__session = requests.Session()
self.__api_info = NocoDBAPI(base_uri)

if not auth_token and not (email and password):
raise ValueError("Either сredentials or token must be provided")

if not auth_token and (email and password):
auth_token = JWTAuthToken(self.get_auth_token(email, password))

self.__session.headers.update(
auth_token.get_header(),
)
auth_token.get_header(),
)
self.__session.headers.update({"Content-Type": "application/json"})
self.__api_info = NocoDBAPI(base_uri)

def get_auth_token(self, email: str, password: str) -> str:
auth_token = self.__session.post(
self.__api_info.get_auth_uri(),
json=dict(email=email, password=password)
).json()['token']
return auth_token

def table_row_list(
self,
Expand Down