Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd8d2d2b

Browse files
authored
Merge pull request#16 from rush-db/feat/more-api-methods
Add raw query method, csv import update, create many relationships me…
2 parents6da9bcb +5bb8749 commitd8d2d2b

File tree

9 files changed

+181
-10
lines changed

9 files changed

+181
-10
lines changed

‎README.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ user.attach(
7373
target=company,
7474
options={"type":"WORKS_AT","direction":"out"}
7575
)
76+
77+
# Run a raw Cypher query (cloud-only)
78+
raw= db.query.raw({
79+
"query":"MATCH (u:USER) RETURN u LIMIT $limit",
80+
"params": {"limit":5}
81+
})
82+
print(raw.get("data"))
7683
```
7784

7885
##Pushing Nested JSON
@@ -97,6 +104,21 @@ db.records.create_many("COMPANY", {
97104
})
98105
```
99106

107+
##Importing CSV Data with Parse Config
108+
109+
```python
110+
csv_data="""name,email,age\nJohn,john@example.com,30\nJane,jane@example.com,25"""
111+
112+
response= db.records.import_csv(
113+
label="USER",
114+
data=csv_data,
115+
options={"returnResult":True,"suggestTypes":True},
116+
parse_config={"header":True,"skipEmptyLines":True,"dynamicTyping":True}
117+
)
118+
119+
print(response.get("data"))
120+
```
121+
100122
##SearchResult API
101123

