Skip to content

Commit 4649a08

Browse files
committed
format & lint
1 parent e4de425 commit 4649a08

File tree

12 files changed

+97
-73
lines changed

12 files changed

+97
-73
lines changed

examples/insert_entity/src/insert_entity_example.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from dotenv import find_dotenv, load_dotenv
1616

1717

18-
1918
def get_env(name: str) -> str:
2019
value = os.getenv(name)
2120
if not value:
@@ -43,7 +42,9 @@ async def find_store(client: DeltaStreamClient, store_name: str):
4342
print("Available stores:")
4443
for store in stores:
4544
print(f" - {store.name}")
46-
print("\nPlease update STORE_NAME in .env to match one of the available stores.")
45+
print(
46+
"\nPlease update STORE_NAME in .env to match one of the available stores."
47+
)
4748
sys.exit(1)
4849

4950
print(f"\n✅ Found configured store: {target_store.name}")
@@ -84,18 +85,26 @@ async def ensure_entity(client: DeltaStreamClient, entity_name: str, target_stor
8485
"kafka.topic.partitions": 1,
8586
"kafka.topic.replicas": 1,
8687
"kafka.topic.retention.ms": "604800000", # 7 days
87-
"kafka.topic.segment.ms": "86400000" # 1 day
88-
}
88+
"kafka.topic.segment.ms": "86400000", # 1 day
89+
},
90+
)
91+
print(
92+
f"Creating entity with params: name='{entity_name}', store='{target_store.name}', params={create_params.params}"
8993
)
90-
print(f"Creating entity with params: name='{entity_name}', store='{target_store.name}', params={create_params.params}")
9194
await client.entities.create(params=create_params)
92-
print(f"Entity '{entity_name}' created successfully in store '{target_store.name}'")
95+
print(
96+
f"Entity '{entity_name}' created successfully in store '{target_store.name}'"
97+
)
9398
except Exception as e:
9499
error_msg = str(e)
95100
if "already exists" in error_msg:
96-
print(f"Entity '{entity_name}' already exists (topic level), continuing...")
101+
print(
102+
f"Entity '{entity_name}' already exists (topic level), continuing..."
103+
)
97104
elif "schema not found" in error_msg:
98-
print(f"Entity '{entity_name}' created successfully but retrieval failed, continuing...")
105+
print(
106+
f"Entity '{entity_name}' created successfully but retrieval failed, continuing..."
107+
)
99108
else:
100109
print(f"Could not create entity using SDK: {e}")
101110
sys.exit(1)
@@ -112,13 +121,15 @@ async def insert_data(client: DeltaStreamClient, entity_name: str, store_name: s
112121
{"viewtime": 1753311018650, "userid": "User_4", "pageid": "Page_2"},
113122
]
114123

115-
print(f"Attempting to insert {len(sample_data)} records into entity '{entity_name}' in store '{store_name}'...")
116-
print(f"Generated SQL will be: INSERT INTO ENTITY \"{entity_name}\" IN STORE \"{store_name}\" VALUE ('{{\"viewtime\": 1753311018649,\"userid\": \"User_3\",\"pageid\": \"Page_1\"}}')")
124+
print(
125+
f"Attempting to insert {len(sample_data)} records into entity '{entity_name}' in store '{store_name}'..."
126+
)
127+
print(
128+
f'Generated SQL will be: INSERT INTO ENTITY "{entity_name}" IN STORE "{store_name}" VALUE (\'{{"viewtime": 1753311018649,"userid": "User_3","pageid": "Page_1"}}\')'
129+
)
117130

118131
await client.entities.insert_values(
119-
name=entity_name,
120-
values=sample_data,
121-
store=store_name
132+
name=entity_name, values=sample_data, store=store_name
122133
)
123134
print("Insert completed successfully.")
124135

examples/list_entity/src/utils/config.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,9 @@ def __init__(self) -> None:
6161
def validate(self) -> None:
6262
"""Validate that required configuration is present."""
6363
if not self.auth_token:
64-
raise ValueError(
65-
"DELTASTREAM_TOKEN environment variable is required"
66-
)
64+
raise ValueError("DELTASTREAM_TOKEN environment variable is required")
6765
if not self.organization_id:
68-
raise ValueError(
69-
"DELTASTREAM_ORG_ID environment variable is required"
70-
)
66+
raise ValueError("DELTASTREAM_ORG_ID environment variable is required")
7167

7268
# Check token validity
7369
self._validate_token()

src/deltastream_sdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
"InvalidConfiguration",
2727
"ConnectionError",
2828
"models",
29-
"resources",
29+
"resources",
3030
"exceptions",
3131
]

src/deltastream_sdk/client.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -251,30 +251,38 @@ async def query_sql(self, sql: str) -> List[Dict[str, Any]]:
251251
async def use_database(self, database: str) -> None:
252252
"""Switch to a different database."""
253253
# Use DATABASE keyword for DeltaStream syntax
254-
escaped_db = database if database.startswith('"') and database.endswith('"') else f'"{database}"'
255-
sql = f'USE DATABASE {escaped_db}'
254+
escaped_db = (
255+
database
256+
if database.startswith('"') and database.endswith('"')
257+
else f'"{database}"'
258+
)
259+
sql = f"USE DATABASE {escaped_db}"
256260
await self.execute_sql(sql)
257-
261+
258262
# Update the current database in memory
259263
self._current_database = database
260264

261265
async def use_store(self, store: str) -> None:
262266
"""Switch to a different store."""
263267
# Use STORE keyword for DeltaStream syntax
264-
escaped_store = store if store.startswith('"') and store.endswith('"') else f'"{store}"'
265-
sql = f'USE STORE {escaped_store}'
268+
escaped_store = (
269+
store if store.startswith('"') and store.endswith('"') else f'"{store}"'
270+
)
271+
sql = f"USE STORE {escaped_store}"
266272
await self.execute_sql(sql)
267-
273+
268274
# Update the current store in memory
269275
self._current_store = store
270276

271277
async def use_schema(self, schema: str) -> None:
272278
"""Switch to a different schema."""
273279
# Use SCHEMA keyword for DeltaStream syntax
274-
escaped_schema = schema if schema.startswith('"') and schema.endswith('"') else f'"{schema}"'
275-
sql = f'USE SCHEMA {escaped_schema}'
280+
escaped_schema = (
281+
schema if schema.startswith('"') and schema.endswith('"') else f'"{schema}"'
282+
)
283+
sql = f"USE SCHEMA {escaped_schema}"
276284
await self.execute_sql(sql)
277-
285+
278286
# Update the current schema in memory
279287
self._current_schema = schema
280288

@@ -283,74 +291,74 @@ async def get_current_database(self) -> str:
283291
# If we have a cached current database, return it
284292
if self._current_database:
285293
return self._current_database
286-
294+
287295
# Otherwise, query LIST DATABASES to find the default database
288296
try:
289297
databases = await self.databases.list()
290298
for db in databases:
291299
# Look for the default database
292-
if hasattr(db, 'is_default') and db.is_default:
300+
if hasattr(db, "is_default") and db.is_default:
293301
self._current_database = db.name
294302
return db.name
295-
303+
296304
# If no default found, return the first database if any exist
297305
if databases:
298306
self._current_database = databases[0].name
299307
return databases[0].name
300308
except Exception:
301309
# If list databases fails, return empty string
302310
pass
303-
311+
304312
return ""
305313

306314
async def get_current_store(self) -> str:
307315
"""Get the current store."""
308316
# If we have a cached current store, return it
309317
if self._current_store:
310318
return self._current_store
311-
319+
312320
# Otherwise, query LIST STORES to find the default store
313321
try:
314322
stores = await self.stores.list()
315323
for store in stores:
316324
# Look for the default store
317-
if hasattr(store, 'is_default') and store.is_default:
325+
if hasattr(store, "is_default") and store.is_default:
318326
self._current_store = store.name
319327
return store.name
320-
328+
321329
# If no default found, return the first store if any exist
322330
if stores:
323331
self._current_store = stores[0].name
324332
return stores[0].name
325333
except Exception:
326334
# If list stores fails, return empty string
327335
pass
328-
336+
329337
return ""
330338

331339
async def get_current_schema(self) -> str:
332340
"""Get the current schema."""
333341
# If we have a cached current schema, return it
334342
if self._current_schema:
335343
return self._current_schema
336-
344+
337345
# Otherwise, query LIST SCHEMAS to find the default schema
338346
try:
339347
schemas = await self.schemas.list()
340348
for schema in schemas:
341349
# Look for the default schema
342-
if hasattr(schema, 'is_default') and schema.is_default:
350+
if hasattr(schema, "is_default") and schema.is_default:
343351
self._current_schema = schema.name
344352
return schema.name
345-
353+
346354
# If no default found, return the first schema if any exist
347355
if schemas:
348356
self._current_schema = schemas[0].name
349357
return schemas[0].name
350358
except Exception:
351359
# If list schemas fails, return empty string
352360
pass
353-
361+
354362
return ""
355363

356364
# Context manager support

src/deltastream_sdk/models/entities.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class Entity(BaseModel):
1111

1212
entity_type: Optional[str] = None
1313
schema_definition: Optional[str] = None
14-
is_leaf: Optional[bool] = None # Whether this entity is a leaf (can't contain other entities)
14+
is_leaf: Optional[bool] = (
15+
None # Whether this entity is a leaf (can't contain other entities)
16+
)
1517

1618

1719
@dataclass

src/deltastream_sdk/models/schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ class SchemaCreateParams:
4040
"""Parameters for creating a schema."""
4141

4242
name: str
43-
comment: Optional[str] = None
43+
comment: Optional[str] = None

src/deltastream_sdk/resources/databases.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from .base import BaseResourceManager
44
from ..models.databases import Database, DatabaseCreateParams
5-
from ..exceptions import ResourceNotFound, SQLError
65

76

87
class DatabaseManager(BaseResourceManager[Database]):

src/deltastream_sdk/resources/entities.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
EntityCreateParams,
1010
EntityUpdateParams,
1111
)
12-
from ..models.base import WithClause
1312

1413

1514
class EntityManager(BaseResourceManager[Entity]):
@@ -33,20 +32,20 @@ def _get_create_sql(self, **params) -> str:
3332

3433
name = self._escape_identifier(create_params.name)
3534
sql = f"CREATE ENTITY {name}"
36-
35+
3736
if create_params.store:
3837
escaped_store = self._escape_identifier(create_params.store)
3938
sql += f" IN STORE {escaped_store}"
40-
39+
4140
with_parts = []
42-
41+
4342
if create_params.params:
4443
for key, value in create_params.params.items():
4544
with_parts.append(f"'{key}' = {self._escape_string(str(value))}")
46-
45+
4746
if with_parts:
4847
sql += f" WITH ({', '.join(with_parts)})"
49-
48+
5049
return sql
5150

5251
def _get_update_sql(self, name: str, **params) -> str:
@@ -92,14 +91,14 @@ def to_json_string(record: Union[str, Dict[str, Any]]) -> str:
9291
single = values[0]
9392
json_str = self._escape_string(to_json_string(single))
9493
sql = f"INSERT INTO ENTITY {escaped_name}"
95-
94+
9695
# Add IN STORE clause if store is provided
9796
if store:
9897
escaped_store = self._escape_identifier(store)
9998
sql += f" IN STORE {escaped_store}"
100-
99+
101100
sql += f" VALUE({json_str})"
102-
101+
103102
# Add WITH clause if we have with_params
104103
if with_params:
105104
with_parts = []
@@ -110,21 +109,23 @@ def to_json_string(record: Union[str, Dict[str, Any]]) -> str:
110109
for record in values:
111110
json_str = self._escape_string(to_json_string(record))
112111
single_sql = f"INSERT INTO ENTITY {escaped_name}"
113-
112+
114113
# Add IN STORE clause if store is provided
115114
if store:
116115
escaped_store = self._escape_identifier(store)
117116
single_sql += f" IN STORE {escaped_store}"
118-
117+
119118
single_sql += f" VALUE({json_str})"
120-
119+
121120
# Add WITH clause if we have with_params
122121
if with_params:
123122
with_parts = []
124123
for key, value in with_params.items():
125-
with_parts.append(f"'{key}' = {self._escape_string(str(value))}")
124+
with_parts.append(
125+
f"'{key}' = {self._escape_string(str(value))}"
126+
)
126127
single_sql += f" WITH ({', '.join(with_parts)})"
127-
128+
128129
await self._execute_sql(single_sql)
129130
return
130131

@@ -146,17 +147,17 @@ async def list_entities(
146147
List of Entity objects representing the entities
147148
"""
148149
sql = "LIST ENTITIES"
149-
150+
150151
# Add IN clause for entity path if provided
151152
if entity_path:
152153
escaped_path = self._escape_identifier(entity_path)
153154
sql += f" IN {escaped_path}"
154-
155+
155156
# Add IN STORE clause if provided
156157
if store:
157158
escaped_store = self._escape_identifier(store)
158159
sql += f" IN STORE {escaped_store}"
159-
160+
160161
try:
161162
results = await self._query_sql(sql)
162163
entities = []
@@ -171,9 +172,10 @@ async def list_entities(
171172
entity.is_leaf = result["Is Leaf"]
172173
elif "is_leaf" in result:
173174
entity.is_leaf = result["is_leaf"]
174-
175+
175176
entities.append(entity)
176177
return entities
177178
except Exception as e:
178179
from ..exceptions import SQLError
180+
179181
raise SQLError(f"Failed to list entities: {e}") from e

src/deltastream_sdk/resources/schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ def _get_update_sql(self, name: str, **params) -> str:
4747
def _get_delete_sql(self, name: str, **params) -> str:
4848
"""Generate SQL for deleting a schema."""
4949
escaped_name = self._escape_identifier(name)
50-
return f"DROP SCHEMA {escaped_name}"
50+
return f"DROP SCHEMA {escaped_name}"

tests/sdk/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def from_dsn(cls, dsn, token_provider=None):
2626
sys.modules["deltastream.api.conn"] = mock_api.conn
2727

2828
# Import SDK components after mocking
29-
from deltastream_sdk import DeltaStreamClient
29+
from deltastream_sdk import DeltaStreamClient # noqa: E402
3030

3131

3232
@pytest.fixture

0 commit comments

Comments
 (0)