fragment-python 0.1.1__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fragment_python-0.1.1 → fragment_python-0.2.0}/PKG-INFO +23 -3
- {fragment_python-0.1.1 → fragment_python-0.2.0}/README.md +22 -2
- fragment_python-0.2.0/fragment/client/sync_client.py +67 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/codegen/helpers.py +10 -5
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/codegen/main.py +8 -1
- fragment_python-0.2.0/fragment/sync_sdk/__init__.py +478 -0
- fragment_python-0.2.0/fragment/sync_sdk/add_ledger_entry.py +54 -0
- fragment_python-0.2.0/fragment/sync_sdk/add_ledger_entry_runtime.py +54 -0
- fragment_python-0.2.0/fragment/sync_sdk/async_client.py +69 -0
- fragment_python-0.2.0/fragment/sync_sdk/base_model.py +29 -0
- fragment_python-0.2.0/fragment/sync_sdk/client.py +1071 -0
- fragment_python-0.2.0/fragment/sync_sdk/create_custom_link.py +40 -0
- fragment_python-0.2.0/fragment/sync_sdk/create_ledger.py +49 -0
- fragment_python-0.2.0/fragment/sync_sdk/enums.py +263 -0
- fragment_python-0.2.0/fragment/sync_sdk/get_ledger.py +23 -0
- fragment_python-0.2.0/fragment/sync_sdk/get_ledger_account_balance.py +23 -0
- fragment_python-0.2.0/fragment/sync_sdk/get_ledger_account_lines.py +47 -0
- fragment_python-0.2.0/fragment/sync_sdk/get_ledger_entry.py +41 -0
- fragment_python-0.2.0/fragment/sync_sdk/get_schema.py +28 -0
- fragment_python-0.2.0/fragment/sync_sdk/get_workspace.py +16 -0
- fragment_python-0.2.0/fragment/sync_sdk/input_types.py +482 -0
- fragment_python-0.2.0/fragment/sync_sdk/list_ledger_account_balances.py +53 -0
- fragment_python-0.2.0/fragment/sync_sdk/list_ledger_accounts.py +50 -0
- fragment_python-0.2.0/fragment/sync_sdk/list_ledger_entries.py +58 -0
- fragment_python-0.2.0/fragment/sync_sdk/list_ledger_entry_group_balances.py +57 -0
- fragment_python-0.2.0/fragment/sync_sdk/list_multi_currency_ledger_account_balances.py +130 -0
- fragment_python-0.2.0/fragment/sync_sdk/reconcile_tx.py +55 -0
- fragment_python-0.2.0/fragment/sync_sdk/reconcile_tx_runtime.py +55 -0
- fragment_python-0.2.0/fragment/sync_sdk/store_schema.py +45 -0
- fragment_python-0.2.0/fragment/sync_sdk/sync_custom_accounts.py +53 -0
- fragment_python-0.2.0/fragment/sync_sdk/sync_custom_txs.py +44 -0
- fragment_python-0.2.0/fragment/sync_sdk/update_ledger.py +39 -0
- fragment_python-0.2.0/fragment/sync_sdk/update_ledger_entry.py +77 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/pyproject.toml +1 -1
- {fragment_python-0.1.1 → fragment_python-0.2.0}/LICENSE +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/__init__.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/client/__init__.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/client/async_client.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/codegen/__init__.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/codegen/plugins/__init__.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/codegen/plugins/generate_client_method.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/codegen/plugins/get_file_comment.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/exceptions.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/logger.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/__init__.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/add_ledger_entry.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/add_ledger_entry_runtime.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/async_client.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/base_model.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/client.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/create_custom_link.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/create_ledger.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/enums.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/get_ledger.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/get_ledger_account_balance.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/get_ledger_account_lines.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/get_ledger_entry.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/get_schema.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/get_workspace.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/input_types.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/list_ledger_account_balances.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/list_ledger_accounts.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/list_ledger_entries.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/list_ledger_entry_group_balances.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/list_multi_currency_ledger_account_balances.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/reconcile_tx.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/reconcile_tx_runtime.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/store_schema.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/sync_custom_accounts.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/sync_custom_txs.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/update_ledger.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/sdk/update_ledger_entry.py +0 -0
- {fragment_python-0.1.1 → fragment_python-0.2.0}/fragment/std_queries/queries.graphql +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: fragment-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Python SDK for https://fragment.dev/
|
|
5
5
|
License: Apache 2.0
|
|
6
6
|
Author: Fragment Foundries Inc
|
|
@@ -63,6 +63,26 @@ loop.run_until_complete(print_schema())
|
|
|
63
63
|
|
|
64
64
|
Read the [Using custom queries](#using-custom-queries) section to learn how to use your own GraphQL queries with the SDK.
|
|
65
65
|
|
|
66
|
+
### Using a synchronous client
|
|
67
|
+
|
|
68
|
+
If you prefer using a synchronous client instead of an async one, then:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from fragment.sync_sdk.client import Client
|
|
72
|
+
|
|
73
|
+
graphql_client = Client(
|
|
74
|
+
client_id="<client id from the dashboard>",
|
|
75
|
+
client_secret="<client secret from the dashboard>",
|
|
76
|
+
api_url="<api url from the dashboard>",
|
|
77
|
+
auth_url="<auth url from the dashboard>",
|
|
78
|
+
auth_scope="<auth scope from the dashboard>",
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
get_schema_result = graphql_client.get_schema("<Your schema key here>")
|
|
82
|
+
print(get_schema_result.schema_.json())
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
|
|
66
86
|
## Examples
|
|
67
87
|
|
|
68
88
|
### Post a Ledger Entry
|
|
@@ -110,7 +130,7 @@ query getSchemaName($key: SafeString!) {
|
|
|
110
130
|
}
|
|
111
131
|
}
|
|
112
132
|
```
|
|
113
|
-
2. Run `fragment-python-client-codegen` to generate the GraphQL SDK client. GraphQL named queries are converted to snake_case to conform to Python's code conventions.
|
|
133
|
+
2. Run `fragment-python-client-codegen` to generate the GraphQL SDK client. GraphQL named queries are converted to snake_case to conform to Python's code conventions. Optionally, pass the `--sync` flag to generate a synchronous client instead of the default async GraphQL client.
|
|
114
134
|
```bash
|
|
115
135
|
fragment-python-client-codegen \
|
|
116
136
|
--input-dir queries/ \
|
|
@@ -132,7 +152,7 @@ graphql_client = Client(
|
|
|
132
152
|
|
|
133
153
|
async def print_schema_name():
|
|
134
154
|
# Note that getSchemaName is converted to snake_case automatically
|
|
135
|
-
response = await graphql_client.get_schema_name()
|
|
155
|
+
response = await graphql_client.get_schema_name("<Your Schema Key>")
|
|
136
156
|
print(response.schema_.key)
|
|
137
157
|
|
|
138
158
|
import asyncio
|
|
@@ -42,6 +42,26 @@ loop.run_until_complete(print_schema())
|
|
|
42
42
|
|
|
43
43
|
Read the [Using custom queries](#using-custom-queries) section to learn how to use your own GraphQL queries with the SDK.
|
|
44
44
|
|
|
45
|
+
### Using a synchronous client
|
|
46
|
+
|
|
47
|
+
If you prefer using a synchronous client instead of an async one, then:
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from fragment.sync_sdk.client import Client
|
|
51
|
+
|
|
52
|
+
graphql_client = Client(
|
|
53
|
+
client_id="<client id from the dashboard>",
|
|
54
|
+
client_secret="<client secret from the dashboard>",
|
|
55
|
+
api_url="<api url from the dashboard>",
|
|
56
|
+
auth_url="<auth url from the dashboard>",
|
|
57
|
+
auth_scope="<auth scope from the dashboard>",
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
get_schema_result = graphql_client.get_schema("<Your schema key here>")
|
|
61
|
+
print(get_schema_result.schema_.json())
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
|
|
45
65
|
## Examples
|
|
46
66
|
|
|
47
67
|
### Post a Ledger Entry
|
|
@@ -89,7 +109,7 @@ query getSchemaName($key: SafeString!) {
|
|
|
89
109
|
}
|
|
90
110
|
}
|
|
91
111
|
```
|
|
92
|
-
2. Run `fragment-python-client-codegen` to generate the GraphQL SDK client. GraphQL named queries are converted to snake_case to conform to Python's code conventions.
|
|
112
|
+
2. Run `fragment-python-client-codegen` to generate the GraphQL SDK client. GraphQL named queries are converted to snake_case to conform to Python's code conventions. Optionally, pass the `--sync` flag to generate a synchronous client instead of the default async GraphQL client.
|
|
93
113
|
```bash
|
|
94
114
|
fragment-python-client-codegen \
|
|
95
115
|
--input-dir queries/ \
|
|
@@ -111,7 +131,7 @@ graphql_client = Client(
|
|
|
111
131
|
|
|
112
132
|
async def print_schema_name():
|
|
113
133
|
# Note that getSchemaName is converted to snake_case automatically
|
|
114
|
-
response = await graphql_client.get_schema_name()
|
|
134
|
+
response = await graphql_client.get_schema_name("<Your Schema Key>")
|
|
115
135
|
print(response.schema_.key)
|
|
116
136
|
|
|
117
137
|
import asyncio
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Ignore untyped authlib
|
|
2
|
+
# mypy: disable-error-code="import-untyped"
|
|
3
|
+
import time
|
|
4
|
+
from typing import Any, Dict, Optional
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
from ariadne_codegen.client_generators.dependencies.base_client import (
|
|
8
|
+
BaseClient,
|
|
9
|
+
)
|
|
10
|
+
from authlib.integrations.httpx_client import OAuth2Client
|
|
11
|
+
|
|
12
|
+
from fragment.exceptions import MissingArgumentException, MissingTokenException
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SyncFragmentClient(BaseClient):
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
api_url: str = "",
|
|
19
|
+
auth_url: str = "",
|
|
20
|
+
auth_scope: str = "",
|
|
21
|
+
client_id: str = "",
|
|
22
|
+
client_secret: str = "",
|
|
23
|
+
http_client: Optional[httpx.AsyncClient] = None,
|
|
24
|
+
):
|
|
25
|
+
if api_url == "":
|
|
26
|
+
raise MissingArgumentException("api_url")
|
|
27
|
+
if auth_url == "":
|
|
28
|
+
raise MissingArgumentException("auth_url")
|
|
29
|
+
if auth_scope == "":
|
|
30
|
+
raise MissingArgumentException("auth_scope")
|
|
31
|
+
if client_id == "":
|
|
32
|
+
raise MissingArgumentException("client_id")
|
|
33
|
+
if client_secret == "":
|
|
34
|
+
raise MissingArgumentException("client_secret")
|
|
35
|
+
super().__init__(url=api_url, http_client=http_client)
|
|
36
|
+
|
|
37
|
+
self.auth_url = auth_url
|
|
38
|
+
self.expiration_time = None
|
|
39
|
+
self.token = None
|
|
40
|
+
self.oauth2_client = OAuth2Client(
|
|
41
|
+
client_id, client_secret, scope=auth_scope
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
def refresh_token(self):
|
|
45
|
+
now = time.time()
|
|
46
|
+
if self.expiration_time is None or self.expiration_time <= now:
|
|
47
|
+
self.token = self.oauth2_client.fetch_token(self.auth_url)
|
|
48
|
+
self.expiration_time = now + self.token["expires_in"]
|
|
49
|
+
|
|
50
|
+
def execute(
|
|
51
|
+
self,
|
|
52
|
+
query: str,
|
|
53
|
+
operation_name: Optional[str] = None,
|
|
54
|
+
variables: Optional[Dict[str, Any]] = None,
|
|
55
|
+
**kwargs: Any,
|
|
56
|
+
) -> httpx.Response:
|
|
57
|
+
self.refresh_token()
|
|
58
|
+
if self.token is None:
|
|
59
|
+
raise MissingTokenException()
|
|
60
|
+
headers = kwargs.get("headers", {})
|
|
61
|
+
kwargs.update(
|
|
62
|
+
headers={
|
|
63
|
+
"Authorization": f'Bearer {self.token["access_token"]}',
|
|
64
|
+
**headers,
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
return super().execute(query, operation_name, variables, **kwargs)
|
|
@@ -18,9 +18,15 @@ def get_codegen_config(
|
|
|
18
18
|
schema_path: str,
|
|
19
19
|
queries_path: str,
|
|
20
20
|
target_package_name: str,
|
|
21
|
-
target_package_path: Optional[str] = None
|
|
21
|
+
target_package_path: Optional[str] = None,
|
|
22
|
+
use_sync_client: bool = False,
|
|
22
23
|
) -> Dict:
|
|
23
24
|
"""Get the configuration for the codegen tool."""
|
|
25
|
+
client_name, file_path = (
|
|
26
|
+
("AsyncFragmentClient", "../../client/async_client.py")
|
|
27
|
+
if not use_sync_client
|
|
28
|
+
else ("SyncFragmentClient", "../../client/sync_client.py")
|
|
29
|
+
)
|
|
24
30
|
return dict(
|
|
25
31
|
tool={
|
|
26
32
|
"ariadne-codegen": dict(
|
|
@@ -30,10 +36,9 @@ def get_codegen_config(
|
|
|
30
36
|
target_package_path=(
|
|
31
37
|
target_package_path if target_package_path else Path.cwd()
|
|
32
38
|
),
|
|
33
|
-
base_client_name=
|
|
34
|
-
base_client_file_path=get_project_path_relative_to_file(
|
|
35
|
-
|
|
36
|
-
),
|
|
39
|
+
base_client_name=client_name,
|
|
40
|
+
base_client_file_path=get_project_path_relative_to_file(file_path),
|
|
41
|
+
async_client=False if use_sync_client else True,
|
|
37
42
|
plugins=[
|
|
38
43
|
"fragment.codegen.plugins.get_file_comment.GenerateFileComment",
|
|
39
44
|
"fragment.codegen.plugins.generate_client_method.RewriteUnsetTypeMethodArguments",
|
|
@@ -37,7 +37,13 @@ GRAPHQL_SCHEMA_API_URL = "https://api.us-west-2.fragment.dev/schema.graphql"
|
|
|
37
37
|
help="The output directory for the generated SDK. Defaults to CWD.",
|
|
38
38
|
required=False,
|
|
39
39
|
)
|
|
40
|
-
|
|
40
|
+
@click.option(
|
|
41
|
+
"--sync",
|
|
42
|
+
help="Generate a synchronous client. Defaults to async.",
|
|
43
|
+
required=False,
|
|
44
|
+
is_flag=True,
|
|
45
|
+
)
|
|
46
|
+
def run(input_dir, target_package_name, sync, output_dir=None):
|
|
41
47
|
console_log.info(f"Downloading the GraphQL schema from {GRAPHQL_SCHEMA_API_URL}")
|
|
42
48
|
try:
|
|
43
49
|
r = httpx.get(GRAPHQL_SCHEMA_API_URL)
|
|
@@ -53,6 +59,7 @@ def run(input_dir, target_package_name, output_dir=None):
|
|
|
53
59
|
standard_query_file.write(get_standard_queries())
|
|
54
60
|
standard_query_file.flush()
|
|
55
61
|
config_dict = get_codegen_config(
|
|
62
|
+
use_sync_client=sync,
|
|
56
63
|
schema_path=schema_file.name,
|
|
57
64
|
queries_path=input_dir,
|
|
58
65
|
target_package_name=target_package_name,
|