102124
RushDB Python SDK uses a modern`SearchResult` container that follows Python SDK best practices similar to boto3, google-cloud libraries, and other popular SDKs.

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name ="rushdb"
3-
version ="1.10.0"
3+
version ="1.14.0"
44
description ="RushDB Python SDK"
55
authors = [
66
{name ="RushDB Team",email ="hi@rushdb.com"}

‎src/rushdb/__init__.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Exposes the RushDB class.
44
"""
55

6+
from .api.queryimportQueryAPI
7+
from .api.relationshipsimportRelationsAPI
68
from .clientimportRushDB
79
from .commonimportRushDBError
810
from .models.propertyimportProperty
@@ -21,4 +23,6 @@
2123
"Property",
2224
"RelationshipOptions",
2325
"RelationshipDetachOptions",
26+
"QueryAPI",
27+
"RelationsAPI",
2428
]

‎src/rushdb/api/__init__.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from .labelsimportLabelsAPI
2+
from .propertiesimportPropertiesAPI
3+
from .queryimportQueryAPI
4+
from .recordsimportRecordsAPI
5+
from .relationshipsimportRelationsAPI
6+
from .transactionsimportTransactionsAPI
7+
8+
__all__= [
9+
"RecordsAPI",
10+
"PropertiesAPI",
11+
"LabelsAPI",
12+
"TransactionsAPI",
13+
"QueryAPI",
14+
"RelationsAPI",
15+
]

‎src/rushdb/api/query.py‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
fromtypingimportAny,Dict,Optional
2+
3+
from ..models.transactionimportTransaction
4+
from .baseimportBaseAPI
5+
6+
7+
classQueryAPI(BaseAPI):
8+
"""API client for executing raw Cypher queries (cloud-only).
9+
10+
This endpoint is only available when using the RushDB managed cloud
11+
service or when your project is connected to a custom database through
12+
RushDB Cloud. It will not function for self-hosted or local-only deployments.
13+
14+
Example:
15+
>>> from rushdb import RushDB
16+
>>> db = RushDB("RUSHDB_API_KEY")
17+
>>> result = db.query.raw({
18+
... "query": "MATCH (n:Person) RETURN n LIMIT $limit",
19+
... "params": {"limit": 10}
20+
... })
21+
>>> print(result)
22+
"""
23+
24+
defraw(
25+
self,
26+
body:Dict[str,Any],
27+
transaction:Optional[Transaction]=None,
28+
)->Dict[str,Any]:
29+
"""Execute a raw Cypher query.
30+
31+
Args:
32+
body (Dict[str, Any]): Payload containing:
33+
- query (str): Cypher query string
34+
- params (Optional[Dict[str, Any]]): Parameter dict
35+
transaction (Optional[Transaction]): Optional transaction context.
36+
37+
Returns:
38+
Dict[str, Any]: API response including raw driver result in 'data'.
39+
"""
40+
headers=Transaction._build_transaction_header(transaction)
41+
returnself.client._make_request("POST","/query/raw",body,headers)

‎src/rushdb/api/records.py‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ def import_csv(
501501
label:str,
502502
data:str,
503503
options:Optional[Dict[str,bool]]=None,
504+
parse_config:Optional[Dict[str,Any]]=None,
504505
transaction:Optional[Transaction]=None,
505506
)->List[Dict[str,Any]]:
506507
"""Import records from CSV data.
@@ -511,14 +512,17 @@ def import_csv(
511512
512513
Args:
513514
label (str): The label/type to assign to all records created from the CSV.
514-
data (Union[str, bytes]): The CSV content to import. Can be provided
515-
as a string.
516-
options (Optional[Dict[str, bool]], optional): Configuration options for the import operation.
517-
Available options:
518-
- returnResult (bool): Whether to return the created records data. Defaults to True.
519-
- suggestTypes (bool): Whether to automatically suggest data types for CSV columns. Defaults to True.
520-
transaction (Optional[Transaction], optional): Transaction context for the operation.
521-
If provided, the operation will be part of the transaction. Defaults to None.
515+
data (str): The CSV content to import as a string.
516+
options (Optional[Dict[str, bool]]): Import write options (see create_many for list).
517+
parse_config (Optional[Dict[str, Any]]): CSV parsing configuration keys (subset of PapaParse):
518+
- delimiter (str)
519+
- header (bool)
520+
- skipEmptyLines (bool | 'greedy')
521+
- dynamicTyping (bool)
522+
- quoteChar (str)
523+
- escapeChar (str)
524+
- newline (str)
525+
transaction (Optional[Transaction]): Transaction context for the operation.
522526
523527
Returns:
524528
List[Dict[str, Any]]: List of dictionaries representing the imported records,
@@ -544,6 +548,22 @@ def import_csv(
544548
"data":data,
545549
"options":optionsor {"returnResult":True,"suggestTypes":True},
546550
}
551+
ifparse_config:
552+
# pass through only known parse config keys, ignore others silently
553+
allowed_keys= {
554+
"delimiter",
555+
"header",
556+
"skipEmptyLines",
557+
"dynamicTyping",
558+
"quoteChar",
559+
"escapeChar",
560+
"newline",
561+
}
562+
payload["parseConfig"]= {
563+
k:v
564+
fork,vinparse_config.items()
565+
ifkinallowed_keysandvisnotNone
566+
}
547567

548568
returnself.client._make_request(
549569
"POST","/records/import/csv",payload,headers

‎src/rushdb/api/relationships.py‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,68 @@ async def find(
141141
)
142142

143143
returnresponse.data
144+
145+
defcreate_many(
146+
self,
147+
*,
148+
source:dict,
149+
target:dict,
150+
type:Optional[str]=None,
151+
direction:Optional[str]=None,
152+
many_to_many:Optional[bool]=None,
153+
transaction:Optional[Union[Transaction,str]]=None,
154+
)->dict:
155+
"""Bulk create relationships by matching keys or many-to-many cartesian.
156+
157+
Modes:
158+
1. Key-match (default): requires source.key and target.key, creates relationships where source[key] = target[key].
159+
2. many_to_many=True: cartesian across filtered sets (requires where filters on both source & target and omits keys).
160+
161+
Args:
162+
source (dict): { label: str, key?: str, where?: dict }
163+
target (dict): { label: str, key?: str, where?: dict }
164+
type (str, optional): Relationship type override.
165+
direction (str, optional): 'in' | 'out'. Defaults to 'out' server-side when omitted.
166+
many_to_many (bool, optional): Enable cartesian mode (requires filters, disallows keys).
167+
transaction (Transaction|str, optional): Transaction context.
168+
169+
Returns:
170+
dict: API response payload.
171+
"""
172+
headers=Transaction._build_transaction_header(transaction)
173+
payload:dict= {"source":source,"target":target}
174+
iftype:
175+
payload["type"]=type
176+
ifdirection:
177+
payload["direction"]=direction
178+
ifmany_to_manyisnotNone:
179+
payload["manyToMany"]=many_to_many
180+
returnself.client._make_request(
181+
"POST","/relationships/create-many",payload,headers
182+
)
183+
184+
defdelete_many(
185+
self,
186+
*,
187+
source:dict,
188+
target:dict,
189+
type:Optional[str]=None,
190+
direction:Optional[str]=None,
191+
many_to_many:Optional[bool]=None,
192+
transaction:Optional[Union[Transaction,str]]=None,
193+
)->dict:
194+
"""Bulk delete relationships using same contract as create_many.
195+
196+
See create_many for argument semantics.
197+
"""
198+
headers=Transaction._build_transaction_header(transaction)
199+
payload:dict= {"source":source,"target":target}
200+
iftype:
201+
payload["type"]=type
202+
ifdirection:
203+
payload["direction"]=direction
204+
ifmany_to_manyisnotNone:
205+
payload["manyToMany"]=many_to_many
206+
returnself.client._make_request(
207+
"POST","/relationships/delete-many",payload,headers
208+
)

‎src/rushdb/client.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
from .api.labelsimportLabelsAPI
1515
from .api.propertiesimportPropertiesAPI
16+
from .api.queryimportQueryAPI
1617
from .api.recordsimportRecordsAPI
18+
from .api.relationshipsimportRelationsAPI
1719
from .api.transactionsimportTransactionsAPI
1820
from .commonimportRushDBError
1921
from .utils.token_prefiximportextract_mixed_properties_from_token
@@ -121,6 +123,8 @@ def __init__(self, api_key: str, base_url: Optional[str] = None):
121123
self.properties=PropertiesAPI(self)
122124
self.labels=LabelsAPI(self)
123125
self.transactions=TransactionsAPI(self)
126+
self.query=QueryAPI(self)
127+
self.relationships=RelationsAPI(self)
124128

125129
def_make_request(
126130
self,

‎uv.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp