everysk-lib 1.10.2__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- everysk/__init__.py +30 -0
- everysk/_version.py +683 -0
- everysk/api/__init__.py +61 -0
- everysk/api/api_requestor.py +167 -0
- everysk/api/api_resources/__init__.py +23 -0
- everysk/api/api_resources/api_resource.py +371 -0
- everysk/api/api_resources/calculation.py +779 -0
- everysk/api/api_resources/custom_index.py +42 -0
- everysk/api/api_resources/datastore.py +81 -0
- everysk/api/api_resources/file.py +42 -0
- everysk/api/api_resources/market_data.py +223 -0
- everysk/api/api_resources/parser.py +66 -0
- everysk/api/api_resources/portfolio.py +43 -0
- everysk/api/api_resources/private_security.py +42 -0
- everysk/api/api_resources/report.py +65 -0
- everysk/api/api_resources/report_template.py +39 -0
- everysk/api/api_resources/tests.py +115 -0
- everysk/api/api_resources/worker_execution.py +64 -0
- everysk/api/api_resources/workflow.py +65 -0
- everysk/api/api_resources/workflow_execution.py +93 -0
- everysk/api/api_resources/workspace.py +42 -0
- everysk/api/http_client.py +63 -0
- everysk/api/tests.py +32 -0
- everysk/api/utils.py +262 -0
- everysk/config.py +451 -0
- everysk/core/_tests/serialize/test_json.py +336 -0
- everysk/core/_tests/serialize/test_orjson.py +295 -0
- everysk/core/_tests/serialize/test_pickle.py +48 -0
- everysk/core/cloud_function/main.py +78 -0
- everysk/core/cloud_function/tests.py +86 -0
- everysk/core/compress.py +245 -0
- everysk/core/datetime/__init__.py +12 -0
- everysk/core/datetime/calendar.py +144 -0
- everysk/core/datetime/date.py +424 -0
- everysk/core/datetime/date_expression.py +299 -0
- everysk/core/datetime/date_mixin.py +1475 -0
- everysk/core/datetime/date_settings.py +30 -0
- everysk/core/datetime/datetime.py +713 -0
- everysk/core/exceptions.py +435 -0
- everysk/core/fields.py +1176 -0
- everysk/core/firestore.py +555 -0
- everysk/core/fixtures/_settings.py +29 -0
- everysk/core/fixtures/other/_settings.py +18 -0
- everysk/core/fixtures/user_agents.json +88 -0
- everysk/core/http.py +691 -0
- everysk/core/lists.py +92 -0
- everysk/core/log.py +709 -0
- everysk/core/number.py +37 -0
- everysk/core/object.py +1469 -0
- everysk/core/redis.py +1021 -0
- everysk/core/retry.py +51 -0
- everysk/core/serialize.py +674 -0
- everysk/core/sftp.py +414 -0
- everysk/core/signing.py +53 -0
- everysk/core/slack.py +127 -0
- everysk/core/string.py +199 -0
- everysk/core/tests.py +240 -0
- everysk/core/threads.py +199 -0
- everysk/core/undefined.py +70 -0
- everysk/core/unittests.py +73 -0
- everysk/core/workers.py +241 -0
- everysk/sdk/__init__.py +23 -0
- everysk/sdk/base.py +98 -0
- everysk/sdk/brutils/cnpj.py +391 -0
- everysk/sdk/brutils/cnpj_pd.py +129 -0
- everysk/sdk/engines/__init__.py +26 -0
- everysk/sdk/engines/cache.py +185 -0
- everysk/sdk/engines/compliance.py +37 -0
- everysk/sdk/engines/cryptography.py +69 -0
- everysk/sdk/engines/expression.cp312-win_amd64.pyd +0 -0
- everysk/sdk/engines/expression.pyi +55 -0
- everysk/sdk/engines/helpers.cp312-win_amd64.pyd +0 -0
- everysk/sdk/engines/helpers.pyi +26 -0
- everysk/sdk/engines/lock.py +120 -0
- everysk/sdk/engines/market_data.py +244 -0
- everysk/sdk/engines/settings.py +19 -0
- everysk/sdk/entities/__init__.py +23 -0
- everysk/sdk/entities/base.py +784 -0
- everysk/sdk/entities/base_list.py +131 -0
- everysk/sdk/entities/custom_index/base.py +209 -0
- everysk/sdk/entities/custom_index/settings.py +29 -0
- everysk/sdk/entities/datastore/base.py +160 -0
- everysk/sdk/entities/datastore/settings.py +17 -0
- everysk/sdk/entities/fields.py +375 -0
- everysk/sdk/entities/file/base.py +215 -0
- everysk/sdk/entities/file/settings.py +63 -0
- everysk/sdk/entities/portfolio/base.py +248 -0
- everysk/sdk/entities/portfolio/securities.py +241 -0
- everysk/sdk/entities/portfolio/security.py +580 -0
- everysk/sdk/entities/portfolio/settings.py +97 -0
- everysk/sdk/entities/private_security/base.py +226 -0
- everysk/sdk/entities/private_security/settings.py +17 -0
- everysk/sdk/entities/query.py +603 -0
- everysk/sdk/entities/report/base.py +214 -0
- everysk/sdk/entities/report/settings.py +23 -0
- everysk/sdk/entities/script.py +310 -0
- everysk/sdk/entities/secrets/base.py +128 -0
- everysk/sdk/entities/secrets/script.py +119 -0
- everysk/sdk/entities/secrets/settings.py +17 -0
- everysk/sdk/entities/settings.py +48 -0
- everysk/sdk/entities/tags.py +174 -0
- everysk/sdk/entities/worker_execution/base.py +307 -0
- everysk/sdk/entities/worker_execution/settings.py +63 -0
- everysk/sdk/entities/workflow_execution/base.py +113 -0
- everysk/sdk/entities/workflow_execution/settings.py +32 -0
- everysk/sdk/entities/workspace/base.py +99 -0
- everysk/sdk/entities/workspace/settings.py +27 -0
- everysk/sdk/settings.py +67 -0
- everysk/sdk/tests.py +105 -0
- everysk/sdk/worker_base.py +47 -0
- everysk/server/__init__.py +9 -0
- everysk/server/applications.py +63 -0
- everysk/server/endpoints.py +516 -0
- everysk/server/example_api.py +69 -0
- everysk/server/middlewares.py +80 -0
- everysk/server/requests.py +62 -0
- everysk/server/responses.py +119 -0
- everysk/server/routing.py +64 -0
- everysk/server/settings.py +36 -0
- everysk/server/tests.py +36 -0
- everysk/settings.py +98 -0
- everysk/sql/__init__.py +9 -0
- everysk/sql/connection.py +232 -0
- everysk/sql/model.py +376 -0
- everysk/sql/query.py +417 -0
- everysk/sql/row_factory.py +63 -0
- everysk/sql/settings.py +49 -0
- everysk/sql/utils.py +129 -0
- everysk/tests.py +23 -0
- everysk/utils.py +81 -0
- everysk/version.py +15 -0
- everysk_lib-1.10.2.dist-info/.gitignore +5 -0
- everysk_lib-1.10.2.dist-info/METADATA +326 -0
- everysk_lib-1.10.2.dist-info/RECORD +137 -0
- everysk_lib-1.10.2.dist-info/WHEEL +5 -0
- everysk_lib-1.10.2.dist-info/licenses/LICENSE.txt +9 -0
- everysk_lib-1.10.2.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
#
|
|
3
|
+
# (C) Copyright 2025 EVERYSK TECHNOLOGIES
|
|
4
|
+
#
|
|
5
|
+
# This is an unpublished work containing confidential and proprietary
|
|
6
|
+
# information of EVERYSK TECHNOLOGIES. Disclosure, use, or reproduction
|
|
7
|
+
# without authorization of EVERYSK TECHNOLOGIES is prohibited.
|
|
8
|
+
#
|
|
9
|
+
###############################################################################
|
|
10
|
+
from calendar import monthrange
|
|
11
|
+
|
|
12
|
+
from typing import Self
|
|
13
|
+
|
|
14
|
+
from everysk.core.datetime import date_settings
|
|
15
|
+
from everysk.core.exceptions import DateError
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class DateExpressionMixin:
|
|
19
|
+
|
|
20
|
+
@classmethod
|
|
21
|
+
def get_date_from_expression(cls, expression: str, year: int, month: int, day: str = None, calendar: str = None) -> Self: # pylint: disable=too-many-return-statements
|
|
22
|
+
"""
|
|
23
|
+
This function takes an expression, year, and a month, then
|
|
24
|
+
it returns a Date object containing the year, month, and day that correspond to
|
|
25
|
+
the `expression` passed as input.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
expression (str): The expression that contains an element that will be used to extract the date.
|
|
29
|
+
year (int): The desired year for the date
|
|
30
|
+
month (int): The desired month for the date.
|
|
31
|
+
calendar (str, optional): The Calendar that will be used to extract the holidays. Defaults to None.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
Date: The Date object containing the date based on the expression elements.
|
|
35
|
+
|
|
36
|
+
Example:
|
|
37
|
+
Get the 15th day of January in the year 2024
|
|
38
|
+
>>> Date.get_date_from_expression('15th day', 2024, 1)
|
|
39
|
+
Date(2024, 1, 15)
|
|
40
|
+
|
|
41
|
+
Get the 15th business day of January in the year 2024
|
|
42
|
+
>>> Date.get_date_from_expression('15th bizday', 2024, 1, calendar='ANBIMA')
|
|
43
|
+
Date(2024, 1, 29)
|
|
44
|
+
|
|
45
|
+
Get the date of the previous business day
|
|
46
|
+
>>> Date.get_date_from_expression('previous bizday', 2024, 8, 16, calendar='ANBIMA')
|
|
47
|
+
Date(2024, 8, 15)
|
|
48
|
+
|
|
49
|
+
Get the date of the next business day
|
|
50
|
+
>>> Date.get_date_from_expression('next bizday', 2024, 8, 16, calendar='ANBIMA')
|
|
51
|
+
Date(2024, 8, 19)
|
|
52
|
+
|
|
53
|
+
Get first Wednesday which is a Business day after a specific day
|
|
54
|
+
>>> Date.get_date_from_expression('first wed bizday after 15th day', 2024, 11, calendar='ANBIMA')
|
|
55
|
+
Date(2024, 11, 27)
|
|
56
|
+
|
|
57
|
+
Get first Wednesday which is a Business day before a specific day
|
|
58
|
+
>>> Date.get_date_from_expression('first wed bizday before 15th day', 2024, 11, calendar='ANBIMA')
|
|
59
|
+
>>> Date(2024, 11, 13)
|
|
60
|
+
"""
|
|
61
|
+
token = expression.lower().split()
|
|
62
|
+
|
|
63
|
+
if len(token) == 2:
|
|
64
|
+
num = cls._convert_ordinal_to_number(token[0])
|
|
65
|
+
|
|
66
|
+
if token[0] in ('previous', 'next') and token[1] == 'bizday':
|
|
67
|
+
return cls._calculate_positional_business_day(token[0], year, month, day, calendar)
|
|
68
|
+
|
|
69
|
+
if token[1] == 'day':
|
|
70
|
+
return cls._calculate_ordinal_day(num, year, month)
|
|
71
|
+
|
|
72
|
+
if token[1] == 'bizday':
|
|
73
|
+
return cls._calculate_ordinal_business_day(num, year, month, calendar)
|
|
74
|
+
|
|
75
|
+
raise ValueError(f'Invalid day: {token[1]}')
|
|
76
|
+
|
|
77
|
+
if len(token) == 5:
|
|
78
|
+
if token[0] not in ('first', 'second', 'third'):
|
|
79
|
+
raise ValueError(f'Invalid Written Ordinal: {token[0]}')
|
|
80
|
+
|
|
81
|
+
day_number = cls._convert_ordinal_to_number(token[3])
|
|
82
|
+
day_position = cls._convert_ordinal_to_number(token[0])
|
|
83
|
+
|
|
84
|
+
if token[2] == 'after':
|
|
85
|
+
return cls._calculate_bizday_relative_to_specific_date(day_number, day_position, year, month, calendar)
|
|
86
|
+
|
|
87
|
+
if token[2] == 'before':
|
|
88
|
+
return cls._calculate_bizday_relative_to_specific_date(day_number, -day_position, year, month, calendar)
|
|
89
|
+
|
|
90
|
+
raise ValueError(f'Invalid expression: {token[2]}, the day reference must be either "before" or "after"')
|
|
91
|
+
|
|
92
|
+
if len(token) == 6:
|
|
93
|
+
if token[0] not in ('first', 'second', 'third'):
|
|
94
|
+
raise ValueError(f'Invalid Written Ordinal: {token[0]}, it must be either "first", "second", or "third"')
|
|
95
|
+
|
|
96
|
+
day_position = cls._convert_ordinal_to_number(token[0])
|
|
97
|
+
|
|
98
|
+
day_number = cls._convert_ordinal_to_number(token[4])
|
|
99
|
+
|
|
100
|
+
if token[1] in date_settings.WEEKDAYS and token[2] == 'bizday' and token[3] in ('after', 'before'):
|
|
101
|
+
return cls._calculate_bizday_relative_to_specific_date_and_week_day(token[1], day_position, day_number, year, month, token[3], calendar)
|
|
102
|
+
|
|
103
|
+
raise ValueError('Invalid expression, please verify the day type or the week days')
|
|
104
|
+
|
|
105
|
+
raise ValueError(f'Invalid expression: {expression}, please refer to the documentation.')
|
|
106
|
+
|
|
107
|
+
@classmethod
|
|
108
|
+
def _convert_ordinal_to_number(cls, nth: str) -> int:
|
|
109
|
+
"""
|
|
110
|
+
This method takes a string that represents a date in ordinal format
|
|
111
|
+
and returns an integer accordingly.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
nth (str): The expression that includes date number
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
int: The integer that represents the date in the previous format string.
|
|
118
|
+
|
|
119
|
+
Example:
|
|
120
|
+
>>> _convert_ordinal_to_number("first")
|
|
121
|
+
1
|
|
122
|
+
|
|
123
|
+
>>> _convert_ordinal_to_number("second")
|
|
124
|
+
2
|
|
125
|
+
|
|
126
|
+
>>> _convert_ordinal_to_number("18th day")
|
|
127
|
+
18
|
|
128
|
+
|
|
129
|
+
>>> _convert_ordinal_to_number("22th day")
|
|
130
|
+
22
|
|
131
|
+
"""
|
|
132
|
+
if nth == 'first':
|
|
133
|
+
return 1
|
|
134
|
+
|
|
135
|
+
if nth == 'second':
|
|
136
|
+
return 2
|
|
137
|
+
|
|
138
|
+
if nth == 'third':
|
|
139
|
+
return 3
|
|
140
|
+
|
|
141
|
+
if nth == 'last':
|
|
142
|
+
return -1
|
|
143
|
+
|
|
144
|
+
if nth[-2:] in ('th', 'st', 'nd', 'rd'):
|
|
145
|
+
return int(nth[:-2])
|
|
146
|
+
|
|
147
|
+
if nth in ('previous', 'next'):
|
|
148
|
+
return 1
|
|
149
|
+
|
|
150
|
+
raise ValueError(f'Invalid nth: {nth}')
|
|
151
|
+
|
|
152
|
+
@classmethod
|
|
153
|
+
def _calculate_positional_business_day(cls, position: str, year: int, month: int, day: int, calendar: str = None) -> Self:
|
|
154
|
+
"""
|
|
155
|
+
This private method takes a position, that will be either "previous" or "next", and returns
|
|
156
|
+
the a business day based on the `position` argument.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
position (str): The position that will be taken into account for the Date calculation. This will be either "previous" or "next".
|
|
160
|
+
year (int): The year desired.
|
|
161
|
+
month (int): The month desired.
|
|
162
|
+
day (int): The day which will be used for reference for the position.
|
|
163
|
+
calendar (str, optional): The type of calendar that will be used for business days or holidays. Defaults to None.
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
Date: The Date object containing the date based on the position
|
|
167
|
+
"""
|
|
168
|
+
if position == 'previous':
|
|
169
|
+
return cls(year, month, day).bizdays_delta(-1, calendar) # pylint: disable=no-member
|
|
170
|
+
|
|
171
|
+
return cls(year, month, day).bizdays_delta(1, calendar) # pylint: disable=no-member
|
|
172
|
+
|
|
173
|
+
@classmethod
|
|
174
|
+
def _calculate_ordinal_day(cls, num: int, year: int, month: int) -> Self:
|
|
175
|
+
"""
|
|
176
|
+
This private method takes a day number, year, and month then it simply converts
|
|
177
|
+
to a Date object.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
num (int): The day number.
|
|
181
|
+
year (int): The year desired.
|
|
182
|
+
month (int, optional): The month number.
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
Date: The Date object with `year`, `month`, and `num` respectively.
|
|
186
|
+
"""
|
|
187
|
+
if num == -1:
|
|
188
|
+
num = monthrange(year, month)[1]
|
|
189
|
+
|
|
190
|
+
return cls(year, month, num)
|
|
191
|
+
|
|
192
|
+
@classmethod
|
|
193
|
+
def _calculate_ordinal_business_day(cls, num: int, year: int, month: int, calendar: str = None) -> Self:
|
|
194
|
+
"""
|
|
195
|
+
This private method takes a day number, month, and year then returns a Date object containing
|
|
196
|
+
the date corresponding to the `num` nth business day of that year and month.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
num (int): The ordinal date converted to integer.
|
|
200
|
+
year (int): The year to perform the calculation.
|
|
201
|
+
month (int): The month number for the calculation.
|
|
202
|
+
calendar (str, optional): The calendar that will be used with the dates.
|
|
203
|
+
|
|
204
|
+
Returns:
|
|
205
|
+
Date: The Date object with the corresponding date accounted for bizdays.
|
|
206
|
+
"""
|
|
207
|
+
start_date = cls(year, month, 1).get_first_day_of_month(True, calendar)
|
|
208
|
+
end_date = cls(year, month, 1).get_last_day_of_month(True, calendar)
|
|
209
|
+
list_of_bizdays_for_the_month = cls.bizdays_range(start_date, end_date.bizdays_delta(1), calendar)
|
|
210
|
+
|
|
211
|
+
try:
|
|
212
|
+
if num == -1:
|
|
213
|
+
return list_of_bizdays_for_the_month[num]
|
|
214
|
+
|
|
215
|
+
return list_of_bizdays_for_the_month[num - 1]
|
|
216
|
+
|
|
217
|
+
except IndexError as error:
|
|
218
|
+
raise DateError(f'Invalid Business Day, the current month only has {cls._calculate_number_of_bizdays_for_the_month(year, month, calendar)}, your value was {num}') from error
|
|
219
|
+
|
|
220
|
+
@classmethod
|
|
221
|
+
def _calculate_bizday_relative_to_specific_date(cls, day_number: int, ordinal_position: str, year: int, month: int, calendar: str = None) -> Self:
|
|
222
|
+
"""
|
|
223
|
+
This private method is used to perform the calculation for retrieving a Date
|
|
224
|
+
before or after a specific date using a set of inputs.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
day_number (int): The integer that corresponds to the day of the month.
|
|
228
|
+
ordinal_position (str): The ordinal format of one, two, and three.
|
|
229
|
+
year (int): The year for the calculation.
|
|
230
|
+
month (int): The month for the calculation.
|
|
231
|
+
calendar (str, optional): The calendar that will be used for extracting business days or holidays. Defaults to None.
|
|
232
|
+
|
|
233
|
+
Returns:
|
|
234
|
+
Date: The Date object that will contain the business day before or after a specific date.
|
|
235
|
+
"""
|
|
236
|
+
current_date = cls(year, month, day_number)
|
|
237
|
+
current_date = current_date.bizdays_delta(ordinal_position, calendar) # pylint: disable=no-member
|
|
238
|
+
|
|
239
|
+
return current_date
|
|
240
|
+
|
|
241
|
+
@classmethod
|
|
242
|
+
def _calculate_bizday_relative_to_specific_date_and_week_day(cls, day_of_week: str, day_position: str, day_number: int, year: int, month: int, date_reference: str, calendar: str = None) -> Self:
|
|
243
|
+
"""
|
|
244
|
+
This private method is used in order to calculate a specific business day thats either before or
|
|
245
|
+
after a date and week day.
|
|
246
|
+
|
|
247
|
+
Args:
|
|
248
|
+
day_of_week (str): The day name.
|
|
249
|
+
day_position (str): The position of the date, it can be first, second, or third.
|
|
250
|
+
day_number (int): The day of the month.
|
|
251
|
+
year (int): The year for the calculation.
|
|
252
|
+
month (int): The month for the calculation.
|
|
253
|
+
calendar (str, optional): The type of calendar that will be usd for the business days and holidays. Defaults to None.
|
|
254
|
+
|
|
255
|
+
Raises:
|
|
256
|
+
ValueError: If the date reference is invalid, it will raise an error
|
|
257
|
+
|
|
258
|
+
Returns:
|
|
259
|
+
Date: The Date object containing the date calculated.
|
|
260
|
+
"""
|
|
261
|
+
current_date = cls(year, month, day_number)
|
|
262
|
+
bizdays_for_the_day_name = []
|
|
263
|
+
|
|
264
|
+
if date_reference == 'before':
|
|
265
|
+
start_date = cls(year, month, day_number).months_delta(-1).get_first_day_of_month(True, calendar) # pylint: disable=no-member
|
|
266
|
+
list_of_bizdays = cls.bizdays_range(start_date, current_date, calendar) # pylint: disable=no-member
|
|
267
|
+
|
|
268
|
+
elif date_reference == 'after':
|
|
269
|
+
end_date = cls(year, month, day_number).months_delta(1).get_last_day_of_month(True, calendar) # pylint: disable=no-member
|
|
270
|
+
list_of_bizdays = cls.bizdays_range(current_date, end_date, calendar) # pylint: disable=no-member
|
|
271
|
+
|
|
272
|
+
else:
|
|
273
|
+
raise ValueError(f'Invalid date reference: {date_reference}')
|
|
274
|
+
|
|
275
|
+
for days in list_of_bizdays:
|
|
276
|
+
if day_of_week in days.day_name.lower():
|
|
277
|
+
bizdays_for_the_day_name.append(days)
|
|
278
|
+
|
|
279
|
+
return bizdays_for_the_day_name[-day_position if date_reference == 'before' else day_position -1]
|
|
280
|
+
|
|
281
|
+
@classmethod
|
|
282
|
+
def _calculate_number_of_bizdays_for_the_month(cls, year: int, month: int, calendar: str = None) -> int:
|
|
283
|
+
"""
|
|
284
|
+
This method takes a year, a month, and optionally a calendar, then returns an
|
|
285
|
+
integer indicating the number of business days for the month.
|
|
286
|
+
|
|
287
|
+
Args:
|
|
288
|
+
year (int): The year for the calculation.
|
|
289
|
+
month (int): The month for the calculation
|
|
290
|
+
calendar (str, optional): The type of calendar to extract the business days or holidays. Defaults to None.
|
|
291
|
+
|
|
292
|
+
Returns:
|
|
293
|
+
int: The number of business days for the month
|
|
294
|
+
"""
|
|
295
|
+
start_date = cls(year, month, 1).get_first_day_of_month(True, calendar) # pylint: disable=no-member
|
|
296
|
+
end_date = cls(year, month, 1).get_last_day_of_month(True, calendar) # pylint: disable=no-member
|
|
297
|
+
list_of_bizdays = cls.bizdays_range(start_date, end_date.bizdays_delta(1), calendar) # pylint: disable=no-member
|
|
298
|
+
|
|
299
|
+
return len(list_of_bizdays)
|