@@ -142,6 +142,9 @@ class Langfuse:
142142 ```
143143 """
144144
145+ _resources : Optional [LangfuseResourceManager ] = None
146+ _mask : Optional [MaskFunction ] = None
147+
145148 def __init__ (
146149 self ,
147150 * ,
@@ -190,7 +193,6 @@ def __init__(
190193 langfuse_logger .warning (
191194 "Authentication error: Langfuse client initialized without public_key. Client will be disabled. "
192195 "Provide a public_key parameter or set LANGFUSE_PUBLIC_KEY environment variable. "
193- "See documentation: https://langfuse.com/docs/sdk/python/low-level-sdk#initialize-client"
194196 )
195197 self ._otel_tracer = otel_trace_api .NoOpTracer ()
196198 return
@@ -200,7 +202,6 @@ def __init__(
200202 langfuse_logger .warning (
201203 "Authentication error: Langfuse client initialized without secret_key. Client will be disabled. "
202204 "Provide a secret_key parameter or set LANGFUSE_SECRET_KEY environment variable. "
203- "See documentation: https://langfuse.com/docs/sdk/python/low-level-sdk#initialize-client"
204205 )
205206 self ._otel_tracer = otel_trace_api .NoOpTracer ()
206207 return
@@ -1326,7 +1327,9 @@ def create_score(
13261327 "timestamp" : _get_timestamp (),
13271328 "body" : new_body ,
13281329 }
1329- self ._resources .add_score_task (event )
1330+
1331+ if self ._resources is not None :
1332+ self ._resources .add_score_task (event )
13301333
13311334 except Exception as e :
13321335 langfuse_logger .exception (
@@ -1520,7 +1523,8 @@ def flush(self):
15201523 # Continue with other work
15211524 ```
15221525 """
1523- self ._resources .flush ()
1526+ if self ._resources is not None :
1527+ self ._resources .flush ()
15241528
15251529 def shutdown (self ):
15261530 """Shut down the Langfuse client and flush all pending data.
@@ -1544,7 +1548,8 @@ def shutdown(self):
15441548 langfuse.shutdown()
15451549 ```
15461550 """
1547- self ._resources .shutdown ()
1551+ if self ._resources is not None :
1552+ self ._resources .shutdown ()
15481553
15491554 def get_current_trace_id (self ) -> Optional [str ]:
15501555 """Get the trace ID of the current active span.
@@ -1926,6 +1931,10 @@ def get_prompt(
19261931 Exception: Propagates any exceptions raised during the fetching of a new prompt, unless there is an
19271932 expired prompt in the cache, in which case it logs a warning and returns the expired prompt.
19281933 """
1934+ if self ._resources is None :
1935+ raise Error (
1936+ "SDK is not correctly initalized. Check the init logs for more details."
1937+ )
19291938 if version is not None and label is not None :
19301939 raise ValueError ("Cannot specify both version and label at the same time." )
19311940
@@ -2051,7 +2060,8 @@ def fetch_prompts():
20512060 else :
20522061 prompt = TextPromptClient (prompt_response )
20532062
2054- self ._resources .prompt_cache .set (cache_key , prompt , ttl_seconds )
2063+ if self ._resources is not None :
2064+ self ._resources .prompt_cache .set (cache_key , prompt , ttl_seconds )
20552065
20562066 return prompt
20572067
@@ -2150,7 +2160,8 @@ def create_prompt(
21502160 )
21512161 server_prompt = self .api .prompts .create (request = request )
21522162
2153- self ._resources .prompt_cache .invalidate (name )
2163+ if self ._resources is not None :
2164+ self ._resources .prompt_cache .invalidate (name )
21542165
21552166 return ChatPromptClient (prompt = cast (Prompt_Chat , server_prompt ))
21562167
@@ -2169,7 +2180,8 @@ def create_prompt(
21692180
21702181 server_prompt = self .api .prompts .create (request = request )
21712182
2172- self ._resources .prompt_cache .invalidate (name )
2183+ if self ._resources is not None :
2184+ self ._resources .prompt_cache .invalidate (name )
21732185
21742186 return TextPromptClient (prompt = cast (Prompt_Text , server_prompt ))
21752187
@@ -2200,7 +2212,9 @@ def update_prompt(
22002212 version = version ,
22012213 new_labels = new_labels ,
22022214 )
2203- self ._resources .prompt_cache .invalidate (name )
2215+
2216+ if self ._resources is not None :
2217+ self ._resources .prompt_cache .invalidate (name )
22042218
22052219 return updated_prompt
22062220
0 commit comments