|
| 1 | +<div align="center"> |
| 2 | + |
| 3 | + |
| 4 | + |
1 | 5 | # RushDB Python SDK
|
| 6 | +### The Instant Database for Modern Apps and DS/ML Ops |
2 | 7 |
|
3 |
| -A modern Python client for RushDB, a graph database built for modern applications. |
| 8 | +RushDB is an open-source database built on Neo4j, designed to simplify application development. |
4 | 9 |
|
5 |
| -## Installation |
| 10 | +It automates data normalization, manages relationships, and infers data types, enabling developers to focus on building features rather than wrestling with data. |
6 | 11 |
|
7 |
| -```bash |
8 |
| -pip install rushdb |
9 |
| -``` |
| 12 | +[🌐 Homepage](https://rushdb.com) — [📢 Blog](https://rushdb.com/blog) — [☁️ Platform ](https://app.rushdb.com) — [📚 Docs](https://docs.rushdb.com) — [🧑💻 Examples](https://github.com/rush-db/rushdb/examples) |
| 13 | +</div> |
10 | 14 |
|
11 |
| -## Quick Start |
| 15 | +## 🚀 Feature Highlights |
12 | 16 |
|
13 |
| -```python |
14 |
| -from src.rushdb import RushDBClient |
| 17 | +### 1. **Data modeling is optional** |
| 18 | +Push data of any shape—RushDB handles relationships, data types, and more automatically. |
15 | 19 |
|
16 |
| -# Initialize the client |
17 |
| -client = RushDBClient("http://localhost:8000", "your-api-key") |
| 20 | +### 2. **Automatic type inference** |
| 21 | +Minimizes overhead while optimizing performance for high-speed searches. |
18 | 22 |
|
19 |
| -# Create a record |
20 |
| -record = client.records.create({ |
21 |
| - "name": "John Doe", |
22 |
| - "age": 30, |
23 |
| - |
24 |
| -}) |
| 23 | +### 3. **Powerful search API** |
| 24 | +Query data with accuracy using the graph-powered search API. |
25 | 25 |
|
26 |
| -# Find records |
27 |
| -results = client.records.find({ |
28 |
| - "where": { |
29 |
| - "age": {"$gt": 25}, |
30 |
| - "status": "active" |
31 |
| - }, |
32 |
| - "orderBy": {"created_at": "desc"}, |
33 |
| - "limit": 10 |
34 |
| -}) |
35 |
| - |
36 |
| -# Create relations |
37 |
| -client.records.attach( |
38 |
| - source_id="user123", |
39 |
| - target_ids=["order456"], |
40 |
| - relation_type="PLACED_ORDER" |
41 |
| -) |
42 |
| - |
43 |
| -# Use transactions |
44 |
| -tx_id = client.transactions.begin() |
45 |
| -try: |
46 |
| - client.records.create({"name": "Alice"}, transaction_id=tx_id) |
47 |
| - client.records.create({"name": "Bob"}, transaction_id=tx_id) |
48 |
| - client.transactions.commit(tx_id) |
49 |
| -except Exception: |
50 |
| - client.transactions.rollback(tx_id) |
51 |
| - raise |
52 |
| -``` |
| 26 | +### 4. **Flexible data import** |
| 27 | +Easily import data in `JSON`, `CSV`, or `JSONB`, creating data-rich applications fast. |
53 | 28 |
|
54 |
| -## Features |
| 29 | +### 5. **Developer-Centric Design** |
| 30 | +RushDB prioritizes DX with an intuitive and consistent API. |
55 | 31 |
|
56 |
| -- Full TypeScript-like type hints |
57 |
| -- Transaction support |
58 |
| -- Comprehensive query builder |
59 |
| -- Graph traversal |
60 |
| -- Property management |
61 |
| -- Label management |
62 |
| -- Error handling |
63 |
| -- Connection pooling (with requests) |
| 32 | +### 6. **REST API Readiness** |
| 33 | +A REST API with SDK-like DX for every operation: manage relationships, create, delete, and search effortlessly. Same DTO everywhere. |
64 | 34 |
|
65 |
| -## API Documentation |
| 35 | +--- |
66 | 36 |
|
67 |
| -### Records API |
| 37 | +## Installation |
68 | 38 |
|
69 |
| -```python |
70 |
| -client.records.find(query) # Find records matching query |
71 |
| -client.records.find_by_id(id_or_ids) # Find records by ID(s) |
72 |
| -client.records.find_one(query) # Find single record |
73 |
| -client.records.find_unique(query) # Find unique record |
74 |
| -client.records.create(data) # Create record |
75 |
| -client.records.create_many(data) # Create multiple records |
76 |
| -client.records.delete(query) # Delete records matching query |
77 |
| -client.records.delete_by_id(id_or_ids) # Delete records by ID(s) |
78 |
| -client.records.attach(source_id, target_ids, relation_type) # Create relations |
79 |
| -client.records.detach(source_id, target_ids, type_or_types) # Remove relations |
80 |
| -client.records.export(query) # Export records to CSV |
| 39 | +Install the RushDB Python SDK via pip: |
| 40 | + |
| 41 | +```sh |
| 42 | +pip install rushdb |
81 | 43 | ```
|
82 | 44 |
|
83 |
| -### Properties API |
| 45 | +--- |
| 46 | + |
| 47 | +## Usage |
| 48 | + |
| 49 | +### **1. Setup SDK** |
84 | 50 |
|
85 | 51 | ```python
|
86 |
| -client.properties.list() # List all properties |
87 |
| -client.properties.create(data) # Create property |
88 |
| -client.properties.get(property_id) # Get property |
89 |
| -client.properties.update(property_id, data) # Update property |
90 |
| -client.properties.delete(property_id) # Delete property |
91 |
| -client.properties.get_values(property_id) # Get property values |
| 52 | +from rushdb import RushDB |
| 53 | + |
| 54 | +db = RushDB("API_TOKEN", url="https://api.rushdb.com") |
92 | 55 | ```
|
93 | 56 |
|
94 |
| -### Labels API |
| 57 | +--- |
| 58 | + |
| 59 | +### **2. Push any JSON data** |
95 | 60 |
|
96 | 61 | ```python
|
97 |
| -client.labels.list() # List all labels |
98 |
| -client.labels.create(label) # Create label |
99 |
| -client.labels.delete(label) # Delete label |
| 62 | +company_data = { |
| 63 | + "label": "COMPANY", |
| 64 | + "payload": { |
| 65 | + "name": "Google LLC", |
| 66 | + "address": "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA", |
| 67 | + "foundedAt": "1998-09-04T00:00:00.000Z", |
| 68 | + "rating": 4.9, |
| 69 | + "DEPARTMENT": [{ |
| 70 | + "name": "Research & Development", |
| 71 | + "description": "Innovating and creating advanced technologies for AI, cloud computing, and consumer devices.", |
| 72 | + "PROJECT": [{ |
| 73 | + "name": "Bard AI", |
| 74 | + "description": "A state-of-the-art generative AI model for natural language understanding and creation.", |
| 75 | + "active": True, |
| 76 | + "budget": 1200000000, |
| 77 | + "EMPLOYEE": [{ |
| 78 | + "name": "Jeff Dean", |
| 79 | + "position": "Head of AI Research", |
| 80 | + |
| 81 | + "dob": "1968-07-16T00:00:00.000Z", |
| 82 | + "salary": 3000000 |
| 83 | + }] |
| 84 | + }] |
| 85 | + }] |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +db.records.create_many(company_data) |
100 | 90 | ```
|
101 | 91 |
|
102 |
| -### Transactions API |
| 92 | +--- |
| 93 | + |
| 94 | +### **3. Find Records by specific criteria** |
103 | 95 |
|
104 | 96 | ```python
|
105 |
| -client.transactions.begin() # Start transaction |
106 |
| -client.transactions.commit(transaction_id) # Commit transaction |
107 |
| -client.transactions.rollback(transaction_id) # Rollback transaction |
| 97 | +query = { |
| 98 | + "labels": ["EMPLOYEE"], |
| 99 | + "where": { |
| 100 | + "position": {"$contains": "AI"}, |
| 101 | + "PROJECT": { |
| 102 | + "DEPARTMENT": { |
| 103 | + "COMPANY": { |
| 104 | + "rating": {"$gte": 4} |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +matched_employees = db.records.find(query) |
| 112 | + |
| 113 | +company = db.records.find_uniq("COMPANY", {"where": {"name": "Google LLC"}}) |
108 | 114 | ```
|
109 | 115 |
|
110 |
| -## Development |
| 116 | +--- |
| 117 | + |
| 118 | +### **4. Use REST API with cURL** |
| 119 | + |
| 120 | +```sh |
| 121 | +curl -X POST https://api.rushdb.com/api/v1/records/search \ |
| 122 | +-H "Authorization: Bearer API_TOKEN" \ |
| 123 | +-H "Content-Type: application/json" \ |
| 124 | +-d '{ |
| 125 | + "labels": ["EMPLOYEE"], |
| 126 | + "where": { |
| 127 | + "position": { "$contains": "AI" }, |
| 128 | + "PROJECT": { |
| 129 | + "DEPARTMENT": { |
| 130 | + "COMPANY": { |
| 131 | + "rating": { "$gte": 4 } |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | +}' |
| 137 | +``` |
111 | 138 |
|
112 |
| -```bash |
113 |
| -# Install dependencies |
114 |
| -pip install -r requirements.txt |
| 139 | +<div align="center"> |
| 140 | +<b>You Rock</b> 🚀 |
| 141 | +</div> |
115 | 142 |
|
116 |
| -# Run tests |
117 |
| -python -m unittest discover tests |
118 |
| -``` |
| 143 | +--- |
| 144 | + |
| 145 | +<div align="center" style="margin-top: 20px"> |
| 146 | + |
| 147 | +> Check the [Documentation](https://docs.rushdb.com) and [Examples](https://github.com/rush-db/rushdb/examples) to learn more 🧐 |
119 | 148 |
|
120 |
| -## License |
| 149 | +</div> |
121 | 150 |
|
122 |
| -MIT License |
|
0 commit comments