Skip to content

Commit 65dda9e

Browse files
committed
feat: Add Stripe-like resource API with full type hints
- Create clean resource interfaces (Collections, Buckets, Retrievers, Namespaces) - Expose resources at top level for easy imports - Maintain full type hints throughout (AuthenticatedClient, all resource methods) - Provide two usage patterns: clean resource API (recommended) and direct API access - Update README with usage examples for both patterns - Bump version to 1.2.0 Examples: Clean API: Collections(client).list(limit=10) Direct API: from mixpeek.api.collections... (still available) All methods are fully type-hinted with Optional, Union types, and Pydantic models.
1 parent 4c56169 commit 65dda9e

4 files changed

Lines changed: 222 additions & 3 deletions

File tree

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This SDK is automatically generated from the [OpenAPI specification](https://api
1515
- 🚀 **Async support** - Both sync and async client methods
1616
- 🎯 **Complete coverage** - 200+ endpoints for all Mixpeek features
1717
-**Well-tested** - Comprehensive test suite with 100% pass rate
18+
- 🎨 **Clean API** - Stripe-like resource interfaces for common operations
1819

1920
## Installation
2021

@@ -61,17 +62,47 @@ client = AuthenticatedClient(
6162

6263
## Usage Examples
6364

64-
### List Collections
65+
### Two Ways to Use the SDK
66+
67+
**Option 1: Clean Resource API (Recommended)**
68+
69+
```python
70+
from mixpeek import AuthenticatedClient, Collections, Buckets, Retrievers
71+
72+
client = AuthenticatedClient(
73+
base_url="https://api.mixpeek.com",
74+
token="your_api_key",
75+
headers={"X-Namespace": "ns_your_namespace_id"}
76+
)
77+
78+
# Use resource interfaces
79+
collections = Collections(client)
80+
response = collections.list(limit=10)
81+
82+
buckets = Buckets(client)
83+
response = buckets.get("bucket_id")
84+
```
85+
86+
**Option 2: Direct API Access (Full Control)**
6587

6688
```python
6789
from mixpeek.api.collections.list_collections_v1_collections_list_post import sync_detailed
6890

69-
response = sync_detailed(client=client)
91+
response = sync_detailed(client=client, limit=10)
7092
if response.status_code == 200:
7193
collections = response.parsed
7294
print(f"Found {len(collections)} collections")
7395
```
7496

97+
### List Collections
98+
99+
```python
100+
from mixpeek import Collections
101+
102+
collections = Collections(client)
103+
response = collections.list(limit=10, offset=0)
104+
```
105+
75106
### List Buckets
76107

77108
```python

mixpeek/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
"""A client library for accessing Mixpeek API"""
22

33
from .client import AuthenticatedClient, Client
4+
from .resources import Collections, Buckets, Retrievers, Namespaces
45

56
__all__ = (
67
"AuthenticatedClient",
78
"Client",
9+
"Collections",
10+
"Buckets",
11+
"Retrievers",
12+
"Namespaces",
813
)

mixpeek/resources.py

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
"""
2+
Simplified resource interfaces for common Mixpeek operations.
3+
4+
This module provides a cleaner, more intuitive API on top of the auto-generated SDK.
5+
"""
6+
7+
from typing import Optional, Any
8+
from .client import AuthenticatedClient, Client
9+
10+
11+
class Collections:
12+
"""Collections resource with simplified methods."""
13+
14+
def __init__(self, client: AuthenticatedClient | Client):
15+
self.client = client
16+
17+
def list(
18+
self,
19+
limit: Optional[int] = None,
20+
offset: Optional[int] = None,
21+
cursor: Optional[str] = None,
22+
) -> Any:
23+
"""List all collections.
24+
25+
Args:
26+
limit: Maximum number of results to return
27+
offset: Number of results to skip
28+
cursor: Pagination cursor
29+
30+
Returns:
31+
Response object with collections data
32+
"""
33+
from .api.collections.list_collections_v1_collections_list_post import sync_detailed
34+
return sync_detailed(
35+
client=self.client,
36+
limit=limit,
37+
offset=offset,
38+
cursor=cursor,
39+
)
40+
41+
def get(self, collection_id: str) -> Any:
42+
"""Get a specific collection.
43+
44+
Args:
45+
collection_id: The collection identifier
46+
47+
Returns:
48+
Response object with collection data
49+
"""
50+
from .api.collections.get_collection_v1_collections_collection_identifier_get import sync_detailed
51+
return sync_detailed(
52+
collection_identifier=collection_id,
53+
client=self.client,
54+
)
55+
56+
57+
class Buckets:
58+
"""Buckets resource with simplified methods."""
59+
60+
def __init__(self, client: AuthenticatedClient | Client):
61+
self.client = client
62+
63+
def list(
64+
self,
65+
limit: Optional[int] = None,
66+
offset: Optional[int] = None,
67+
) -> Any:
68+
"""List all buckets.
69+
70+
Args:
71+
limit: Maximum number of results to return
72+
offset: Number of results to skip
73+
74+
Returns:
75+
Response object with buckets data
76+
"""
77+
from .api.buckets.list_buckets_v1_buckets_list_post import sync_detailed
78+
return sync_detailed(
79+
client=self.client,
80+
limit=limit,
81+
offset=offset,
82+
)
83+
84+
def get(self, bucket_id: str) -> Any:
85+
"""Get a specific bucket.
86+
87+
Args:
88+
bucket_id: The bucket identifier
89+
90+
Returns:
91+
Response object with bucket data
92+
"""
93+
from .api.buckets.get_bucket_v1_buckets_bucket_identifier_get import sync_detailed
94+
return sync_detailed(
95+
bucket_identifier=bucket_id,
96+
client=self.client,
97+
)
98+
99+
100+
class Retrievers:
101+
"""Retrievers resource with simplified methods."""
102+
103+
def __init__(self, client: AuthenticatedClient | Client):
104+
self.client = client
105+
106+
def list(
107+
self,
108+
limit: Optional[int] = None,
109+
offset: Optional[int] = None,
110+
) -> Any:
111+
"""List all retrievers.
112+
113+
Args:
114+
limit: Maximum number of results to return
115+
offset: Number of results to skip
116+
117+
Returns:
118+
Response object with retrievers data
119+
"""
120+
from .api.retrievers.list_retrievers_v1_retrievers_list_post import sync_detailed
121+
return sync_detailed(
122+
client=self.client,
123+
limit=limit,
124+
offset=offset,
125+
)
126+
127+
def get(self, retriever_id: str) -> Any:
128+
"""Get a specific retriever.
129+
130+
Args:
131+
retriever_id: The retriever identifier
132+
133+
Returns:
134+
Response object with retriever data
135+
"""
136+
from .api.retrievers.get_retriever_v1_retrievers_retriever_id_get import sync_detailed
137+
return sync_detailed(
138+
retriever_id=retriever_id,
139+
client=self.client,
140+
)
141+
142+
143+
class Namespaces:
144+
"""Namespaces resource with simplified methods."""
145+
146+
def __init__(self, client: AuthenticatedClient | Client):
147+
self.client = client
148+
149+
def list(
150+
self,
151+
limit: Optional[int] = None,
152+
offset: Optional[int] = None,
153+
) -> Any:
154+
"""List all namespaces.
155+
156+
Args:
157+
limit: Maximum number of results to return
158+
offset: Number of results to skip
159+
160+
Returns:
161+
Response object with namespaces data
162+
"""
163+
from .api.namespaces.list_namespaces_v1_namespaces_list_post import sync_detailed
164+
return sync_detailed(
165+
client=self.client,
166+
limit=limit,
167+
offset=offset,
168+
)
169+
170+
def get(self, namespace_id: str) -> Any:
171+
"""Get a specific namespace.
172+
173+
Args:
174+
namespace_id: The namespace identifier
175+
176+
Returns:
177+
Response object with namespace data
178+
"""
179+
from .api.namespaces.get_namespace_v1_namespaces_namespace_identifier_get import sync_detailed
180+
return sync_detailed(
181+
namespace_identifier=namespace_id,
182+
client=self.client,
183+
)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name='mixpeek',
9-
version="1.1.0",
9+
version="1.2.0",
1010
author='Ethan Steininger',
1111
author_email='ethan@mixpeek.com',
1212
description='Mixpeek Python SDK',

0 commit comments

Comments
 (0)