Skip to content

Commit a2ff85b

Browse files
committed
refactor(client): format client based on linting rules
1 parent 15cbbd7 commit a2ff85b

File tree

1 file changed

+101
-13
lines changed

1 file changed

+101
-13
lines changed

src/typesense/client.py

Lines changed: 101 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
"""
2+
This module provides the main client interface for interacting with the Typesense API.
3+
4+
It contains the Client class, which serves as the entry point for all Typesense operations,
5+
integrating various components like collections, multi-search, keys, aliases, analytics, etc.
6+
7+
Classes:
8+
Client: The main client class for interacting with Typesense.
9+
10+
Dependencies:
11+
- typesense.aliases: Provides the Aliases class.
12+
- typesense.analytics: Provides the Analytics class.
13+
- typesense.api_call: Provides the ApiCall class for making API requests.
14+
- typesense.collection: Provides the Collection class.
15+
- typesense.collections: Provides the Collections class.
16+
- typesense.configuration: Provides Configuration and ConfigDict types.
17+
- typesense.conversations_models: Provides the ConversationsModels class.
18+
- typesense.debug: Provides the Debug class.
19+
- typesense.keys: Provides the Keys class.
20+
- typesense.multi_search: Provides the MultiSearch class.
21+
- typesense.operations: Provides the Operations class.
22+
- typesense.stopwords: Provides the Stopwords class.
23+
- typesense.types.document: Provides the DocumentSchema type.
24+
25+
Note: This module uses conditional imports to support both Python 3.11+ and earlier versions.
26+
"""
27+
128
import sys
229

330
from typesense.types.document import DocumentSchema
@@ -7,25 +34,61 @@
734
else:
835
import typing_extensions as typing
936

37+
from typesense.aliases import Aliases
38+
from typesense.analytics import Analytics
39+
from typesense.api_call import ApiCall
1040
from typesense.collection import Collection
11-
12-
from .aliases import Aliases
13-
from .analytics import Analytics
14-
from .api_call import ApiCall
15-
from .collections import Collections
16-
from .configuration import ConfigDict, Configuration
17-
from .conversations_models import ConversationsModels
18-
from .debug import Debug
19-
from .keys import Keys
20-
from .multi_search import MultiSearch
21-
from .operations import Operations
22-
from .stopwords import Stopwords
41+
from typesense.collections import Collections
42+
from typesense.configuration import ConfigDict, Configuration
43+
from typesense.conversations_models import ConversationsModels
44+
from typesense.debug import Debug
45+
from typesense.keys import Keys
46+
from typesense.multi_search import MultiSearch
47+
from typesense.operations import Operations
48+
from typesense.stopwords import Stopwords
2349

2450
TDoc = typing.TypeVar("TDoc", bound=DocumentSchema)
2551

2652

27-
class Client(object):
53+
class Client:
54+
"""
55+
The main client class for interacting with Typesense.
56+
57+
This class serves as the entry point for all Typesense operations. It initializes
58+
and provides access to various components of the Typesense SDK, such as collections,
59+
multi-search, keys, aliases, analytics, operations, debug, stopwords,
60+
and conversation models.
61+
62+
Attributes:
63+
config (Configuration): The configuration object for the Typesense client.
64+
api_call (ApiCall): The ApiCall instance for making API requests.
65+
collections (Collections[DocumentSchema]): Instance for managing collections.
66+
multi_search (MultiSearch): Instance for performing multi-search operations.
67+
keys (Keys): Instance for managing API keys.
68+
aliases (Aliases): Instance for managing collection aliases.
69+
analytics (Analytics): Instance for analytics operations.
70+
operations (Operations): Instance for various Typesense operations.
71+
debug (Debug): Instance for debug operations.
72+
stopwords (Stopwords): Instance for managing stopwords.
73+
conversations_models (ConversationsModels): Instance for managing conversation models.
74+
"""
75+
2876
def __init__(self, config_dict: ConfigDict) -> None:
77+
"""
78+
Initialize the Client instance.
79+
80+
Args:
81+
config_dict (ConfigDict):
82+
A dictionary containing the configuration for the Typesense client.
83+
84+
Example:
85+
>>> config = {
86+
... "api_key": "your_api_key",
87+
... "nodes": [{"host": "localhost", "port": "8108", "protocol": "http"}],
88+
... "connection_timeout_seconds": 2
89+
... }
90+
>>> client = Client(config)
91+
"""
2992
self.config = Configuration(config_dict)
3093
self.api_call = ApiCall(self.config)
3194
self.collections: Collections[DocumentSchema] = Collections(self.api_call)
@@ -44,6 +107,31 @@ def typed_collection(
44107
model: typing.Type[TDoc],
45108
name: typing.Union[str, None] = None,
46109
) -> Collection[TDoc]:
110+
"""
111+
Get a Collection instance for a specific document model.
112+
113+
This method allows retrieving a Collection instance typed to a specific document model.
114+
If no name is provided, it uses the lowercase name of the model class as
115+
the collection name.
116+
117+
Args:
118+
model (Type[TDoc]): The document model class.
119+
name (Union[str, None], optional):
120+
The name of the collection. If None, uses the lowercase model class name.
121+
122+
Returns:
123+
Collection[TDoc]: A Collection instance typed to the specified document model.
124+
125+
Example:
126+
>>> class Company(DocumentSchema):
127+
... name: str
128+
... num_employees: int
129+
...
130+
>>> client = Client(config)
131+
>>> companies_collection = client.typed_collection(model=Company)
132+
# This is equivalent to:
133+
# companies_collection = client.typed_collection(model=Company, name="company")
134+
"""
47135
if name is None:
48136
name = model.__name__.lower()
49137
collection: Collection[TDoc] = self.collections[name]

0 commit comments

Comments
 (0)