nadeshiko-sdk 0.1.0__py3-none-any.whl

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.
Files changed (167) hide show
  1. nadeshiko/__init__.py +10 -0
  2. nadeshiko/_version.py +1 -0
  3. nadeshiko/api/__init__.py +1 -0
  4. nadeshiko/api/auth/__init__.py +3 -0
  5. nadeshiko/api/auth/internal/__init__.py +11 -0
  6. nadeshiko/api/auth/internal/get_discord_auth_url.py +176 -0
  7. nadeshiko/api/auth/internal/login.py +213 -0
  8. nadeshiko/api/auth/internal/login_discord.py +204 -0
  9. nadeshiko/api/auth/internal/login_google.py +204 -0
  10. nadeshiko/api/auth/internal/register.py +212 -0
  11. nadeshiko/api/auth_jwt/__init__.py +3 -0
  12. nadeshiko/api/auth_jwt/internal/__init__.py +7 -0
  13. nadeshiko/api/auth_jwt/internal/logout.py +151 -0
  14. nadeshiko/api/lists/__init__.py +8 -0
  15. nadeshiko/api/lists/internal/__init__.py +12 -0
  16. nadeshiko/api/lists/internal/list_add_item.py +215 -0
  17. nadeshiko/api/lists/internal/list_create.py +194 -0
  18. nadeshiko/api/lists/internal/list_destroy.py +193 -0
  19. nadeshiko/api/lists/internal/list_remove_item.py +207 -0
  20. nadeshiko/api/lists/internal/list_update.py +215 -0
  21. nadeshiko/api/lists/internal/list_update_item.py +229 -0
  22. nadeshiko/api/lists/list_index.py +257 -0
  23. nadeshiko/api/lists/list_show.py +193 -0
  24. nadeshiko/api/media/__init__.py +14 -0
  25. nadeshiko/api/media/character_show.py +193 -0
  26. nadeshiko/api/media/episode_index.py +229 -0
  27. nadeshiko/api/media/episode_show.py +207 -0
  28. nadeshiko/api/media/internal/__init__.py +16 -0
  29. nadeshiko/api/media/internal/episode_create.py +215 -0
  30. nadeshiko/api/media/internal/episode_destroy.py +205 -0
  31. nadeshiko/api/media/internal/episode_update.py +229 -0
  32. nadeshiko/api/media/internal/media_create.py +194 -0
  33. nadeshiko/api/media/internal/media_destroy.py +197 -0
  34. nadeshiko/api/media/internal/media_update.py +219 -0
  35. nadeshiko/api/media/internal/segment_create.py +229 -0
  36. nadeshiko/api/media/internal/segment_destroy.py +219 -0
  37. nadeshiko/api/media/internal/segment_index.py +243 -0
  38. nadeshiko/api/media/internal/segment_update.py +243 -0
  39. nadeshiko/api/media/media_index.py +232 -0
  40. nadeshiko/api/media/media_show.py +193 -0
  41. nadeshiko/api/media/segment_show.py +221 -0
  42. nadeshiko/api/media/segment_show_by_uuid.py +193 -0
  43. nadeshiko/api/media/seiyuu_show.py +193 -0
  44. nadeshiko/api/search/__init__.py +11 -0
  45. nadeshiko/api/search/fetch_media_info.py +278 -0
  46. nadeshiko/api/search/fetch_sentence_context.py +219 -0
  47. nadeshiko/api/search/internal/__init__.py +6 -0
  48. nadeshiko/api/search/search.py +295 -0
  49. nadeshiko/api/search/search_health_check.py +168 -0
  50. nadeshiko/api/search/search_multiple.py +238 -0
  51. nadeshiko/api/user/__init__.py +3 -0
  52. nadeshiko/api/user/internal/__init__.py +11 -0
  53. nadeshiko/api/user/internal/create_api_key.py +199 -0
  54. nadeshiko/api/user/internal/deactivate_api_key.py +194 -0
  55. nadeshiko/api/user/internal/get_api_keys.py +151 -0
  56. nadeshiko/api/user/internal/get_identity_me.py +156 -0
  57. nadeshiko/api/user/internal/get_user_info.py +156 -0
  58. nadeshiko/client.py +138 -0
  59. nadeshiko/errors.py +16 -0
  60. nadeshiko/models/__init__.py +215 -0
  61. nadeshiko/models/api_key.py +118 -0
  62. nadeshiko/models/api_key_permission.py +70 -0
  63. nadeshiko/models/auth_user.py +107 -0
  64. nadeshiko/models/basic_info.py +132 -0
  65. nadeshiko/models/category_statistic.py +71 -0
  66. nadeshiko/models/character.py +100 -0
  67. nadeshiko/models/character_input.py +130 -0
  68. nadeshiko/models/character_input_character_role.py +10 -0
  69. nadeshiko/models/character_with_media.py +124 -0
  70. nadeshiko/models/character_with_media_media_appearances_item.py +93 -0
  71. nadeshiko/models/character_with_media_media_appearances_item_role.py +10 -0
  72. nadeshiko/models/create_api_key_request.py +75 -0
  73. nadeshiko/models/create_api_key_response.py +70 -0
  74. nadeshiko/models/deactivate_api_key_request.py +62 -0
  75. nadeshiko/models/deactivate_api_key_response.py +62 -0
  76. nadeshiko/models/discord_auth_url_response.py +62 -0
  77. nadeshiko/models/discord_login_request.py +62 -0
  78. nadeshiko/models/episode.py +253 -0
  79. nadeshiko/models/episode_create_request.py +145 -0
  80. nadeshiko/models/episode_list_response.py +94 -0
  81. nadeshiko/models/episode_update_request.py +135 -0
  82. nadeshiko/models/error.py +128 -0
  83. nadeshiko/models/error_errors.py +46 -0
  84. nadeshiko/models/fetch_media_info_response.py +115 -0
  85. nadeshiko/models/fetch_media_info_type.py +10 -0
  86. nadeshiko/models/fetch_sentence_context_request.py +96 -0
  87. nadeshiko/models/fetch_sentence_context_response.py +75 -0
  88. nadeshiko/models/get_api_keys_response.py +86 -0
  89. nadeshiko/models/google_login_request.py +62 -0
  90. nadeshiko/models/list_.py +97 -0
  91. nadeshiko/models/list_add_item_body.py +69 -0
  92. nadeshiko/models/list_add_item_response_201.py +61 -0
  93. nadeshiko/models/list_create_request.py +107 -0
  94. nadeshiko/models/list_create_request_type.py +9 -0
  95. nadeshiko/models/list_create_request_visibility.py +9 -0
  96. nadeshiko/models/list_destroy_response_200.py +70 -0
  97. nadeshiko/models/list_index_type.py +9 -0
  98. nadeshiko/models/list_index_visibility.py +9 -0
  99. nadeshiko/models/list_input.py +138 -0
  100. nadeshiko/models/list_input_list_type.py +9 -0
  101. nadeshiko/models/list_input_list_visibility.py +9 -0
  102. nadeshiko/models/list_remove_item_response_200.py +61 -0
  103. nadeshiko/models/list_type.py +9 -0
  104. nadeshiko/models/list_update_body.py +78 -0
  105. nadeshiko/models/list_update_body_visibility.py +9 -0
  106. nadeshiko/models/list_update_item_body.py +61 -0
  107. nadeshiko/models/list_update_item_response_200.py +61 -0
  108. nadeshiko/models/list_visibility.py +9 -0
  109. nadeshiko/models/list_with_media.py +119 -0
  110. nadeshiko/models/list_with_media_media_item.py +83 -0
  111. nadeshiko/models/list_with_media_type.py +9 -0
  112. nadeshiko/models/list_with_media_visibility.py +9 -0
  113. nadeshiko/models/login_request.py +70 -0
  114. nadeshiko/models/login_response.py +84 -0
  115. nadeshiko/models/logout_response.py +73 -0
  116. nadeshiko/models/media.py +288 -0
  117. nadeshiko/models/media_category.py +11 -0
  118. nadeshiko/models/media_character.py +78 -0
  119. nadeshiko/models/media_character_role.py +10 -0
  120. nadeshiko/models/media_create_request.py +270 -0
  121. nadeshiko/models/media_create_request_category.py +11 -0
  122. nadeshiko/models/media_destroy_response_200.py +70 -0
  123. nadeshiko/models/media_index_category.py +9 -0
  124. nadeshiko/models/media_info_data.py +307 -0
  125. nadeshiko/models/media_info_path.py +83 -0
  126. nadeshiko/models/media_info_stats.py +89 -0
  127. nadeshiko/models/media_list_response.py +94 -0
  128. nadeshiko/models/media_update_request.py +297 -0
  129. nadeshiko/models/media_update_request_category.py +9 -0
  130. nadeshiko/models/quota_info.py +87 -0
  131. nadeshiko/models/quota_info_quota_limit_type_1.py +8 -0
  132. nadeshiko/models/register_request.py +78 -0
  133. nadeshiko/models/register_response.py +76 -0
  134. nadeshiko/models/register_response_user.py +46 -0
  135. nadeshiko/models/search_health_check_response.py +138 -0
  136. nadeshiko/models/search_multiple_request.py +72 -0
  137. nadeshiko/models/search_multiple_response.py +79 -0
  138. nadeshiko/models/search_request.py +253 -0
  139. nadeshiko/models/search_request_content_sort.py +13 -0
  140. nadeshiko/models/search_request_media_item.py +85 -0
  141. nadeshiko/models/search_request_media_item_seasons_item.py +69 -0
  142. nadeshiko/models/search_response.py +158 -0
  143. nadeshiko/models/segment.py +303 -0
  144. nadeshiko/models/segment_create_request.py +203 -0
  145. nadeshiko/models/segment_create_request_status.py +13 -0
  146. nadeshiko/models/segment_info.py +207 -0
  147. nadeshiko/models/segment_list_response.py +94 -0
  148. nadeshiko/models/segment_status.py +13 -0
  149. nadeshiko/models/segment_update_request.py +198 -0
  150. nadeshiko/models/segment_update_request_status.py +13 -0
  151. nadeshiko/models/seiyuu.py +86 -0
  152. nadeshiko/models/seiyuu_with_roles.py +108 -0
  153. nadeshiko/models/seiyuu_with_roles_roles_item.py +109 -0
  154. nadeshiko/models/seiyuu_with_roles_roles_item_role.py +10 -0
  155. nadeshiko/models/sentence.py +88 -0
  156. nadeshiko/models/statistic.py +132 -0
  157. nadeshiko/models/statistic_season_with_episode_hits.py +74 -0
  158. nadeshiko/models/statistic_season_with_episode_hits_additional_property.py +46 -0
  159. nadeshiko/models/user_info_response.py +79 -0
  160. nadeshiko/models/user_info_response_user.py +91 -0
  161. nadeshiko/models/user_role.py +71 -0
  162. nadeshiko/models/word_match.py +107 -0
  163. nadeshiko/models/word_match_media.py +98 -0
  164. nadeshiko/types.py +54 -0
  165. nadeshiko_sdk-0.1.0.dist-info/METADATA +147 -0
  166. nadeshiko_sdk-0.1.0.dist-info/RECORD +167 -0
  167. nadeshiko_sdk-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,151 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+
