Skip to content

Commit 5a3ed65

Browse files
committed
3.5.2: reduce print statements
1 parent 8e4f714 commit 5a3ed65

File tree

6 files changed

+147
-140
lines changed

6 files changed

+147
-140
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## [3.5.2] - 2025-03-19
4+
5+
- [Fixed] Reduce print statements in the library
6+
37
## [3.5.1] - 2025-03-10
48

59
- [Fixed] Set httpx logger to WARNING level to reduce verbose HTTP request logs in applications using this library
@@ -11,7 +15,7 @@
1115
- Optimized thread management and reduced sleep times in polling loops
1216
- Implemented connection pooling with thread-local HTTP clients
1317
- Improved async code with better connection reuse
14-
- Added proper resource cleanup with __del__ method
18+
- Added proper resource cleanup with **del** method
1519
- Reduced memory allocations with reusable constants and data structures
1620
- Added exponential backoff for connection retries
1721
- Added orjson for much faster JSON serialization/deserialization

pygqlc/GraphQLClient.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class GraphQLClient(metaclass=Singleton):
214214
client = GraphQLClient()
215215
with client.enterEnvironment('dev') as gql:
216216
data, errors = gql.query('{lines(limit:2){id}}')
217-
print(data, errors)
217+
# Process data and errors here
218218
'''
219219
>>> setEnvironment:
220220
'''
@@ -224,7 +224,7 @@ class GraphQLClient(metaclass=Singleton):
224224
environment='dev',
225225
header={'Authorization': dev_token})
226226
data, errors = gql.query('{lines(limit:2){id}}')
227-
print(data, errors)
227+
# Process data and errors here
228228
'''
229229
"""
230230

@@ -492,7 +492,6 @@ def _sub_routing_loop(self):
492492
to_del = []
493493
for sub_id, sub in self.subs.items():
494494
if (sub['kill'] or not sub['running']) and not sub['starting']:
495-
print(f'deleting halted subscription (id: {sub_id})')
496495
# Don't block if thread is already dead
497496
if sub['thread'].is_alive():
498497
# Use timeout to avoid blocking indefinitely
@@ -530,7 +529,7 @@ def _sub_routing_loop(self):
530529
if active_sub:
531530
active_sub['queue'].append(message)
532531
elif message_type == CONNECTION_ACK_TYPE:
533-
print('Connection Ack with the server.')
532+
pass # Connection Ack with the server
534533
elif message_type == PONG_TYPE:
535534
pass
536535
else:
@@ -555,7 +554,6 @@ def _resubscribe_all(self):
555554

556555
# Then join all threads with timeout to avoid blocking indefinitely
557556
for sub_id, sub in self.subs.items():
558-
print(f'killing halted subscription (id={sub_id})')
559557
if sub['thread'].is_alive():
560558
sub['thread'].join(0.5)
561559

@@ -610,7 +608,8 @@ def _subscription_loop(self, _cb, _id, _ecb):
610608
print('Subscription message has payload Errors')
611609
print(message)
612610
elif is_ws_connection_init_msg(message):
613-
print('Subscription successfully initialized')
611+
# Subscription successfully initialized
612+
pass
614613
else:
615614
# Process message more efficiently
616615
gql_msg = self._clean_sub_message(_id, message)
@@ -673,8 +672,8 @@ def close(self):
673672

674673
def _on_message(self, message):
675674
'''Dummy callback for subscription'''
676-
print('message received on subscription:')
677-
print(message)
675+
# Message handling happens elsewhere - no need to print here
676+
pass
678677

679678
def _conn_init(self):
680679
env = self.environments.get(self.environment, None)
@@ -702,7 +701,7 @@ def _waiting_connection_ack(self):
702701
# set timeout to raise Exception websocket.WebSocketTimeoutException
703702
message = orjson.loads(self._conn.recv())
704703
if message['type'] == CONNECTION_ACK_TYPE:
705-
print('Connection Ack with the server.')
704+
pass # Connection Ack with the server
706705

707706
def _ping_pong(self):
708707
self.pingTimer = time.time()
@@ -719,9 +718,7 @@ def _ping_pong(self):
719718
try:
720719
self._conn.send(PING_JSON)
721720
ping_count += 1
722-
# Log only every 10 pings to reduce noise
723-
if ping_count % 10 == 0:
724-
print(f"Sent ping #{ping_count}")
721+
# No need to log normal ping operations
725722
except Exception as e:
726723
if not self.closing:
727724
print('error trying to send ping, WSS Pipe is broken')

pygqlc/MutationBatch.py

Lines changed: 117 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -33,127 +33,130 @@
3333
"""The purpuse of this module is batch and execute a graphql transaction, such
3434
as a query or mutation.
3535
"""
36+
37+
3638
class InvalidMutationException(Exception):
37-
"""This class is to define the InvalidMutationException
38-
"""
39-
pass
39+
"""This class is to define the InvalidMutationException
40+
"""
41+
pass
42+
4043

4144
class MutationBatch:
42-
"""This is the mutation batch class, it can generate and execute a batch of
43-
graphql's transaction.
44-
45-
Args:
46-
client (GraphQLClient Object, optional): Instance of the GraphQLClient.
47-
Defaults to None.
48-
label (str, optional): Label that will get each transaction of the batch.
49-
Defaults to 'mutation'.
50-
51-
Examples:
52-
>>> Batch example:
53-
with gql.batchMutate(label='mut') as batch:
54-
for author in authors:
55-
batch.add(
56-
muts.create_author, {
57-
'name': author['name']
58-
}
59-
)
60-
data, errors = batch.execute()
61-
print(data)
62-
63-
>>> Mutation simple example:
64-
mutation {
65-
label_1: mutationName(
66-
param1: valx
67-
param2: valy
68-
){
69-
response1
70-
}
71-
label_2: mutationName2(
72-
param1: valz
73-
){
74-
response2
75-
}
76-
}
77-
78-
>>> Mutation complex example:
79-
mutation MutationAlias(
80-
>>>$param1: Type1
81-
$param2: Type2
82-
$param3: Type3
83-
){
84-
label_1: mutationName(
85-
param1: $param1
86-
param2: $param2
87-
){
88-
response1
45+
"""This is the mutation batch class, it can generate and execute a batch of
46+
graphql's transaction.
47+
48+
Args:
49+
client (GraphQLClient Object, optional): Instance of the GraphQLClient.
50+
Defaults to None.
51+
label (str, optional): Label that will get each transaction of the batch.
52+
Defaults to 'mutation'.
53+
54+
Examples:
55+
>>> Batch example:
56+
with gql.batchMutate(label='mut') as batch:
57+
for author in authors:
58+
batch.add(
59+
muts.create_author, {
60+
'name': author['name']
61+
}
62+
)
63+
data, errors = batch.execute()
64+
# Process data and errors here
65+
66+
>>> Mutation simple example:
67+
mutation {
68+
label_1: mutationName(
69+
param1: valx
70+
param2: valy
71+
){
72+
response1
73+
}
74+
label_2: mutationName2(
75+
param1: valz
76+
){
77+
response2
78+
}
8979
}
90-
label_2: mutationName2(
91-
param1: $param3
92-
){
93-
response2
80+
81+
>>> Mutation complex example:
82+
mutation MutationAlias(
83+
>>>$param1: Type1
84+
$param2: Type2
85+
$param3: Type3
86+
){
87+
label_1: mutationName(
88+
param1: $param1
89+
param2: $param2
90+
){
91+
response1
92+
}
93+
label_2: mutationName2(
94+
param1: $param3
95+
){
96+
response2
97+
}
9498
}
95-
}
96-
97-
"""
98-
def __init__(self, client=None, label='mutation'):
99-
"""Constructor of the MutatuibBatch object.
99+
100100
"""
101-
self.client = client
102-
self.start_tag = 'mutation BatchMutation {'
103-
self.batch_doc = ''
104-
self.close_tag = '}'
105-
self.label = label
106-
self.count = 1
107-
108-
def __enter__(self):
109-
# print(f'setting things up with client {self.client}')
110-
return self
111-
112-
def __exit__(self, type, value, traceback):
113-
pass # print(f'tear down things in {self.client}')
114-
115-
def append(self, doc, variables={}):
116-
"""This function makes each transactions for the batch.
117101

118-
Args:
119-
doc (string): GraphQL transaction intructions.
120-
variables (dict, optional): Variables of the transaction. Defaults to {}.
102+
def __init__(self, client=None, label='mutation'):
103+
"""Constructor of the MutatuibBatch object.
104+
"""
105+
self.client = client
106+
self.start_tag = 'mutation BatchMutation {'
107+
self.batch_doc = ''
108+
self.close_tag = '}'
109+
self.label = label
110+
self.count = 1
121111

122-
Raises:
123-
InvalidMutationException: It raises when the doc is invalid.
124-
"""
125-
# extract document tokens
126-
mp = MutationParser(doc)
127-
valid_doc = mp.parse()
128-
if not valid_doc:
129-
raise InvalidMutationException('Invalid mutation document')
130-
# build batch mutation from extracted tokens
131-
parsed_doc = mp.content
132-
for key, value in variables.items():
133-
parsed_doc = parsed_doc.replace(f'${key}', mp.format_value(value))
134-
self.batch_doc += f'\t{self.label}_{self.count}: {parsed_doc}\n'
135-
self.count += 1
136-
137-
def get_doc(self):
138-
"""This function builds the transaction.
139-
140-
Returns:
141-
(string): Returns the full transaction, ready to execute.
142-
"""
143-
full_doc = f'''{self.start_tag}\n{self.batch_doc} {self.close_tag}'''
144-
return full_doc
112+
def __enter__(self):
113+
return self
145114

146-
def execute(self):
147-
"""This function can execute a TransactionBatch.
115+
def __exit__(self, type, value, traceback):
116+
pass
148117

149-
Returns:
150-
(GraphqlResponse): Returns the Graphql response.
151-
"""
152-
error_dict = {}
153-
data, errors = self.client.mutate(self.get_doc())
154-
if errors:
155-
error_dict['server'] = errors
156-
if data:
157-
for label, response in data.items():
158-
error_dict[label] = response.get('messages', [])
159-
return data, error_dict
118+
def append(self, doc, variables={}):
119+
"""This function makes each transactions for the batch.
120+
121+
Args:
122+
doc (string): GraphQL transaction intructions.
123+
variables (dict, optional): Variables of the transaction. Defaults to {}.
124+
125+
Raises:
126+
InvalidMutationException: It raises when the doc is invalid.
127+
"""
128+
# extract document tokens
129+
mp = MutationParser(doc)
130+
valid_doc = mp.parse()
131+
if not valid_doc:
132+
raise InvalidMutationException('Invalid mutation document')
133+
# build batch mutation from extracted tokens
134+
parsed_doc = mp.content
135+
for key, value in variables.items():
136+
parsed_doc = parsed_doc.replace(f'${key}', mp.format_value(value))
137+
self.batch_doc += f'\t{self.label}_{self.count}: {parsed_doc}\n'
138+
self.count += 1
139+
140+
def get_doc(self):
141+
"""This function builds the transaction.
142+
143+
Returns:
144+
(string): Returns the full transaction, ready to execute.
145+
"""
146+
full_doc = f'''{self.start_tag}\n{self.batch_doc} {self.close_tag}'''
147+
return full_doc
148+
149+
def execute(self):
150+
"""This function can execute a TransactionBatch.
151+
152+
Returns:
153+
(GraphqlResponse): Returns the Graphql response.
154+
"""
155+
error_dict = {}
156+
data, errors = self.client.mutate(self.get_doc())
157+
if errors:
158+
error_dict['server'] = errors
159+
if data:
160+
for label, response in data.items():
161+
error_dict[label] = response.get('messages', [])
162+
return data, error_dict

pygqlc/__main__.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
from .GraphQLClient import GraphQLClient
1+
from .GraphQLClient import GraphQLClient
2+
3+
24
def main():
3-
print('setup for GQL client')
4-
import os
5-
gql = GraphQLClient()
6-
gql.addEnvironment(
7-
'dev',
8-
url=os.environ.get('API'),
9-
wss=os.environ.get('WSS'),
10-
headers={'Authorization': os.environ.get('TOKEN')},
11-
default=True)
5+
print('setup for GQL client')
6+
import os
7+
gql = GraphQLClient()
8+
gql.addEnvironment(
9+
'dev',
10+
url=os.environ.get('API'),
11+
wss=os.environ.get('WSS'),
12+
headers={'Authorization': os.environ.get('TOKEN')},
13+
default=True)
14+
1215

1316
if __name__ == "__main__":
14-
main()
17+
main()

pygqlc/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '3.5.1'
1+
__version__ = '3.5.2'

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pygqlc"
3-
version = "3.5.1"
3+
version = "3.5.2"
44
description = "Python client for graphql APIs"
55
authors = ["Baruc Almaguer <baruc.almaguer@gmail.com>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)