rushdb 1.2.0__tar.gz → 1.4.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rushdb
3
- Version: 1.2.0
3
+ Version: 1.4.0
4
4
  Summary: RushDB Python SDK
5
5
  Home-page: https://github.com/rushdb/rushdb-python
6
6
  License: Apache-2.0
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "rushdb"
3
- version = "1.2.0"
3
+ version = "1.4.0"
4
4
  description = "RushDB Python SDK"
5
5
  authors = ["RushDB Team <hi@rushdb.com>"]
6
6
  license = "Apache-2.0"
@@ -0,0 +1,87 @@
1
+ import typing
2
+ from typing import List, Optional
3
+
4
+ from ..models.search_query import SearchQuery
5
+ from ..models.transaction import Transaction
6
+ from .base import BaseAPI
7
+
8
+
9
+ class LabelsAPI(BaseAPI):
10
+ """API client for managing labels in RushDB.
11
+
12
+ The LabelsAPI provides functionality for discovering and working with record labels
13
+ in the database. Labels are used to categorize and type records, similar to table
14
+ names in relational databases or document types in NoSQL databases.
15
+
16
+ This class handles:
17
+ - Label discovery and listing
18
+ - Label searching and filtering
19
+ - Transaction support for operations
20
+
21
+ Labels help organize and categorize records, making it easier to query and
22
+ understand the structure of data within the database.
23
+
24
+ Attributes:
25
+ client: The underlying RushDB client instance for making HTTP requests.
26
+
27
+ Example:
28
+ >>> from rushdb import RushDB
29
+ >>> client = RushDB(api_key="your_api_key")
30
+ >>> labels_api = client.labels
31
+ >>>
32
+ >>> # Get all labels in the database
33
+ >>> all_labels = labels_api.find()
34
+ >>> print("Available labels:", all_labels)
35
+ >>>
36
+ >>> # Search for specific labels
37
+ >>> from rushdb.models.search_query import SearchQuery
38
+ >>> query = SearchQuery(where={"name":{"$contains": "alice"}})
39
+ >>> user_labels = labels_api.find(query)
40
+ """
41
+
42
+ def find(
43
+ self,
44
+ search_query: Optional[SearchQuery] = None,
45
+ transaction: Optional[Transaction] = None,
46
+ ) -> List[str]:
47
+ """Search for and retrieve labels matching the specified criteria.
48
+
49
+ Discovers labels (record types) that exist in the database and can optionally
50
+ filter them based on search criteria. Labels represent the different types
51
+ or categories of records stored in the database.
52
+
53
+ Args:
54
+ search_query (Optional[SearchQuery], optional): The search criteria to filter labels.
55
+ If None, returns all labels in the database. Can include filters for
56
+ label names, patterns, or other metadata. Defaults to None.
57
+ transaction (Optional[Transaction], optional): Transaction context for the operation.
58
+ If provided, the operation will be part of the transaction. Defaults to None.
59
+
60
+ Returns:
61
+ List[str]: List of label names (strings) matching the search criteria.
62
+ Each string represents a unique label/type used in the database.
63
+
64
+ Raises:
65
+ RequestError: If the server request fails.
66
+
67
+ Example:
68
+ >>> from rushdb.models.search_query import SearchQuery
69
+ >>> labels_api = LabelsAPI(client)
70
+ >>>
71
+ >>> # Get all labels
72
+ >>> all_labels = labels_api.find()
73
+ >>> print("Database contains these record types:", all_labels)
74
+ >>>
75
+ >>> # Search for labels amongst records matching a pattern
76
+ >>> query = SearchQuery(where={"name":{"$contains": "alice"}})
77
+ >>> user_labels = labels_api.find(query)
78
+ >>> print("User-related labels:", user_labels)
79
+ """
80
+ headers = Transaction._build_transaction_header(transaction)
81
+
82
+ return self.client._make_request(
83
+ "POST",
84
+ "/labels/search",
85
+ data=typing.cast(typing.Dict[str, typing.Any], search_query or {}),
86
+ headers=headers,
87
+ )
@@ -0,0 +1,215 @@
1
+ import typing
2
+ from typing import List, Optional
3
+
4
+ from ..models.property import Property, PropertyValuesData
5
+ from ..models.search_query import SearchQuery
6
+ from ..models.transaction import Transaction
7
+ from .base import BaseAPI
8
+
9
+
10
+ class PropertyValuesQuery(SearchQuery, total=False):
11
+ """Extended SearchQuery for property values endpoint with text search support.
12
+
13
+ This class extends the base SearchQuery to include additional search capabilities
14
+ specifically for querying property values, including text-based search functionality.
15
+
16
+ Attributes:
17
+ query (Optional[str]): Text search string to filter property values.
18
+ When provided, performs a text-based search among the property values.
19
+ """
20
+
21
+ query: Optional[str] # For text search among values
22
+
23
+
24
+ class PropertiesAPI(BaseAPI):
25
+ """API client for managing properties in RushDB.
26
+
27
+ The PropertiesAPI provides functionality for working with database properties,
28
+ including searching for properties, retrieving individual properties by ID,
29
+ deleting properties, and querying property values. Properties represent
30
+ metadata about the structure and characteristics of data in the database.
31
+
32
+ This class handles:
33
+ - Property discovery and searching
34
+ - Individual property retrieval
35
+ - Property deletion
36
+ - Property values querying with text search capabilities
37
+ - Transaction support for all operations
38
+
39
+ Attributes:
40
+ client: The underlying RushDB client instance for making HTTP requests.
41
+
42
+ Example:
43
+ >>> from rushdb import RushDB
44
+ >>> client = RushDB(api_key="your_api_key")
45
+ >>> properties_api = client.properties
46
+ >>>
47
+ >>> # Find all properties
48
+ >>> properties = properties_api.find()
49
+ >>>
50
+ >>> # Get a specific property
51
+ >>> property_obj = properties_api.find_by_id("property_123")
52
+ """
53
+
54
+ def find(
55
+ self,
56
+ search_query: Optional[SearchQuery] = None,
57
+ transaction: Optional[Transaction] = None,
58
+ ) -> List[Property]:
59
+ """Search for and retrieve properties matching the specified criteria.
60
+
61
+ Searches the database for properties that match the provided search query.
62
+ Properties represent metadata about the database structure and can be
63
+ filtered using various search criteria.
64
+
65
+ Args:
66
+ search_query (Optional[SearchQuery], optional): The search criteria to filter properties.
67
+ If None, returns all properties. Can include filters for property names,
68
+ types, or other metadata. Defaults to None.
69
+ transaction (Optional[Transaction], optional): Transaction context for the operation.
70
+ If provided, the operation will be part of the transaction. Defaults to None.
71
+
72
+ Returns:
73
+ List[Property]: List of Property objects matching the search criteria.
74
+
75
+ Raises:
76
+ RequestError: If the server request fails.
77
+
78
+ Example:
79
+ >>> from rushdb.models.search_query import SearchQuery
80
+ >>> properties_api = PropertiesAPI(client)
81
+ >>>
82
+ >>> # Find all properties
83
+ >>> all_properties = properties_api.find()
84
+ >>>
85
+ >>> # Find properties with specific criteria
86
+ >>> query = SearchQuery(where={"age":{"$gte": 30}})
87
+ >>> string_properties = properties_api.find(query)
88
+ """
89
+ headers = Transaction._build_transaction_header(transaction)
90
+
91
+ return self.client._make_request(
92
+ "POST",
93
+ "/properties/search",
94
+ typing.cast(typing.Dict[str, typing.Any], search_query or {}),
95
+ headers,
96
+ )
97
+
98
+ def find_by_id(
99
+ self, property_id: str, transaction: Optional[Transaction] = None
100
+ ) -> Property:
101
+ """Retrieve a specific property by its unique identifier.
102
+
103
+ Fetches a single property from the database using its unique ID.
104
+ This method is useful when you know the exact property you want to retrieve.
105
+
106
+ Args:
107
+ property_id (str): The unique identifier of the property to retrieve.
108
+ transaction (Optional[Transaction], optional): Transaction context for the operation.
109
+ If provided, the operation will be part of the transaction. Defaults to None.
110
+
111
+ Returns:
112
+ Property: The Property object with the specified ID.
113
+
114
+ Raises:
115
+ ValueError: If the property_id is invalid or empty.
116
+ NotFoundError: If no property exists with the specified ID.
117
+ RequestError: If the server request fails.
118
+
119
+ Example:
120
+ >>> properties_api = PropertiesAPI(client)
121
+ >>> property_obj = properties_api.find_by_id("prop_123")
122
+ >>> print(property_obj.name)
123
+ """
124
+ headers = Transaction._build_transaction_header(transaction)
125
+
126
+ return self.client._make_request(
127
+ "GET", f"/properties/{property_id}", headers=headers
128
+ )
129
+
130
+ def delete(
131
+ self, property_id: str, transaction: Optional[Transaction] = None
132
+ ) -> None:
133
+ """Delete a property from the database.
134
+
135
+ Permanently removes a property and all its associated metadata from the database.
136
+ This operation cannot be undone, so use with caution.
137
+
138
+ Args:
139
+ property_id (str): The unique identifier of the property to delete.
140
+ transaction (Optional[Transaction], optional): Transaction context for the operation.
141
+ If provided, the operation will be part of the transaction. Defaults to None.
142
+
143
+ Returns:
144
+ None: This method does not return a value.
145
+
146
+ Raises:
147
+ ValueError: If the property_id is invalid or empty.
148
+ NotFoundError: If no property exists with the specified ID.
149
+ RequestError: If the server request fails.
150
+
151
+ Warning:
152
+ This operation permanently deletes the property and cannot be undone.
153
+ Ensure you have proper backups and confirmation before deleting properties.
154
+
155
+ Example:
156
+ >>> properties_api = PropertiesAPI(client)
157
+ >>> properties_api.delete("prop_123")
158
+ >>> # Property is now permanently deleted
159
+ """
160
+ headers = Transaction._build_transaction_header(transaction)
161
+
162
+ return self.client._make_request(
163
+ "DELETE", f"/properties/{property_id}", headers=headers
164
+ )
165
+
166
+ def values(
167
+ self,
168
+ property_id: str,
169
+ search_query: Optional[PropertyValuesQuery] = None,
170
+ transaction: Optional[Transaction] = None,
171
+ ) -> PropertyValuesData:
172
+ """Retrieve and search values data for a specific property.
173
+
174
+ Gets statistical and analytical data about the values stored in a particular property,
175
+ including value distributions, counts, and other metadata. Supports text-based
176
+ searching within the property values.
177
+
178
+ Args:
179
+ property_id (str): The unique identifier of the property to analyze.
180
+ search_query (Optional[PropertyValuesQuery], optional): Extended search query
181
+ that supports text search among property values. Can include:
182
+ - Standard SearchQuery filters
183
+ - query (str): Text search string to filter values
184
+ Defaults to None.
185
+ transaction (Optional[Transaction], optional): Transaction context for the operation.
186
+ If provided, the operation will be part of the transaction. Defaults to None.
187
+
188
+ Returns:
189
+ PropertyValuesData: Object containing statistical and analytical data about
190
+ the property's values, including distributions, counts, and value samples.
191
+
192
+ Raises:
193
+ ValueError: If the property_id is invalid or empty.
194
+ NotFoundError: If no property exists with the specified ID.
195
+ RequestError: If the server request fails.
196
+
197
+ Example:
198
+ >>> properties_api = PropertiesAPI(client)
199
+ >>>
200
+ >>> # Get all values data for a property
201
+ >>> values_data = properties_api.values("prop_123")
202
+ >>> print(f"Total values: {values_data.total}")
203
+ >>>
204
+ >>> # Search for specific values
205
+ >>> query = PropertyValuesQuery(query="search_text")
206
+ >>> filtered_values = properties_api.values("prop_123", query)
207
+ """
208
+ headers = Transaction._build_transaction_header(transaction)
209
+
210
+ return self.client._make_request(
211
+ "POST",
212
+ f"/properties/{property_id}/values",
213
+ typing.cast(typing.Dict[str, typing.Any], search_query or {}),
214
+ headers,
215
+ )