4
+ import httpx
5
+
6
+ from .... import errors
7
+ from ....client import AuthenticatedClient, Client
8
+ from ....models.error import Error
9
+ from ....models.get_api_keys_response import GetApiKeysResponse
10
+ from ....types import Response
11
+
12
+
13
+ def _get_kwargs() -> dict[str, Any]:
14
+ _kwargs: dict[str, Any] = {
15
+ "method": "post",
16
+ "url": "/v1/user/getApiKeys",
17
+ }
18
+
19
+ return _kwargs
20
+
21
+
22
+ def _parse_response(
23
+ *, client: AuthenticatedClient | Client, response: httpx.Response
24
+ ) -> Error | GetApiKeysResponse | None:
25
+ if response.status_code == 200:
26
+ response_200 = GetApiKeysResponse.from_dict(response.json())
27
+
28
+ return response_200
29
+
30
+ if response.status_code == 401:
31
+ response_401 = Error.from_dict(response.json())
32
+
33
+ return response_401
34
+
35
+ if response.status_code == 429:
36
+ response_429 = Error.from_dict(response.json())
37
+
38
+ return response_429
39
+
40
+ if response.status_code == 500:
41
+ response_500 = Error.from_dict(response.json())
42
+
43
+ return response_500
44
+
45
+ if client.raise_on_unexpected_status:
46
+ raise errors.UnexpectedStatus(response.status_code, response.content)
47
+ else:
48
+ return None
49
+
50
+
51
+ def _build_response(
52
+ *, client: AuthenticatedClient | Client, response: httpx.Response
53
+ ) -> Response[Error | GetApiKeysResponse]:
54
+ return Response(
55
+ status_code=HTTPStatus(response.status_code),
56
+ content=response.content,
57
+ headers=response.headers,
58
+ parsed=_parse_response(client=client, response=response),
59
+ )
60
+
61
+
62
+ def sync_detailed(
63
+ *,
64
+ client: AuthenticatedClient,
65
+ ) -> Response[Error | GetApiKeysResponse]:
66
+ """Get API keys
67
+
68
+ Get all API keys for the authenticated user
69
+
70
+ Raises:
71
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
72
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
73
+
74
+ Returns:
75
+ Response[Error | GetApiKeysResponse]
76
+ """
77
+
78
+ kwargs = _get_kwargs()
79
+
80
+ response = client.get_httpx_client().request(
81
+ **kwargs,
82
+ )
83
+
84
+ return _build_response(client=client, response=response)
85
+
86
+
87
+ def sync(
88
+ *,
89
+ client: AuthenticatedClient,
90
+ ) -> Error | GetApiKeysResponse | None:
91
+ """Get API keys
92
+
93
+ Get all API keys for the authenticated user
94
+
95
+ Raises:
96
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
97
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
98
+
99
+ Returns:
100
+ Error | GetApiKeysResponse
101
+ """
102
+
103
+ return sync_detailed(
104
+ client=client,
105
+ ).parsed
106
+
107
+
108
+ async def asyncio_detailed(
109
+ *,
110
+ client: AuthenticatedClient,
111
+ ) -> Response[Error | GetApiKeysResponse]:
112
+ """Get API keys
113
+
114
+ Get all API keys for the authenticated user
115
+
116
+ Raises:
117
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
118
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
119
+
120
+ Returns:
121
+ Response[Error | GetApiKeysResponse]
122
+ """
123
+
124
+ kwargs = _get_kwargs()
125
+
126
+ response = await client.get_async_httpx_client().request(**kwargs)
127
+
128
+ return _build_response(client=client, response=response)
129
+
130
+
131
+ async def asyncio(
132
+ *,
133
+ client: AuthenticatedClient,
134
+ ) -> Error | GetApiKeysResponse | None:
135
+ """Get API keys
136
+
137
+ Get all API keys for the authenticated user
138
+
139
+ Raises:
140
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
141
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
142
+
143
+ Returns:
144
+ Error | GetApiKeysResponse
145
+ """
146
+
147
+ return (
148
+ await asyncio_detailed(
149
+ client=client,
150
+ )
151
+ ).parsed
@@ -0,0 +1,156 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+
4
+ import httpx
5
+
6
+ from .... import errors
7
+ from ....client import AuthenticatedClient, Client
8
+ from ....models.error import Error
9
+ from ....models.user_info_response import UserInfoResponse
10
+ from ....types import Response
11
+
12
+
13
+ def _get_kwargs() -> dict[str, Any]:
14
+ _kwargs: dict[str, Any] = {
15
+ "method": "get",
16
+ "url": "/v1/auth/identity/me",
17
+ }
18
+
19
+ return _kwargs
20
+
21
+
22
+ def _parse_response(
23
+ *, client: AuthenticatedClient | Client, response: httpx.Response
24
+ ) -> Error | UserInfoResponse | None:
25
+ if response.status_code == 200:
26
+ response_200 = UserInfoResponse.from_dict(response.json())
27
+
28
+ return response_200
29
+
30
+ if response.status_code == 401:
31
+ response_401 = Error.from_dict(response.json())
32
+
33
+ return response_401
34
+
35
+ if response.status_code == 404:
36
+ response_404 = Error.from_dict(response.json())
37
+
38
+ return response_404
39
+
40
+ if response.status_code == 429:
41
+ response_429 = Error.from_dict(response.json())
42
+
43
+ return response_429
44
+
45
+ if response.status_code == 500:
46
+ response_500 = Error.from_dict(response.json())
47
+
48
+ return response_500
49
+
50
+ if client.raise_on_unexpected_status:
51
+ raise errors.UnexpectedStatus(response.status_code, response.content)
52
+ else:
53
+ return None
54
+
55
+
56
+ def _build_response(
57
+ *, client: AuthenticatedClient | Client, response: httpx.Response
58
+ ) -> Response[Error | UserInfoResponse]:
59
+ return Response(
60
+ status_code=HTTPStatus(response.status_code),
61
+ content=response.content,
62
+ headers=response.headers,
63
+ parsed=_parse_response(client=client, response=response),
64
+ )
65
+
66
+
67
+ def sync_detailed(
68
+ *,
69
+ client: AuthenticatedClient,
70
+ ) -> Response[Error | UserInfoResponse]:
71
+ """Get current identity
72
+
73
+ Get information about the currently authenticated user (alternative endpoint)
74
+
75
+ Raises:
76
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
77
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
78
+
79
+ Returns:
80
+ Response[Error | UserInfoResponse]
81
+ """
82
+
83
+ kwargs = _get_kwargs()
84
+
85
+ response = client.get_httpx_client().request(
86
+ **kwargs,
87
+ )
88
+
89
+ return _build_response(client=client, response=response)
90
+
91
+
92
+ def sync(
93
+ *,
94
+ client: AuthenticatedClient,
95
+ ) -> Error | UserInfoResponse | None:
96
+ """Get current identity
97
+
98
+ Get information about the currently authenticated user (alternative endpoint)
99
+
100
+ Raises:
101
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
102
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
103
+
104
+ Returns:
105
+ Error | UserInfoResponse
106
+ """
107
+
108
+ return sync_detailed(
109
+ client=client,
110
+ ).parsed
111
+
112
+
113
+ async def asyncio_detailed(
114
+ *,
115
+ client: AuthenticatedClient,
116
+ ) -> Response[Error | UserInfoResponse]:
117
+ """Get current identity
118
+
119
+ Get information about the currently authenticated user (alternative endpoint)
120
+
121
+ Raises:
122
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
123
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
124
+
125
+ Returns:
126
+ Response[Error | UserInfoResponse]
127
+ """
128
+
129
+ kwargs = _get_kwargs()
130
+
131
+ response = await client.get_async_httpx_client().request(**kwargs)
132
+
133
+ return _build_response(client=client, response=response)
134
+
135
+
136
+ async def asyncio(
137
+ *,
138
+ client: AuthenticatedClient,
139
+ ) -> Error | UserInfoResponse | None:
140
+ """Get current identity
141
+
142
+ Get information about the currently authenticated user (alternative endpoint)
143
+
144
+ Raises:
145
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
146
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
147
+
148
+ Returns:
149
+ Error | UserInfoResponse
150
+ """
151
+
152
+ return (
153
+ await asyncio_detailed(
154
+ client=client,
155
+ )
156
+ ).parsed
@@ -0,0 +1,156 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+
4
+ import httpx
5
+
6
+ from .... import errors
7
+ from ....client import AuthenticatedClient, Client
8
+ from ....models.error import Error
9
+ from ....models.user_info_response import UserInfoResponse
10
+ from ....types import Response
11
+
12
+
13
+ def _get_kwargs() -> dict[str, Any]:
14
+ _kwargs: dict[str, Any] = {
15
+ "method": "post",
16
+ "url": "/v1/jwt/user/info",
17
+ }
18
+
19
+ return _kwargs
20
+
21
+
22
+ def _parse_response(
23
+ *, client: AuthenticatedClient | Client, response: httpx.Response
24
+ ) -> Error | UserInfoResponse | None:
25
+ if response.status_code == 200:
26
+ response_200 = UserInfoResponse.from_dict(response.json())
27
+
28
+ return response_200
29
+
30
+ if response.status_code == 401:
31
+ response_401 = Error.from_dict(response.json())
32
+
33
+ return response_401
34
+
35
+ if response.status_code == 404:
36
+ response_404 = Error.from_dict(response.json())
37
+
38
+ return response_404
39
+
40
+ if response.status_code == 429:
41
+ response_429 = Error.from_dict(response.json())
42
+
43
+ return response_429
44
+
45
+ if response.status_code == 500:
46
+ response_500 = Error.from_dict(response.json())
47
+
48
+ return response_500
49
+
50
+ if client.raise_on_unexpected_status:
51
+ raise errors.UnexpectedStatus(response.status_code, response.content)
52
+ else:
53
+ return None
54
+
55
+
56
+ def _build_response(
57
+ *, client: AuthenticatedClient | Client, response: httpx.Response
58
+ ) -> Response[Error | UserInfoResponse]:
59
+ return Response(
60
+ status_code=HTTPStatus(response.status_code),
61
+ content=response.content,
62
+ headers=response.headers,
63
+ parsed=_parse_response(client=client, response=response),
64
+ )
65
+
66
+
67
+ def sync_detailed(
68
+ *,
69
+ client: AuthenticatedClient,
70
+ ) -> Response[Error | UserInfoResponse]:
71
+ """Get user info
72
+
73
+ Get information about the currently authenticated user
74
+
75
+ Raises:
76
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
77
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
78
+
79
+ Returns:
80
+ Response[Error | UserInfoResponse]
81
+ """
82
+
83
+ kwargs = _get_kwargs()
84
+
85
+ response = client.get_httpx_client().request(
86
+ **kwargs,
87
+ )
88
+
89
+ return _build_response(client=client, response=response)
90
+
91
+
92
+ def sync(
93
+ *,
94
+ client: AuthenticatedClient,
95
+ ) -> Error | UserInfoResponse | None:
96
+ """Get user info
97
+
98
+ Get information about the currently authenticated user
99
+
100
+ Raises:
101
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
102
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
103
+
104
+ Returns:
105
+ Error | UserInfoResponse
106
+ """
107
+
108
+ return sync_detailed(
109
+ client=client,
110
+ ).parsed
111
+
112
+
113
+ async def asyncio_detailed(
114
+ *,
115
+ client: AuthenticatedClient,
116
+ ) -> Response[Error | UserInfoResponse]:
117
+ """Get user info
118
+
119
+ Get information about the currently authenticated user
120
+
121
+ Raises:
122
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
123
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
124
+
125
+ Returns:
126
+ Response[Error | UserInfoResponse]
127
+ """
128
+
129
+ kwargs = _get_kwargs()
130
+
131
+ response = await client.get_async_httpx_client().request(**kwargs)
132
+
133
+ return _build_response(client=client, response=response)
134
+
135
+
136
+ async def asyncio(
137
+ *,
138
+ client: AuthenticatedClient,
139
+ ) -> Error | UserInfoResponse | None:
140
+ """Get user info
141
+
142
+ Get information about the currently authenticated user
143
+
144
+ Raises:
145
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
146
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
147
+
148
+ Returns:
149
+ Error | UserInfoResponse
150
+ """
151
+
152
+ return (
153
+ await asyncio_detailed(
154
+ client=client,
155
+ )
156
+ ).parsed
nadeshiko/client.py ADDED
@@ -0,0 +1,138 @@
1
+ import ssl
2
+ from enum import Enum
3
+ from typing import Any
4
+
5
+ import httpx
6
+ from attrs import define, evolve, field
7
+
8
+
9
+ class Environment(Enum):
10
+ """API environment presets."""
11
+
12
+ LOCAL = "http://localhost:5000"
13
+ PRODUCTION = "https://api.nadeshiko.co"
14
+
15
+
16
+ def _resolve_base_url(base_url: str | Environment) -> str:
17
+ """Resolve environment enum to URL, or return URL string as-is."""
18
+ if isinstance(base_url, Environment):
19
+ return base_url.value
20
+ return base_url
21
+
22
+
23
+ @define
24
+ class Nadeshiko:
25
+ """Nadeshiko API client.
26
+
27
+ Example:
28
+ >>> from nadeshiko import Nadeshiko, Environment
29
+ >>> from nadeshiko.api.search import search
30
+ >>>
31
+ >>> client = Nadeshiko(api_key="your-key")
32
+ >>> result = search.sync(client=client, body={"query": "..."})
33
+
34
+ Args:
35
+ api_key: Your Nadeshiko API key
36
+ base_url: API environment (Environment.PRODUCTION, Environment.LOCAL) or custom URL string
37
+ timeout: Request timeout
38
+ verify_ssl: Whether to verify SSL certificates
39
+ follow_redirects: Whether to follow redirects
40
+ raise_on_unexpected_status: Whether to raise on unexpected status codes
41
+ httpx_args: Additional arguments for httpx.Client
42
+ """
43
+
44
+ _api_key: str = field(alias="api_key")
45
+ _base_url: str | Environment = field(default=Environment.PRODUCTION, alias="base_url")
46
+ _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
47
+ _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
48
+ _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout")
49
+ _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl")
50
+ _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
51
+ _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
52
+ _raise_on_unexpected_status: bool = field(
53
+ default=False, kw_only=True, alias="raise_on_unexpected_status"
54
+ )
55
+ _client: httpx.Client | None = field(default=None, init=False)
56
+ _async_client: httpx.AsyncClient | None = field(default=None, init=False)
57
+
58
+ @property
59
+ def raise_on_unexpected_status(self) -> bool:
60
+ """Whether to raise on unexpected status codes."""
61
+ return self._raise_on_unexpected_status
62
+
63
+ def with_headers(self, headers: dict[str, str]) -> "Nadeshiko":
64
+ """Get a new client matching this one with additional headers."""
65
+ if self._client is not None:
66
+ self._client.headers.update(headers)
67
+ if self._async_client is not None:
68
+ self._async_client.headers.update(headers)
69
+ return evolve(self, headers={**self._headers, **headers})
70
+
71
+ def with_cookies(self, cookies: dict[str, str]) -> "Nadeshiko":
72
+ """Get a new client matching this one with additional cookies."""
73
+ if self._client is not None:
74
+ self._client.cookies.update(cookies)
75
+ if self._async_client is not None:
76
+ self._async_client.cookies.update(cookies)
77
+ return evolve(self, cookies={**self._cookies, **cookies})
78
+
79
+ def with_timeout(self, timeout: httpx.Timeout) -> "Nadeshiko":
80
+ """Get a new client matching this one with a new timeout configuration."""
81
+ if self._client is not None:
82
+ self._client.timeout = timeout
83
+ if self._async_client is not None:
84
+ self._async_client.timeout = timeout
85
+ return evolve(self, timeout=timeout)
86
+
87
+ # Internal methods required by generated API functions
88
+ # These are not part of the public API
89
+
90
+ def set_httpx_client(self, client: httpx.Client) -> "Nadeshiko":
91
+ self._client = client
92
+ return self
93
+
94
+ def get_httpx_client(self) -> httpx.Client:
95
+ if self._client is None:
96
+ headers = {**self._headers, "X-API-Key": self._api_key}
97
+ self._client = httpx.Client(
98
+ base_url=_resolve_base_url(self._base_url),
99
+ cookies=self._cookies,
100
+ headers=headers,
101
+ timeout=self._timeout,
102
+ verify=self._verify_ssl,
103
+ follow_redirects=self._follow_redirects,
104
+ **self._httpx_args,
105
+ )
106
+ return self._client
107
+
108
+ def __enter__(self) -> "Nadeshiko":
109
+ self.get_httpx_client().__enter__()
110
+ return self
111
+
112
+ def __exit__(self, *args: Any, **kwargs: Any) -> None:
113
+ self.get_httpx_client().__exit__(*args, **kwargs)
114
+
115
+ def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Nadeshiko":
116
+ self._async_client = async_client
117
+ return self
118
+
119
+ def get_async_httpx_client(self) -> httpx.AsyncClient:
120
+ if self._async_client is None:
121
+ headers = {**self._headers, "X-API-Key": self._api_key}
122
+ self._async_client = httpx.AsyncClient(
123
+ base_url=_resolve_base_url(self._base_url),
124
+ cookies=self._cookies,
125
+ headers=headers,
126
+ timeout=self._timeout,
127
+ verify=self._verify_ssl,
128
+ follow_redirects=self._follow_redirects,
129
+ **self._httpx_args,
130
+ )
131
+ return self._async_client
132
+
133
+ async def __aenter__(self) -> "Nadeshiko":
134
+ await self.get_async_httpx_client().__aenter__()
135
+ return self
136
+
137
+ async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
138
+ await self.get_async_httpx_client().__aexit__(*args, **kwargs)
nadeshiko/errors.py ADDED
@@ -0,0 +1,16 @@
1
+ """Contains shared errors types that can be raised from API functions"""
2
+
3
+
4
+ class UnexpectedStatus(Exception):
5
+ """Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True"""
6
+
7
+ def __init__(self, status_code: int, content: bytes):
8
+ self.status_code = status_code
9
+ self.content = content
10
+
11
+ super().__init__(
12
+ f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
13
+ )
14
+
15
+
16
+ __all__ = ["UnexpectedStatus"]