-
Notifications
You must be signed in to change notification settings - Fork 29
/
module_reference.html
1349 lines (1240 loc) · 116 KB
/
module_reference.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<title>Module Reference — PagerDuty Python REST API Sessions 5.1.2 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/sphinx_highlight.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Contribution Guide" href="contributing.html" />
<link rel="prev" title="User Guide" href="user_guide.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head><body>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="module-reference">
<span id="id1"></span><h1>Module Reference<a class="headerlink" href="#module-reference" title="Permalink to this heading">¶</a></h1>
<p>This page covers the documentation of individual methods and classes provided
by the module. For general usage and examples, refer to the <a class="reference internal" href="user_guide.html#user-guide"><span class="std std-ref">User Guide</span></a>.</p>
<section id="api-client-classes">
<h2>API Client Classes<a class="headerlink" href="#api-client-classes" title="Permalink to this heading">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="pdpyras.PDSession">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">PDSession</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">api_key</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">debug</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.PDSession" title="Permalink to this definition">¶</a></dt>
<dd><p>Base class for making HTTP requests to PagerDuty APIs</p>
<p>This is an opinionated wrapper of <a class="reference external" href="https://docs.python-requests.org/en/master/api/#request-sessions">requests.Session</a>, with a few additional
features:</p>
<ul class="simple">
<li><p>The client will reattempt the request with auto-increasing cooldown/retry
intervals, with attempt limits configurable through the <a class="reference internal" href="#pdpyras.PDSession.retry" title="pdpyras.PDSession.retry"><code class="xref py py-attr docutils literal notranslate"><span class="pre">retry</span></code></a>
attribute.</p></li>
<li><p>When making requests, headers specified ad-hoc in calls to HTTP verb
functions will not replace, but will be merged into, default headers.</p></li>
<li><p>The request URL, if it doesn’t already start with the REST API base URL,
will be prepended with the default REST API base URL.</p></li>
<li><p>It will only perform requests with methods as given in the
<a class="reference internal" href="#pdpyras.PDSession.permitted_methods" title="pdpyras.PDSession.permitted_methods"><code class="xref py py-attr docutils literal notranslate"><span class="pre">permitted_methods</span></code></a> list, and will raise <a class="reference internal" href="#pdpyras.PDClientError" title="pdpyras.PDClientError"><code class="xref py py-class docutils literal notranslate"><span class="pre">PDClientError</span></code></a> for
any other HTTP methods.</p></li>
</ul>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>api_key</strong> – REST API access token to use for HTTP requests</p></li>
<li><p><strong>debug</strong> (<em>bool</em>) – Sets <a class="reference internal" href="#pdpyras.PDSession.print_debug" title="pdpyras.PDSession.print_debug"><code class="xref py py-attr docutils literal notranslate"><span class="pre">print_debug</span></code></a>. Set to True to enable verbose command line
output.</p></li>
</ul>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.PDSession.after_set_api_key">
<span class="sig-name descname"><span class="pre">after_set_api_key</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.PDSession.after_set_api_key" title="Permalink to this definition">¶</a></dt>
<dd><p>Setter hook for setting or updating the API key.</p>
<p>Child classes should implement this to perform additional steps.</p>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="pdpyras.PDSession.api_key">
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">api_key</span></span><a class="headerlink" href="#pdpyras.PDSession.api_key" title="Permalink to this definition">¶</a></dt>
<dd><p>API Key property getter.</p>
<p>Returns the _api_key attribute’s value.</p>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="pdpyras.PDSession.auth_header">
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">auth_header</span></span><a class="headerlink" href="#pdpyras.PDSession.auth_header" title="Permalink to this definition">¶</a></dt>
<dd><p>Generates the header with the API credential used for authentication.</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.PDSession.log">
<span class="sig-name descname"><span class="pre">log</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#pdpyras.PDSession.log" title="Permalink to this definition">¶</a></dt>
<dd><p>A <code class="docutils literal notranslate"><span class="pre">logging.Logger</span></code> object for logging messages. By default it is
configured without any handlers and so no messages will be emitted. See
<a class="reference external" href="https://docs.python.org/3/library/logging.html#logger-objects">logger objects</a></p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.PDSession.max_http_attempts">
<span class="sig-name descname"><span class="pre">max_http_attempts</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">10</span></em><a class="headerlink" href="#pdpyras.PDSession.max_http_attempts" title="Permalink to this definition">¶</a></dt>
<dd><p>The number of times that the client will retry after error statuses, for any
that are defined greater than zero in <a class="reference internal" href="#pdpyras.PDSession.retry" title="pdpyras.PDSession.retry"><code class="xref py py-attr docutils literal notranslate"><span class="pre">retry</span></code></a>.</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.PDSession.max_network_attempts">
<span class="sig-name descname"><span class="pre">max_network_attempts</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">3</span></em><a class="headerlink" href="#pdpyras.PDSession.max_network_attempts" title="Permalink to this definition">¶</a></dt>
<dd><p>The number of times that connecting to the API will be attempted before
treating the failure as non-transient; a <a class="reference internal" href="#pdpyras.PDClientError" title="pdpyras.PDClientError"><code class="xref py py-class docutils literal notranslate"><span class="pre">PDClientError</span></code></a> exception
will be raised if this happens.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.PDSession.normalize_params">
<span class="sig-name descname"><span class="pre">normalize_params</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">params</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.PDSession.normalize_params" title="Permalink to this definition">¶</a></dt>
<dd><p>Modify the user-supplied parameters.</p>
<p>Current behavior:</p>
<ul class="simple">
<li><p>If a parameter’s value is of type list, and the parameter name does
not already end in “[]”, then the square brackets are appended to keep
in line with the requirement that all set filters’ parameter names end
in “[]”.</p></li>
</ul>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.PDSession.normalize_url">
<span class="sig-name descname"><span class="pre">normalize_url</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.PDSession.normalize_url" title="Permalink to this definition">¶</a></dt>
<dd><p>Compose the URL whether it is a path or an already-complete URL</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.PDSession.parent">
<span class="sig-name descname"><span class="pre">parent</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#pdpyras.PDSession.parent" title="Permalink to this definition">¶</a></dt>
<dd><p>The <code class="docutils literal notranslate"><span class="pre">super</span></code> object (<a class="reference external" href="https://docs.python-requests.org/en/master/api/#request-sessions">requests.Session</a>)</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.PDSession.permitted_methods">
<span class="sig-name descname"><span class="pre">permitted_methods</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">()</span></em><a class="headerlink" href="#pdpyras.PDSession.permitted_methods" title="Permalink to this definition">¶</a></dt>
<dd><p>A tuple of the methods permitted by the API which the client implements.</p>
<p>For instance:</p>
<ul class="simple">
<li><p>The REST API accepts GET, POST, PUT and DELETE.</p></li>
<li><p>The Events API and Change Events APIs only accept POST.</p></li>
</ul>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.PDSession.postprocess">
<span class="sig-name descname"><span class="pre">postprocess</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">response</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.PDSession.postprocess" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform supplemental actions immediately after receiving a response.</p>
<p>This method is called once per request not including retries, and can be
extended in child classes.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.PDSession.prepare_headers">
<span class="sig-name descname"><span class="pre">prepare_headers</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">method</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">user_headers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">{}</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.PDSession.prepare_headers" title="Permalink to this definition">¶</a></dt>
<dd><p>Append special additional per-request headers.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>method</strong> – The HTTP method, in upper case.</p></li>
<li><p><strong>user_headers</strong> – Headers that can be specified to override default values.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="pdpyras.PDSession.print_debug">
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">print_debug</span></span><a class="headerlink" href="#pdpyras.PDSession.print_debug" title="Permalink to this definition">¶</a></dt>
<dd><p>Printing debug flag</p>
<p>If set to True, the logging level of <a class="reference internal" href="#pdpyras.PDSession.log" title="pdpyras.PDSession.log"><code class="xref py py-attr docutils literal notranslate"><span class="pre">log</span></code></a> is set to
<code class="docutils literal notranslate"><span class="pre">logging.DEBUG</span></code> and all log messages are emitted to <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>.
If set to False, the logging level of <a class="reference internal" href="#pdpyras.PDSession.log" title="pdpyras.PDSession.log"><code class="xref py py-attr docutils literal notranslate"><span class="pre">log</span></code></a> is set to
<code class="docutils literal notranslate"><span class="pre">logging.NOTSET</span></code> and the debugging log handler that prints messages to
<code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> is removed. This value thus can be toggled to enable and
disable verbose command line output.</p>
<p>It is <code class="docutils literal notranslate"><span class="pre">False</span></code> by default and it is recommended to keep it that way in
production settings.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.PDSession.request">
<span class="sig-name descname"><span class="pre">request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">method</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">url</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.PDSession.request" title="Permalink to this definition">¶</a></dt>
<dd><p>Make a generic PagerDuty API request.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>method</strong> (<em>str</em>) – The request method to use. Case-insensitive. May be one of get, put,
post or delete.</p></li>
<li><p><strong>url</strong> (<em>str</em>) – The path/URL to request. If it does not start with the base URL, the
base URL will be prepended.</p></li>
<li><p><strong>**kwargs</strong> – Additional keyword arguments to pass to <a class="reference external" href="https://docs.python-requests.org/en/master/">Requests</a></p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>the HTTP response object</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p><a class="reference external" href="https://docs.python-requests.org/en/master/api/#requests.Response">requests.Response</a></p>
</dd>
</dl>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.PDSession.retry">
<span class="sig-name descname"><span class="pre">retry</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">{}</span></em><a class="headerlink" href="#pdpyras.PDSession.retry" title="Permalink to this definition">¶</a></dt>
<dd><p>A dict defining the retry behavior for each HTTP response status code.</p>
<p>Note, any value set for this class variable will not be reflected in
instances and so it must be set separately for each instance.</p>
<p>Each key in this dictionary is an int representing a HTTP response code. The
behavior is specified by the int value at each key as follows:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">-1</span></code> to retry infinitely</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">0</span></code> to return the <a class="reference external" href="https://docs.python-requests.org/en/master/api/#requests.Response">requests.Response</a> object and exit (which is the
default behavior)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">n</span></code>, where <code class="docutils literal notranslate"><span class="pre">n</span> <span class="pre">></span> <span class="pre">0</span></code>, to retry <code class="docutils literal notranslate"><span class="pre">n</span></code> times (or up
to <a class="reference internal" href="#pdpyras.PDSession.max_http_attempts" title="pdpyras.PDSession.max_http_attempts"><code class="xref py py-attr docutils literal notranslate"><span class="pre">max_http_attempts</span></code></a> total for all statuses, whichever is
encountered first), and raise a <a class="reference internal" href="#pdpyras.PDClientError" title="pdpyras.PDClientError"><code class="xref py py-class docutils literal notranslate"><span class="pre">PDClientError</span></code></a> after that many
attempts. For each successive attempt, the wait time will increase by a
factor of <a class="reference internal" href="#pdpyras.PDSession.sleep_timer_base" title="pdpyras.PDSession.sleep_timer_base"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sleep_timer_base</span></code></a>.</p></li>
</ul>
<p>The default behavior is to retry infinitely on a 429, and return the
response in any other case (assuming a HTTP response was received from the
server).</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.PDSession.sleep_timer">
<span class="sig-name descname"><span class="pre">sleep_timer</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">1.5</span></em><a class="headerlink" href="#pdpyras.PDSession.sleep_timer" title="Permalink to this definition">¶</a></dt>
<dd><p>Default initial cooldown time factor for rate limiting and network errors.</p>
<p>Each time that the request makes a followup request, there will be a delay
in seconds equal to this number times <a class="reference internal" href="#pdpyras.PDSession.sleep_timer_base" title="pdpyras.PDSession.sleep_timer_base"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sleep_timer_base</span></code></a> to the power
of how many attempts have already been made so far, unless
<a class="reference internal" href="#pdpyras.PDSession.stagger_cooldown" title="pdpyras.PDSession.stagger_cooldown"><code class="xref py py-attr docutils literal notranslate"><span class="pre">stagger_cooldown</span></code></a> is nonzero.</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.PDSession.sleep_timer_base">
<span class="sig-name descname"><span class="pre">sleep_timer_base</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">2</span></em><a class="headerlink" href="#pdpyras.PDSession.sleep_timer_base" title="Permalink to this definition">¶</a></dt>
<dd><p>After each retry, the time to sleep before reattempting the API connection
and request will increase by a factor of this amount.</p>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="pdpyras.PDSession.stagger_cooldown">
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">stagger_cooldown</span></span><a class="headerlink" href="#pdpyras.PDSession.stagger_cooldown" title="Permalink to this definition">¶</a></dt>
<dd><p>Randomizing factor for wait times between retries during rate limiting.</p>
<p>If set to number greater than 0, the sleep time for rate limiting will
(for each successive sleep) be adjusted by a factor of one plus a
uniformly-distributed random number between 0 and 1 times this number,
on top of the base sleep timer <a class="reference internal" href="#pdpyras.PDSession.sleep_timer_base" title="pdpyras.PDSession.sleep_timer_base"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sleep_timer_base</span></code></a>.</p>
<p>For example:</p>
<ul class="simple">
<li><p>If this is 1, and <a class="reference internal" href="#pdpyras.PDSession.sleep_timer_base" title="pdpyras.PDSession.sleep_timer_base"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sleep_timer_base</span></code></a> is 2 (default), then after
each status 429 response, the sleep time will change overall by a
random factor between 2 and 4, whereas if it is zero, it will change
by a factor of 2.</p></li>
<li><p>If <a class="reference internal" href="#pdpyras.PDSession.sleep_timer_base" title="pdpyras.PDSession.sleep_timer_base"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sleep_timer_base</span></code></a> is 1, then the cooldown time will be
adjusted by a random factor between one and one plus this number.</p></li>
</ul>
<p>If the number is set to zero, then this behavior is effectively
disabled, and the cooldown factor (by which the sleep time is adjusted)
will just be <a class="reference internal" href="#pdpyras.PDSession.sleep_timer_base" title="pdpyras.PDSession.sleep_timer_base"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sleep_timer_base</span></code></a></p>
<p>Setting this to a nonzero number helps avoid the “thundering herd”
effect that can potentially be caused by many API clients making
simultaneous concurrent API requests and consequently waiting for the
same amount of time before retrying. It is currently zero by default
for consistent behavior with previous versions.</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.PDSession.timeout">
<span class="sig-name descname"><span class="pre">timeout</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">60</span></em><a class="headerlink" href="#pdpyras.PDSession.timeout" title="Permalink to this definition">¶</a></dt>
<dd><p>This is the value sent to <a class="reference external" href="https://docs.python-requests.org/en/master/">Requests</a> as the <code class="docutils literal notranslate"><span class="pre">timeout</span></code> parameter that
determines the TCP read timeout.</p>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="pdpyras.PDSession.trunc_key">
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">trunc_key</span></span><a class="headerlink" href="#pdpyras.PDSession.trunc_key" title="Permalink to this definition">¶</a></dt>
<dd><p>Truncated key for secure display/identification purposes.</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="pdpyras.APISession">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">APISession</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">api_key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default_from</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">auth_type</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'token'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">debug</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession" title="Permalink to this definition">¶</a></dt>
<dd><p>PagerDuty REST API v2 session object class.</p>
<p>Implements the most generic and oft-implemented aspects of PagerDuty’s REST
API v2 as an opinionated wrapper of <a class="reference external" href="https://docs.python-requests.org/en/master/api/#request-sessions">requests.Session</a>.</p>
<p>Inherits from <a class="reference internal" href="#pdpyras.PDSession" title="pdpyras.PDSession"><code class="xref py py-class docutils literal notranslate"><span class="pre">PDSession</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>api_key</strong> – REST API access token to use for HTTP requests</p></li>
<li><p><strong>default_from</strong> (<em>str</em><em> or </em><em>None</em>) – The default email address to use in the <code class="docutils literal notranslate"><span class="pre">From</span></code> header when making
API calls using an account-level API access key.</p></li>
<li><p><strong>auth_type</strong> – The type of credential in use. If authenticating with an OAuth access
token, this must be set to <code class="docutils literal notranslate"><span class="pre">oauth2</span></code> or <code class="docutils literal notranslate"><span class="pre">bearer</span></code>.</p></li>
<li><p><strong>debug</strong> (<em>bool</em>) – Sets <code class="xref py py-attr docutils literal notranslate"><span class="pre">print_debug</span></code>. Set to True to enable verbose command line
output.</p></li>
</ul>
</dd>
<dt class="field-even">Members<span class="colon">:</span></dt>
<dd class="field-even"><p></p></dd>
</dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.APISession.api_call_counts">
<span class="sig-name descname"><span class="pre">api_call_counts</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#pdpyras.APISession.api_call_counts" title="Permalink to this definition">¶</a></dt>
<dd><p>A dict object recording the number of API calls per endpoint</p>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="pdpyras.APISession.api_key_access">
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">api_key_access</span></span><a class="headerlink" href="#pdpyras.APISession.api_key_access" title="Permalink to this definition">¶</a></dt>
<dd><p>Memoized API key access type getter.</p>
<p>Will be “user” if the API key is a user-level token (all users should
have permission to create an API key with the same permissions as they
have in the PagerDuty web UI).</p>
<p>If the API key in use is an account-level API token (as only a global
administrator user can create), this property will be “account”.</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.APISession.api_time">
<span class="sig-name descname"><span class="pre">api_time</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#pdpyras.APISession.api_time" title="Permalink to this definition">¶</a></dt>
<dd><p>A dict object recording the total time of API calls to each endpoint</p>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="pdpyras.APISession.auth_type">
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">auth_type</span></span><a class="headerlink" href="#pdpyras.APISession.auth_type" title="Permalink to this definition">¶</a></dt>
<dd><p>Defines the method of API authentication.</p>
<p>By default this is “token”; if “oauth2”, the API key will be used.</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.APISession.default_from">
<span class="sig-name descname"><span class="pre">default_from</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#pdpyras.APISession.default_from" title="Permalink to this definition">¶</a></dt>
<dd><p>The default value to use as the <code class="docutils literal notranslate"><span class="pre">From</span></code> request header</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.APISession.default_page_size">
<span class="sig-name descname"><span class="pre">default_page_size</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">100</span></em><a class="headerlink" href="#pdpyras.APISession.default_page_size" title="Permalink to this definition">¶</a></dt>
<dd><p>This will be the default number of results requested in each page when
iterating/querying an index (the <code class="docutils literal notranslate"><span class="pre">limit</span></code> parameter).</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.APISession.dict_all">
<span class="sig-name descname"><span class="pre">dict_all</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession.dict_all" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a dictionary of all objects from a given index endpoint.</p>
<p>With the exception of <code class="docutils literal notranslate"><span class="pre">by</span></code>, all keyword arguments passed to this
method are also passed to <a class="reference internal" href="#pdpyras.APISession.iter_all" title="pdpyras.APISession.iter_all"><code class="xref py py-attr docutils literal notranslate"><span class="pre">iter_all</span></code></a>; see the documentation on
that method for further details.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>path</strong> – The index endpoint URL to use.</p></li>
<li><p><strong>by</strong> – The attribute of each object to use for the key values of the
dictionary. This is <code class="docutils literal notranslate"><span class="pre">id</span></code> by default. Please note, there is no
uniqueness validation, so if you use an attribute that is not
distinct for the data set, this function will omit some data in the
results.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.APISession.find">
<span class="sig-name descname"><span class="pre">find</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">query</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">attribute</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'name'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">params</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession.find" title="Permalink to this definition">¶</a></dt>
<dd><p>Finds an object of a given resource type exactly matching a query.</p>
<p>Returns a dict if a result is found. The structure will be that of an
entry in the index endpoint schema’s array of results. Otherwise, it
will return <code class="docutils literal notranslate"><span class="pre">None</span></code> if no result is found or an error is encountered.</p>
<p>Works by querying a given resource index endpoint using the <code class="docutils literal notranslate"><span class="pre">query</span></code>
parameter. To use this function on any given resource, the resource’s
index must support the <code class="docutils literal notranslate"><span class="pre">query</span></code> parameter; otherwise, the function may
not work as expected. If the index ignores the parameter, for instance,
this function will take much longer to return; results will not be
constrained to those matching the query, and so every result in the
index will be downloaded and compared against the query up until a
matching result is found or all results have been checked.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>resource</strong> (<em>str</em>) – The name of the resource endpoint to query, i.e.
<code class="docutils literal notranslate"><span class="pre">escalation_policies</span></code></p></li>
<li><p><strong>query</strong> (<em>str</em>) – The string to query for in the the index.</p></li>
<li><p><strong>attribute</strong> (<em>str</em>) – The property of each result to compare against the query value when
searching for an exact match. By default it is <code class="docutils literal notranslate"><span class="pre">name</span></code>, but when
searching for user by email (for example) it can be set to <code class="docutils literal notranslate"><span class="pre">email</span></code></p></li>
<li><p><strong>params</strong> (<em>dict</em><em> or </em><em>None</em>) – Optional additional parameters to use when querying.</p></li>
</ul>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p>dict</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.APISession.iter_all">
<span class="sig-name descname"><span class="pre">iter_all</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">params</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">page_size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">item_hook</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">total</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession.iter_all" title="Permalink to this definition">¶</a></dt>
<dd><p>Iterator for the contents of an index endpoint or query.</p>
<p>Automatically paginates and yields the results in each page, until all
matching results have been yielded or a HTTP error response is received.</p>
<p>If the URL to use supports cursor-based pagintation, then this will
return <a class="reference internal" href="#pdpyras.APISession.iter_cursor" title="pdpyras.APISession.iter_cursor"><code class="xref py py-attr docutils literal notranslate"><span class="pre">iter_cursor</span></code></a> with the same keyword arguments. Otherwise,
it implements classic pagination, a.k.a. numeric pagination.</p>
<p>Each yielded value is a dict object representing a result returned from
the index. For example, if requesting the <code class="docutils literal notranslate"><span class="pre">/users</span></code> endpoint, each
yielded value will be an entry of the <code class="docutils literal notranslate"><span class="pre">users</span></code> array property in the
response.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>url</strong> (<em>str</em>) – The index endpoint URL to use.</p></li>
<li><p><strong>params</strong> (<em>dict</em><em> or </em><em>None</em>) – Additional URL parameters to include.</p></li>
<li><p><strong>page_size</strong> (<em>int</em><em> or </em><em>None</em>) – If set, the <code class="docutils literal notranslate"><span class="pre">page_size</span></code> argument will override the
<code class="docutils literal notranslate"><span class="pre">default_page_size</span></code> parameter on the session and set the <code class="docutils literal notranslate"><span class="pre">limit</span></code>
parameter to a custom value (default is 100), altering the number of
pagination results. The actual number of results in the response
will still take precedence, if it differs; this parameter and
<code class="docutils literal notranslate"><span class="pre">default_page_size</span></code> only dictate what is requested of the API.</p></li>
<li><p><strong>item_hook</strong> – Callable object that will be invoked for each iteration, i.e. for
printing progress. It will be called with three parameters: a dict
representing a given result in the iteration, an int representing
the number of the item in the series, and an int (or str, as of
v5.0.0) representing the total number of items in the series. If the
total isn’t knowable, the value passed is “?”.</p></li>
<li><p><strong>total</strong> (<em>bool</em>) – If True, the <code class="docutils literal notranslate"><span class="pre">total</span></code> parameter will be included in API calls, and
the value for the third parameter to the item hook will be the total
count of records that match the query. Leaving this as False confers
a small performance advantage, as the API in this case does not have
to compute the total count of results in the query.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.APISession.iter_cursor">
<span class="sig-name descname"><span class="pre">iter_cursor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">params</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">item_hook</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession.iter_cursor" title="Permalink to this definition">¶</a></dt>
<dd><p>Iterator for results from an endpoint using cursor-based pagination.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>url</strong> – The index endpoint URL to use.</p></li>
<li><p><strong>params</strong> – Query parameters to include in the request.</p></li>
<li><p><strong>item_hook</strong> – A callable object that accepts 3 positional arguments; see</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.APISession.jget">
<span class="sig-name descname"><span class="pre">jget</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession.jget" title="Permalink to this definition">¶</a></dt>
<dd><p>Performs a GET request, returning the JSON-decoded body as a dictionary</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.APISession.jpost">
<span class="sig-name descname"><span class="pre">jpost</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession.jpost" title="Permalink to this definition">¶</a></dt>
<dd><p>Performs a POST request, returning the JSON-decoded body as a dictionary</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.APISession.jput">
<span class="sig-name descname"><span class="pre">jput</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession.jput" title="Permalink to this definition">¶</a></dt>
<dd><p>Performs a PUT request, returning the JSON-decoded body as a dictionary</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.APISession.list_all">
<span class="sig-name descname"><span class="pre">list_all</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession.list_all" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of all objects from a given index endpoint.</p>
<p>All keyword arguments passed to this function are also passed directly
to <a class="reference internal" href="#pdpyras.APISession.iter_all" title="pdpyras.APISession.iter_all"><code class="xref py py-attr docutils literal notranslate"><span class="pre">iter_all</span></code></a>; see the documentation on that method for details.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>url</strong> – The index endpoint URL to use.</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.APISession.persist">
<span class="sig-name descname"><span class="pre">persist</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">attr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">values</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">update</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession.persist" title="Permalink to this definition">¶</a></dt>
<dd><p>Finds or creates and returns a resource with a matching attribute</p>
<p>Given a resource name, an attribute to use as an idempotency key and a
set of attribute:value pairs as a dict, create a resource with the
specified attributes if it doesn’t exist already and return the resource
persisted via the API (whether or not it already existed).</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>resource</strong> (<em>str</em>) – The URL to use when creating the new resource or searching for an
existing one. The underlying AP must support entity wrapping to use
this method with it.</p></li>
<li><p><strong>attr</strong> (<em>str</em>) – Name of the attribute to use as the idempotency key. For instance,
“email” when the resource is “users” will not create the user if a
user with the email address given in <code class="docutils literal notranslate"><span class="pre">values</span></code> already exists.</p></li>
<li><p><strong>values</strong> (<em>dict</em>) – The content of the resource to be created, if it does not already
exist. This must contain an item with a key that is the same as the
<code class="docutils literal notranslate"><span class="pre">attr</span></code> argument.</p></li>
<li><p><strong>update</strong> (<em>bool</em>) – (New in 4.4.0) If set to True, any existing resource will be updated
with the values supplied.</p></li>
</ul>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p>dict</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.APISession.postprocess">
<span class="sig-name descname"><span class="pre">postprocess</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">response</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Response</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">suffix</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession.postprocess" title="Permalink to this definition">¶</a></dt>
<dd><p>Records performance information / request metadata about the API call.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>response</strong> (<a class="reference external" href="https://docs.python-requests.org/en/master/api/#requests.Response">requests.Response</a>) – The <a class="reference external" href="https://docs.python-requests.org/en/master/api/#requests.Response">requests.Response</a> object returned by the request method</p></li>
<li><p><strong>suffix</strong> (<em>str</em><em> or </em><em>None</em>) – Optional suffix to append to the key</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.APISession.rdelete">
<span class="sig-name descname"><span class="pre">rdelete</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession.rdelete" title="Permalink to this definition">¶</a></dt>
<dd><p>Delete a resource.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>resource</strong> (<em>str</em><em> or </em><em>dict</em>) – The path/URL to which to send the request, or a dict object
representing an API resource that contains an item with key <code class="docutils literal notranslate"><span class="pre">self</span></code>
whose value is the URL of the resource.</p></li>
<li><p><strong>**kw</strong> – Keyword arguments to pass to <code class="docutils literal notranslate"><span class="pre">requests.Session.delete</span></code></p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.APISession.rget">
<span class="sig-name descname"><span class="pre">rget</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession.rget" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapped-entity-aware GET function.</p>
<p>Retrieves a resource via GET and returns the wrapped entity in the
response.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>resource</strong> (<em>str</em><em> or </em><em>dict</em>) – The path/URL to which to send the request, or a dict object
representing an API resource that contains an item with key <code class="docutils literal notranslate"><span class="pre">self</span></code>
whose value is the URL of the resource.</p></li>
<li><p><strong>**kw</strong> – Keyword arguments to pass to <code class="docutils literal notranslate"><span class="pre">requests.Session.get</span></code></p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Dictionary representation of the object.</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>dict</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.APISession.rpost">
<span class="sig-name descname"><span class="pre">rpost</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession.rpost" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapped-entity-aware POST function.</p>
<p>Creates a resource and returns the created entity if successful.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>path</strong> (<em>str</em>) – The path/URL to which to send the POST request, which should be an
index endpoint.</p></li>
<li><p><strong>**kw</strong> – Keyword arguments to pass to <code class="docutils literal notranslate"><span class="pre">requests.Session.post</span></code></p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Dictionary representation of the created object</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>dict</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.APISession.rput">
<span class="sig-name descname"><span class="pre">rput</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.APISession.rput" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapped-entity-aware PUT function.</p>
<p>Update an individual resource, returning the wrapped entity.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>resource</strong> – The path/URL to which to send the request, or a dict object
representing an API resource that contains an item with key <code class="docutils literal notranslate"><span class="pre">self</span></code>
whose value is the URL of the resource.</p></li>
<li><p><strong>**kw</strong> – Keyword arguments to pass to <code class="docutils literal notranslate"><span class="pre">requests.Session.put</span></code></p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>Dictionary representation of the updated object</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>dict</p>
</dd>
</dl>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="pdpyras.APISession.subdomain">
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">subdomain</span></span><a class="headerlink" href="#pdpyras.APISession.subdomain" title="Permalink to this definition">¶</a></dt>
<dd><p>Subdomain of the PagerDuty account of the API access token.</p>
<dl class="field-list simple">
<dt class="field-odd">Type<span class="colon">:</span></dt>
<dd class="field-odd"><p>str or None</p>
</dd>
</dl>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="pdpyras.APISession.total_call_count">
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">total_call_count</span></span><a class="headerlink" href="#pdpyras.APISession.total_call_count" title="Permalink to this definition">¶</a></dt>
<dd><p>The total number of API calls made by this instance.</p>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="pdpyras.APISession.total_call_time">
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">total_call_time</span></span><a class="headerlink" href="#pdpyras.APISession.total_call_time" title="Permalink to this definition">¶</a></dt>
<dd><p>The total time spent making API calls.</p>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="pdpyras.APISession.trunc_token">
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">trunc_token</span></span><a class="headerlink" href="#pdpyras.APISession.trunc_token" title="Permalink to this definition">¶</a></dt>
<dd><p>Truncated token for secure display/identification purposes.</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.APISession.url">
<span class="sig-name descname"><span class="pre">url</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">'https://api.pagerduty.com'</span></em><a class="headerlink" href="#pdpyras.APISession.url" title="Permalink to this definition">¶</a></dt>
<dd><p>Base URL of the REST API</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="pdpyras.EventsAPISession">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">EventsAPISession</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">api_key</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">debug</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.EventsAPISession" title="Permalink to this definition">¶</a></dt>
<dd><p>Session class for submitting events to the PagerDuty v2 Events API.</p>
<p>Implements methods for submitting events to PagerDuty through the Events API
and inherits from <a class="reference internal" href="#pdpyras.PDSession" title="pdpyras.PDSession"><code class="xref py py-class docutils literal notranslate"><span class="pre">pdpyras.PDSession</span></code></a>. For more details on usage of
this API, refer to the <a class="reference external" href="https://developer.pagerduty.com/docs/events-api-v2/overview/">Events API v2 documentation</a></p>
<p>Inherits from <a class="reference internal" href="#pdpyras.PDSession" title="pdpyras.PDSession"><code class="xref py py-class docutils literal notranslate"><span class="pre">PDSession</span></code></a>.</p>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.EventsAPISession.acknowledge">
<span class="sig-name descname"><span class="pre">acknowledge</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dedup_key</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.EventsAPISession.acknowledge" title="Permalink to this definition">¶</a></dt>
<dd><p>Acknowledge an alert via Events API.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>dedup_key</strong> – The deduplication key of the alert to set to the acknowledged state.</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.EventsAPISession.post">
<span class="sig-name descname"><span class="pre">post</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kw</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.EventsAPISession.post" title="Permalink to this definition">¶</a></dt>
<dd><p>Override of <code class="docutils literal notranslate"><span class="pre">requests.Session.post</span></code></p>
<p>Adds the <code class="docutils literal notranslate"><span class="pre">routing_key</span></code> parameter to the body before sending.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.EventsAPISession.prepare_headers">
<span class="sig-name descname"><span class="pre">prepare_headers</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">method</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">user_headers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">{}</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.EventsAPISession.prepare_headers" title="Permalink to this definition">¶</a></dt>
<dd><p>Add user agent and content type headers for Events API requests.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>user_headers</strong> – User-supplied headers that will override defaults</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.EventsAPISession.resolve">
<span class="sig-name descname"><span class="pre">resolve</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dedup_key</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.EventsAPISession.resolve" title="Permalink to this definition">¶</a></dt>
<dd><p>Resolve an alert via Events API.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>dedup_key</strong> – The deduplication key of the alert to resolve.</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.EventsAPISession.send_event">
<span class="sig-name descname"><span class="pre">send_event</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">action</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dedup_key</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">properties</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.EventsAPISession.send_event" title="Permalink to this definition">¶</a></dt>
<dd><p>Send an event to the v2 Events API.</p>
<p>See: <a class="reference external" href="https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2">https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2</a></p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>action</strong> (<em>str</em>) – The action to perform through the Events API: trigger, acknowledge
or resolve.</p></li>
<li><p><strong>dedup_key</strong> (<em>str</em>) – The deduplication key; used for determining event uniqueness and
associating actions with existing incidents.</p></li>
<li><p><strong>**properties</strong> – Additional properties to set, i.e. if <code class="docutils literal notranslate"><span class="pre">action</span></code> is <code class="docutils literal notranslate"><span class="pre">trigger</span></code>
this would include <code class="docutils literal notranslate"><span class="pre">payload</span></code></p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>The deduplication key of the incident, if any.</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.EventsAPISession.trigger">
<span class="sig-name descname"><span class="pre">trigger</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">summary</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dedup_key</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">severity</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'critical'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">payload</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">custom_details</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">images</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">links</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.EventsAPISession.trigger" title="Permalink to this definition">¶</a></dt>
<dd><p>Trigger an incident</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>summary</strong> (<em>str</em>) – Summary / brief description of what is wrong.</p></li>
<li><p><strong>source</strong> (<em>str</em>) – A human-readable name identifying the system that is affected.</p></li>
<li><p><strong>dedup_key</strong> (<em>str</em>) – The deduplication key; used for determining event uniqueness and
associating actions with existing incidents.</p></li>
<li><p><strong>severity</strong> (<em>str</em>) – Alert severity. Sets the <code class="docutils literal notranslate"><span class="pre">payload.severity</span></code> property.</p></li>
<li><p><strong>payload</strong> (<em>dict</em>) – Set the payload directly. Can be used in conjunction with other
parameters that also set payload properties; these properties will
be merged into the default payload, and any properties in this
parameter will take precedence except with regard to
<code class="docutils literal notranslate"><span class="pre">custom_details</span></code>.</p></li>
<li><p><strong>custom_details</strong> (<em>dict</em>) – The <code class="docutils literal notranslate"><span class="pre">payload.custom_details</span></code> property of the payload. Will
override the property set in the <code class="docutils literal notranslate"><span class="pre">payload</span></code> parameter if given.</p></li>
<li><p><strong>images</strong> (<em>list</em>) – Set the <code class="docutils literal notranslate"><span class="pre">images</span></code> property of the event.</p></li>
<li><p><strong>links</strong> (<em>list</em>) – Set the <code class="docutils literal notranslate"><span class="pre">links</span></code> property of the event.</p></li>
</ul>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p>str</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="pdpyras.ChangeEventsAPISession">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">ChangeEventsAPISession</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">api_key</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">debug</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.ChangeEventsAPISession" title="Permalink to this definition">¶</a></dt>
<dd><p>Session class for submitting change events to the PagerDuty v2 Change Events API.</p>
<p>Implements methods for submitting change events to PagerDuty’s change events
API. See the <a class="reference external" href="https://developer.pagerduty.com/docs/events-api-v2/send-change-events/">Change Events API documentation</a>
for more details.</p>
<p>Inherits from <a class="reference internal" href="#pdpyras.PDSession" title="pdpyras.PDSession"><code class="xref py py-class docutils literal notranslate"><span class="pre">PDSession</span></code></a>.</p>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.ChangeEventsAPISession.prepare_headers">
<span class="sig-name descname"><span class="pre">prepare_headers</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">method</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">user_headers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">{}</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.ChangeEventsAPISession.prepare_headers" title="Permalink to this definition">¶</a></dt>
<dd><p>Add user agent and content type headers for Change Events API requests.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.ChangeEventsAPISession.send_change_event">
<span class="sig-name descname"><span class="pre">send_change_event</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">properties</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.ChangeEventsAPISession.send_change_event" title="Permalink to this definition">¶</a></dt>
<dd><p>Send a change event to the v2 Change Events API.</p>
<p>See: <a class="reference external" href="https://developer.pagerduty.com/docs/events-api-v2/send-change-events/">https://developer.pagerduty.com/docs/events-api-v2/send-change-events/</a></p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>**properties</strong> – Properties to set, i.e. <code class="docutils literal notranslate"><span class="pre">payload</span></code> and <code class="docutils literal notranslate"><span class="pre">links</span></code></p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>The response ID</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="pdpyras.ChangeEventsAPISession.submit">
<span class="sig-name descname"><span class="pre">submit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">summary</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">source</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">custom_details</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">links</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timestamp</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.ChangeEventsAPISession.submit" title="Permalink to this definition">¶</a></dt>
<dd><p>Submit an incident change</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>summary</strong> (<em>str</em>) – Summary / brief description of the change.</p></li>
<li><p><strong>source</strong> (<em>str</em>) – A human-readable name identifying the source of the change.</p></li>
<li><p><strong>custom_details</strong> (<em>dict</em>) – The <code class="docutils literal notranslate"><span class="pre">payload.custom_details</span></code> property of the payload.</p></li>
<li><p><strong>links</strong> (<em>list</em>) – Set the <code class="docutils literal notranslate"><span class="pre">links</span></code> property of the event.</p></li>
<li><p><strong>timestamp</strong> (<em>str</em>) – Specifies an event timestamp. Must be an ISO8601-format date/time.</p></li>
</ul>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p>str</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
</section>
<section id="errors">
<h2>Errors<a class="headerlink" href="#errors" title="Permalink to this heading">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="pdpyras.PDClientError">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">PDClientError</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">message</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">response</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.PDClientError" title="Permalink to this definition">¶</a></dt>
<dd><p>General API errors base class.</p>
<p>Note, the name of this class does not imply it solely includes errors
experienced by the client or HTTP status 4xx responses, but descendants can
include issues with the API backend.</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="pdpyras.PDClientError.response">
<span class="sig-name descname"><span class="pre">response</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#pdpyras.PDClientError.response" title="Permalink to this definition">¶</a></dt>
<dd><p>The HTTP response object, if a response was successfully received.</p>
<p>In the case of network errors, this property will be None.</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="pdpyras.PDHTTPError">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">PDHTTPError</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">message</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">response</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Response</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.PDHTTPError" title="Permalink to this definition">¶</a></dt>
<dd><p>Error class representing errors strictly associated with HTTP responses.</p>
<p>This class was created to make it easier to more cleanly handle errors by
way of a class that is guaranteed to have its <code class="docutils literal notranslate"><span class="pre">response</span></code> be a valid
<a class="reference external" href="https://docs.python-requests.org/en/master/api/#requests.Response">requests.Response</a> object.</p>
<p>Whereas, the more generic <a class="reference internal" href="#pdpyras.PDClientError" title="pdpyras.PDClientError"><code class="xref py py-class docutils literal notranslate"><span class="pre">PDClientError</span></code></a> could also be used
to denote such things as non-transient network errors wherein no response
was recevied from the API.</p>
<p>For instance, instead of this:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="p">:</span>
<span class="n">user</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="n">rget</span><span class="p">(</span><span class="s1">'/users/PABC123'</span><span class="p">)</span>
<span class="k">except</span> <span class="n">pdpyras</span><span class="o">.</span><span class="n">PDClientError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">response</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"HTTP error: "</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">e</span>
</pre></div>
</div>
<p>one could write this:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="p">:</span>
<span class="n">user</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="n">rget</span><span class="p">(</span><span class="s1">'/users/PABC123'</span><span class="p">)</span>
<span class="k">except</span> <span class="n">pdpyras</span><span class="o">.</span><span class="n">PDHTTPError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"HTTP error: "</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span><span class="p">))</span>
</pre></div>
</div>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="pdpyras.PDServerError">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">PDServerError</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">message</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">response</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Response</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.PDServerError" title="Permalink to this definition">¶</a></dt>
<dd><p>Error class representing failed expectations made of the server</p>
<p>This is raised in cases where the response schema differs from the expected
schema because of an API bug, or because it’s an early access endpoint and
changes before GA, or in cases of HTTP status 5xx where a successful
response is required.</p>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="pdpyras.URLError">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">URLError</span></span><a class="headerlink" href="#pdpyras.URLError" title="Permalink to this definition">¶</a></dt>
<dd><p>Exception class for unsupported URLs or malformed input.</p>
</dd></dl>
</section>
<section id="client-defaults">
<h2>Client Defaults<a class="headerlink" href="#client-defaults" title="Permalink to this heading">¶</a></h2>
<p>These are properties of the module that configure default behavior for the API
client. There should be no need for the end user to modify them.</p>
<span class="target" id="module-pdpyras"></span><dl class="py data">
<dt class="sig sig-object py" id="pdpyras.CANONICAL_PATHS">
<span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">CANONICAL_PATHS</span></span><a class="headerlink" href="#pdpyras.CANONICAL_PATHS" title="Permalink to this definition">¶</a></dt>
<dd><p>Explicit list of supported canonical REST API v2 paths</p>
<dl class="field-list simple">
</dl>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="pdpyras.CURSOR_BASED_PAGINATION_PATHS">
<span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">CURSOR_BASED_PAGINATION_PATHS</span></span><a class="headerlink" href="#pdpyras.CURSOR_BASED_PAGINATION_PATHS" title="Permalink to this definition">¶</a></dt>
<dd><p>Explicit list of paths that support cursor-based pagination</p>
<dl class="field-list simple">
</dl>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="pdpyras.ENTITY_WRAPPER_CONFIG">
<span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">ENTITY_WRAPPER_CONFIG</span></span><a class="headerlink" href="#pdpyras.ENTITY_WRAPPER_CONFIG" title="Permalink to this definition">¶</a></dt>
<dd><p>Wrapped entities antipattern handling configuration.</p>
<p>When trying to determine the entity wrapper name, this dictionary is first
checked for keys that apply to a given request method and canonical API path
based on a matching logic. If no keys are found that match, it is assumed that
the API endpoint follows classic entity wrapping conventions, and the wrapper
name can be inferred based on those conventions (see
<a class="reference internal" href="#pdpyras.infer_entity_wrapper" title="pdpyras.infer_entity_wrapper"><code class="xref py py-attr docutils literal notranslate"><span class="pre">infer_entity_wrapper</span></code></a>). Any new API that does not follow these
conventions should therefore be given an entry in this dictionary in order to
properly support it for entity wrapping.</p>
<p>Each of the keys should be a capitalized HTTP method (or <code class="docutils literal notranslate"><span class="pre">*</span></code> to match any
method), followed by a space, followed by a canonical path i.e. as returned by
<a class="reference internal" href="#pdpyras.canonical_path" title="pdpyras.canonical_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">canonical_path</span></code></a> and included in <a class="reference internal" href="#pdpyras.CANONICAL_PATHS" title="pdpyras.CANONICAL_PATHS"><code class="xref py py-attr docutils literal notranslate"><span class="pre">CANONICAL_PATHS</span></code></a>. Each value
is either a tuple with request and response body wrappers (if they differ), a
string (if they are the same for both cases) or <code class="docutils literal notranslate"><span class="pre">None</span></code> (if wrapping is
disabled and the data is to be marshaled or unmarshaled as-is). Values in tuples
can also be None to denote that either the request or response is unwrapped.</p>
<p>An endpoint, under the design logic of this client, is said to have entity
wrapping if the body (request or response) has only one property containing
the content requested or transmitted, apart from properties used for
pagination. If there are any secondary content-bearing properties (other than
those used for pagination), entity wrapping should be disabled to avoid
discarding those properties from responses or preventing the use of those
properties in request bodies.</p>
<dl class="field-list simple">
</dl>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="pdpyras.ITERATION_LIMIT">
<span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">ITERATION_LIMIT</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">10000.0</span></em><a class="headerlink" href="#pdpyras.ITERATION_LIMIT" title="Permalink to this definition">¶</a></dt>
<dd><p>The maximum position of a result in classic pagination.</p>
<p>The offset plus limit parameter may not exceed this number. This is enforced
server-side and is not something the client may override. Rather, this value is
used to short-circuit pagination in order to avoid a HTTP 400 error.</p>
<p>See: <a class="reference external" href="https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTU4-pagination">Pagination</a>.</p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="pdpyras.TEXT_LEN_LIMIT">
<span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">TEXT_LEN_LIMIT</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">100</span></em><a class="headerlink" href="#pdpyras.TEXT_LEN_LIMIT" title="Permalink to this definition">¶</a></dt>
<dd><p>The longest permissible length of API content to include in error messages.</p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="pdpyras.TIMEOUT">
<span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">TIMEOUT</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">60</span></em><a class="headerlink" href="#pdpyras.TIMEOUT" title="Permalink to this definition">¶</a></dt>
<dd><p>The default timeout in seconds for any given HTTP request.</p>
<p>Modifying this value will not affect any preexisting API session instances.
Rather, it will only affect new instances. It is recommended to use
<a class="reference internal" href="#pdpyras.PDSession.timeout" title="pdpyras.PDSession.timeout"><code class="xref py py-attr docutils literal notranslate"><span class="pre">PDSession.timeout</span></code></a> to configure the timeout for a given session.</p>
</dd></dl>
</section>
<section id="functions">
<h2>Functions<a class="headerlink" href="#functions" title="Permalink to this heading">¶</a></h2>
<p>These are generic functions used by the API session classes and are not on
their own typically needed, but which are documented for the benefit of anyone
who may find use in them.</p>
<section id="url-handling">
<h3>URL Handling<a class="headerlink" href="#url-handling" title="Permalink to this heading">¶</a></h3>
<p>URL related functions.</p>
<span class="target" id="module-0"></span><dl class="py function">
<dt class="sig sig-object py" id="pdpyras.canonical_path">
<span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">canonical_path</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">base_url</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">url</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.canonical_path" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the canonical REST API path corresponding to a URL.</p>
<p>This is used to identify and classify URLs according to which particular API
within REST API v2 it belongs to.</p>
<p>Explicitly supported canonical paths are defined in the list
<a class="reference internal" href="#pdpyras.CANONICAL_PATHS" title="pdpyras.CANONICAL_PATHS"><code class="xref py py-attr docutils literal notranslate"><span class="pre">CANONICAL_PATHS</span></code></a> and are the path part of any given API’s URL. The
path for a given API is what is shown at the top of its reference page, i.e.
<code class="docutils literal notranslate"><span class="pre">/users/{id}/contact_methods</span></code> for retrieving a user’s contact methods
(GET) or creating a new one (POST).</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>base_url</strong> – The base URL of the API</p></li>
<li><p><strong>url</strong> – A non-normalized URL (a path or full URL)</p></li>
</ul>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p>str</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="pdpyras.endpoint_matches">
<span class="sig-prename descclassname"><span class="pre">pdpyras.</span></span><span class="sig-name descname"><span class="pre">endpoint_matches</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">endpoint_pattern</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">method</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">path</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pdpyras.endpoint_matches" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns true if a method and path match an endpoint pattern.</p>
<p>This is the filtering logic used for finding the appropriate entry in
<a class="reference internal" href="#pdpyras.ENTITY_WRAPPER_CONFIG" title="pdpyras.ENTITY_WRAPPER_CONFIG"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ENTITY_WRAPPER_CONFIG</span></code></a> to use for a given method and API path.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>endpoint_pattern</strong> – The endpoint pattern in the form <code class="docutils literal notranslate"><span class="pre">METHOD</span> <span class="pre">PATH</span></code> where <code class="docutils literal notranslate"><span class="pre">METHOD</span></code> is the
HTTP method in uppercase or <code class="docutils literal notranslate"><span class="pre">*</span></code> to match all methods, and <code class="docutils literal notranslate"><span class="pre">PATH</span></code> is
a canonical API path.</p></li>
<li><p><strong>method</strong> – The HTTP method.</p></li>
<li><p><strong>path</strong> – The canonical API path (i.e. as returned by <a class="reference internal" href="#pdpyras.canonical_path" title="pdpyras.canonical_path"><code class="xref py py-func docutils literal notranslate"><span class="pre">canonical_path()</span></code></a>)</p></li>