Endpoints adapters (Domains)¶
Endpoints are grouped under tags which represent a domain exposed by the API.
Calendar API exposes 2 domains:
- Holidays: Holidays related operations
- Bdays: Business Days related operations
Conceptually if we merge the results of both of them we will have the whole calendar
In the client side, the domains are represented as Resource adapters
BaseMixin
¶
BaseMixin(client: Client, endpoints: dict = None, **kwargs)
Mixin Base class for resource-interaction with Calendar API.
Attributes:
-
resource_name(str) –Resource canonical name
-
model_type(ModelT) –Default model class of an endpoint
-
endpoints(dict) –A mapping of operation keys and endpoint URLS. Each operation has a unique key in the dict
Methods:
-
endpoint_by_operation–Retrieve the endpoint URL from the deined method key in URLS (self.endpoints)
-
host_url–Returns the host url from the client.
self.client.base_urlcontains the/api/v1path to ease the definition of operation keys. -
json_from_response_or_raise–Extract the json payload from the Response.
Source code in pycalendar_api/domains/base.py
26 27 28 29 30 31 32 33 | |
endpoint_by_operation
¶
Retrieve the endpoint URL from the deined method key in URLS (self.endpoints) the key is in the form of {self.resource_name}:{method}.
Parameters:
Returns:
-
str(str) –Endpoint URL
Raises:
-
CalendarAPIParamError–Method not defined
Source code in pycalendar_api/domains/base.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
host_url
¶
host_url() -> str
Returns the host url from the client. self.client.base_url contains the /api/v1 path to ease the definition of operation keys.
Source code in pycalendar_api/domains/base.py
54 55 56 57 58 | |
json_from_response_or_raise
staticmethod
¶
Extract the json payload from the Response.
Parameters:
-
(response¶Response) –httpx Response
-
(error_key¶(str, detail), default:'detail') –Error key name in the Json body
Returns:
-
dict(dict) –Json extracted from the response
Raises:
-
CalendarAPIClientError–If the HTTP response status is >= 400
Source code in pycalendar_api/domains/base.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
HolidaysResource
¶
HolidaysResource(client: Session)
Methods:
-
endpoint_by_operation–Retrieve the endpoint URL from the deined method key in URLS (self.endpoints)
-
host_url–Returns the host url from the client.
self.client.base_urlcontains the/api/v1path to ease the definition of operation keys. -
is_holiday–Verify if the provided date is a Holiday. If True, also returns the description of that Holiday and its type.
-
json_from_response_or_raise–Extract the json payload from the Response.
-
year–Get the holidays of a year
-
years–Get the holidays of many years
Source code in pycalendar_api/domains/holidays.py
17 18 | |
endpoint_by_operation
¶
Retrieve the endpoint URL from the deined method key in URLS (self.endpoints) the key is in the form of {self.resource_name}:{method}.
Parameters:
Returns:
-
str(str) –Endpoint URL
Raises:
-
CalendarAPIParamError–Method not defined
Source code in pycalendar_api/domains/base.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
host_url
¶
host_url() -> str
Returns the host url from the client. self.client.base_url contains the /api/v1 path to ease the definition of operation keys.
Source code in pycalendar_api/domains/base.py
54 55 56 57 58 | |
is_holiday
¶
is_holiday(date: date) -> HolidayCheckResult
Verify if the provided date is a Holiday. If True, also returns the description of that Holiday and its type.
Parameters:
Returns:
-
HolidayCheckResult(HolidayCheckResult) –Result of the verification
Source code in pycalendar_api/domains/holidays.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
json_from_response_or_raise
staticmethod
¶
Extract the json payload from the Response.
Parameters:
-
(response¶Response) –httpx Response
-
(error_key¶(str, detail), default:'detail') –Error key name in the Json body
Returns:
-
dict(dict) –Json extracted from the response
Raises:
-
CalendarAPIClientError–If the HTTP response status is >= 400
Source code in pycalendar_api/domains/base.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
year
¶
year(
year: int, *, holiday_type: CalHolidayType = None
) -> list[Holiday]
Get the holidays of a year
Parameters:
-
(year¶int) –the Year
-
(holiday_type¶`CalHolidayType`, default:None) –Optional filter on holiday type. See
CalHolidayType
Returns:
Source code in pycalendar_api/domains/holidays.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
years
¶
years(
years: Iterable[int],
*,
holiday_type: CalHolidayType = None
) -> list[Holiday]
Get the holidays of many years
Parameters:
-
(years¶Iterable[int]) –Iterable of years as int
-
(holiday_type¶`CalHolidayType`, default:None) –Optional filter on holiday type. See
CalHolidayType
Returns:
Source code in pycalendar_api/domains/holidays.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
BDaysResource
¶
BDaysResource(client: Session)
Methods:
-
bdays_of–Get the Business days of a year.
-
between–Get the Business days between 2 dates
-
count–Count the business days (inclusive) between 2 dates
-
endpoint_by_operation–Retrieve the endpoint URL from the deined method key in URLS (self.endpoints)
-
host_url–Returns the host url from the client.
self.client.base_urlcontains the/api/v1path to ease the definition of operation keys. -
json_from_response_or_raise–Extract the json payload from the Response.
-
next_date–Returns the
nextBusiness day following the provided date -
previous_date–Returns the
previousBusiness day before the provided date -
span–Get the Start/End dates of periods (Quarters, Semesters, Months) in the form of ]
Start,End] (Open-Close Interval).
Source code in pycalendar_api/domains/bdays.py
17 18 | |
bdays_of
¶
Get the Business days of a year.
Parameters:
-
(year¶int) –the year
-
(month¶int, default:None) –If provided returns the business days of that month
Returns:
-
DateSeries(DateSeries) –Ordered Set of dates. The collection is under
DateSeries.serie
Source code in pycalendar_api/domains/bdays.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
between
¶
Get the Business days between 2 dates
Parameters:
Returns:
-
DateSeries(DateSeries) –Ordered Set of dates. The collection is under
DateSeries.serie
Source code in pycalendar_api/domains/bdays.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
count
¶
Count the business days (inclusive) between 2 dates
Parameters:
Returns:
-
DaysCount(DaysCount) –Days count datastruct
Source code in pycalendar_api/domains/bdays.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
endpoint_by_operation
¶
Retrieve the endpoint URL from the deined method key in URLS (self.endpoints) the key is in the form of {self.resource_name}:{method}.
Parameters:
Returns:
-
str(str) –Endpoint URL
Raises:
-
CalendarAPIParamError–Method not defined
Source code in pycalendar_api/domains/base.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
host_url
¶
host_url() -> str
Returns the host url from the client. self.client.base_url contains the /api/v1 path to ease the definition of operation keys.
Source code in pycalendar_api/domains/base.py
54 55 56 57 58 | |
json_from_response_or_raise
staticmethod
¶
Extract the json payload from the Response.
Parameters:
-
(response¶Response) –httpx Response
-
(error_key¶(str, detail), default:'detail') –Error key name in the Json body
Returns:
-
dict(dict) –Json extracted from the response
Raises:
-
CalendarAPIClientError–If the HTTP response status is >= 400
Source code in pycalendar_api/domains/base.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
next_date
¶
Returns the next Business day following the provided date
Parameters:
Returns:
-
NextDate(NextDate) –Contains the requested date and the next open date
Source code in pycalendar_api/domains/bdays.py
76 77 78 79 80 81 82 83 84 85 86 87 88 | |
previous_date
¶
previous_date(date: date) -> PreviousDate
Returns the previous Business day before the provided date
Parameters:
Returns:
-
PreviousDate(PreviousDate) –Contains the requested date and the previous open date
Source code in pycalendar_api/domains/bdays.py
90 91 92 93 94 95 96 97 98 99 100 101 102 | |
span
¶
Get the Start/End dates of periods (Quarters, Semesters, Months) in the form of ]Start, End] (Open-Close Interval).
-
Start: The last Open Business day of the previous period -
End: The last Open Business day of the period
Parameters:
-
(year¶int) –Span of a year
-
(month¶int, default:None) –Span of a month, 1 <= month <= 12
-
(quarter¶int, default:None) –Span of a quarter, 1 <= quarter <= 4
-
(semester¶int, default:None) –Span of a semester, 1 <= semester <= 2
Returns:
-
CalSpan(CalSpan) –Span interval of the requested period
Raises:
-
CalendarAPIParamError–Only one of the periods must be provided.
Source code in pycalendar_api/domains/bdays.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |