Skip to content

release: 4.2.0 #2555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 452 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
452 commits
Select commit Hold shift + click to select a range
6cd0b18
codegen metadata
stainless-app[bot] Apr 2, 2025
6bc4a3a
codegen metadata
stainless-app[bot] Apr 3, 2025
317d54d
codegen metadata
stainless-app[bot] Apr 3, 2025
5e1ca2b
codegen metadata
stainless-app[bot] Apr 3, 2025
453311c
codegen metadata
stainless-app[bot] Apr 3, 2025
a7f3836
codegen metadata
stainless-app[bot] Apr 3, 2025
d31cd55
codegen metadata
stainless-app[bot] Apr 3, 2025
6c974e8
codegen metadata
stainless-app[bot] Apr 3, 2025
9d80288
codegen metadata
stainless-app[bot] Apr 3, 2025
9dd6028
chore(internal): remove trailing character (#2596)
stainless-app[bot] Apr 3, 2025
1360a4e
codegen metadata
stainless-app[bot] Apr 3, 2025
eb04fc5
codegen metadata
stainless-app[bot] Apr 3, 2025
f20e40f
feat(api): api update (#2597)
stainless-app[bot] Apr 3, 2025
346f94a
codegen metadata
stainless-app[bot] Apr 3, 2025
814addf
codegen metadata
stainless-app[bot] Apr 3, 2025
db709ec
codegen metadata
stainless-app[bot] Apr 3, 2025
7100114
codegen metadata
stainless-app[bot] Apr 3, 2025
d93a481
codegen metadata
stainless-app[bot] Apr 3, 2025
428c317
codegen metadata
stainless-app[bot] Apr 3, 2025
495821f
codegen metadata
stainless-app[bot] Apr 3, 2025
b3c74e9
codegen metadata
stainless-app[bot] Apr 3, 2025
d610102
feat(api): api update (#2598)
stainless-app[bot] Apr 3, 2025
5809e0e
codegen metadata
stainless-app[bot] Apr 4, 2025
22b50cd
chore(internal): update response_info (#2599)
stainless-app[bot] Apr 4, 2025
38a74ad
feat(workflows): add events (#2600)
stainless-app[bot] Apr 4, 2025
cf6326e
codegen metadata
stainless-app[bot] Apr 4, 2025
b9aec4a
codegen metadata
stainless-app[bot] Apr 4, 2025
56948f0
chore(internal): force response_info model generation (#2601)
stainless-app[bot] Apr 4, 2025
35a10c5
codegen metadata
stainless-app[bot] Apr 4, 2025
f3b620b
codegen metadata
stainless-app[bot] Apr 4, 2025
8288ab5
codegen metadata
stainless-app[bot] Apr 4, 2025
0e423c6
feat(api): api update (#2602)
stainless-app[bot] Apr 4, 2025
61b7eee
feat(api): api update (#2603)
stainless-app[bot] Apr 4, 2025
e466ede
codegen metadata
stainless-app[bot] Apr 4, 2025
e8b5121
codegen metadata
stainless-app[bot] Apr 4, 2025
586ccb8
codegen metadata
stainless-app[bot] Apr 4, 2025
ccc4ff5
codegen metadata
stainless-app[bot] Apr 4, 2025
715716e
codegen metadata
stainless-app[bot] Apr 4, 2025
b499be8
codegen metadata
stainless-app[bot] Apr 4, 2025
ea12531
codegen metadata
stainless-app[bot] Apr 4, 2025
9cbf953
codegen metadata
stainless-app[bot] Apr 4, 2025
eadd868
feat(api): api update (#2604)
stainless-app[bot] Apr 4, 2025
23beb0a
codegen metadata
stainless-app[bot] Apr 4, 2025
69126d2
codegen metadata
stainless-app[bot] Apr 4, 2025
8d08f3e
fix(client): support serialising multipart entries as json
RobertCraigie Apr 4, 2025
19fad53
codegen metadata
stainless-app[bot] Apr 4, 2025
1ec78c3
feat(api): api update (#2605)
stainless-app[bot] Apr 4, 2025
0cf96cc
codegen metadata
stainless-app[bot] Apr 4, 2025
df02f0a
codegen metadata
stainless-app[bot] Apr 4, 2025
07eed76
codegen metadata
stainless-app[bot] Apr 4, 2025
f64b014
feat(api): api update (#2608)
stainless-app[bot] Apr 4, 2025
88a0e75
docs: swap examples used in readme (#2609)
stainless-app[bot] Apr 4, 2025
850aa28
chore(internal): codegen related update (#2610)
stainless-app[bot] Apr 4, 2025
1eeb74d
codegen metadata
stainless-app[bot] Apr 4, 2025
f69a156
codegen metadata
stainless-app[bot] Apr 5, 2025
6d00004
codegen metadata
stainless-app[bot] Apr 5, 2025
825c90f
codegen metadata
stainless-app[bot] Apr 6, 2025
856c676
codegen metadata
stainless-app[bot] Apr 6, 2025
c377177
codegen metadata
stainless-app[bot] Apr 6, 2025
5251e7d
codegen metadata
stainless-app[bot] Apr 6, 2025
effce67
codegen metadata
stainless-app[bot] Apr 6, 2025
b026dd6
codegen metadata
stainless-app[bot] Apr 7, 2025
20516ec
codegen metadata
stainless-app[bot] Apr 7, 2025
b6eb839
codegen metadata
stainless-app[bot] Apr 7, 2025
2afa2d3
feat(api): api update (#2611)
stainless-app[bot] Apr 7, 2025
2424b0d
feat(api): api update (#2612)
stainless-app[bot] Apr 7, 2025
4a22456
codegen metadata
stainless-app[bot] Apr 7, 2025
6a71e41
feat(api): api update (#2613)
stainless-app[bot] Apr 7, 2025
f17dbe4
codegen metadata
stainless-app[bot] Apr 7, 2025
7a6e890
fix(client): send all configured auth headers (#2614)
stainless-app[bot] Apr 7, 2025
7c78d90
feat(api): api update (#2615)
stainless-app[bot] Apr 7, 2025
28e0c77
feat(api): api update (#2616)
stainless-app[bot] Apr 7, 2025
0c8b0c3
codegen metadata
stainless-app[bot] Apr 7, 2025
a1231d1
codegen metadata
stainless-app[bot] Apr 7, 2025
8390456
codegen metadata
stainless-app[bot] Apr 7, 2025
1f32ecd
feat(api): api update
stainless-app[bot] Apr 7, 2025
5f8d57e
chore(internal): only run examples workflow in main repo (#2617)
stainless-app[bot] Apr 9, 2025
a697679
feat(api): api update (#2618)
stainless-app[bot] Apr 7, 2025
8cac041
feat(api): Add workers telemetry routes (#2619)
stainless-app[bot] Apr 7, 2025
689d871
feat(api): api update (#2620)
stainless-app[bot] Apr 7, 2025
8f7d997
feat(api): api update
stainless-app[bot] Apr 7, 2025
3dac189
feat(api): api update
stainless-app[bot] Apr 7, 2025
c1bcdc4
feat(api): api update (#2621)
stainless-app[bot] Apr 7, 2025
1913a92
feat(api): api update
stainless-app[bot] Apr 7, 2025
ac90c58
feat(api): api update
stainless-app[bot] Apr 7, 2025
734d348
feat(api): api update
stainless-app[bot] Apr 7, 2025
421b7b7
feat(api): api update
stainless-app[bot] Apr 7, 2025
c736922
feat(api): api update
stainless-app[bot] Apr 7, 2025
80744d8
feat(api): api update
stainless-app[bot] Apr 7, 2025
12d29f1
feat(api): api update
stainless-app[bot] Apr 7, 2025
0c2494a
feat(api): api update (#2622)
stainless-app[bot] Apr 7, 2025
cf1c2c6
feat(api): api update
stainless-app[bot] Apr 7, 2025
41f7540
feat(api): api update (#2623)
stainless-app[bot] Apr 7, 2025
d5f09fe
feat(devices): add registrations support (#2624)
stainless-app[bot] Apr 8, 2025
41c78d1
feat(secret_store): add support (#2625)
stainless-app[bot] Apr 8, 2025
67ff68f
feat(secrets_store): remove incorrect bulk edit endpoint (#2626)
stainless-app[bot] Apr 8, 2025
885de82
feat(docs): add secrets store to navigation
stainless-app[bot] Apr 8, 2025
d7fcece
feat(api): api update
stainless-app[bot] Apr 8, 2025
a808a96
feat(api): manual updates
stainless-app[bot] Apr 8, 2025
85e3f9d
feat(api): manual updates (#2627)
stainless-app[bot] Apr 8, 2025
4713a3f
feat(api): manual updates
stainless-app[bot] Apr 8, 2025
aca7ce9
feat(api): manual updates (#2628)
stainless-app[bot] Apr 8, 2025
4ecbc97
feat(api): manual updates
stainless-app[bot] Apr 8, 2025
9114751
feat(api): manual updates
stainless-app[bot] Apr 8, 2025
553bbf1
feat(api): manual updates
stainless-app[bot] Apr 8, 2025
7c66e21
feat(api): api update
stainless-app[bot] Apr 8, 2025
b3e54f7
feat(api): api update (#2629)
stainless-app[bot] Apr 8, 2025
f2c6867
feat(api): api update
stainless-app[bot] Apr 8, 2025
6590e50
chore(internal): codegen related update (#2630)
stainless-app[bot] Apr 8, 2025
0d149f0
feat(api): api update
stainless-app[bot] Apr 8, 2025
c0f9513
chore(internal): slight transform perf improvement (#2631)
stainless-app[bot] Apr 8, 2025
86396aa
feat(api): api update
stainless-app[bot] Apr 8, 2025
522175c
feat(api): api update
stainless-app[bot] Apr 8, 2025
fd5011f
feat(api): api update
stainless-app[bot] Apr 8, 2025
44d9b44
chore(tests): improve enum examples (#2632)
stainless-app[bot] Apr 8, 2025
f11ee75
feat(api): api update
stainless-app[bot] Apr 8, 2025
0e9fcd1
feat(api): api update
stainless-app[bot] Apr 8, 2025
92b95fd
feat(api): api update
stainless-app[bot] Apr 8, 2025
c3bc0db
feat(api): api update
stainless-app[bot] Apr 8, 2025
11cba1e
feat(api): api update
stainless-app[bot] Apr 8, 2025
8756cce
feat(api): api update
stainless-app[bot] Apr 8, 2025
41ddaf9
feat(api): api update (#2633)
stainless-app[bot] Apr 8, 2025
c723180
feat(api): api update
stainless-app[bot] Apr 8, 2025
41e03bc
feat(api): api update (#2634)
stainless-app[bot] Apr 8, 2025
618e905
feat(api): api update
stainless-app[bot] Apr 8, 2025
5271c53
feat(api): api update
stainless-app[bot] Apr 8, 2025
7fc5804
feat(api): api update (#2635)
stainless-app[bot] Apr 8, 2025
c19449e
feat(api): api update (#2636)
stainless-app[bot] Apr 8, 2025
a171eca
feat(api): api update
stainless-app[bot] Apr 8, 2025
fef07c2
feat(api): api update
stainless-app[bot] Apr 8, 2025
f171c1a
feat(api): api update (#2637)
stainless-app[bot] Apr 8, 2025
c1f2df6
feat(api): api update
stainless-app[bot] Apr 8, 2025
c33ea2e
feat(api): api update
stainless-app[bot] Apr 8, 2025
81fe226
feat(api): api update
stainless-app[bot] Apr 8, 2025
5c0c4f7
feat(api): api update (#2638)
stainless-app[bot] Apr 8, 2025
8c7bfe9
feat(api): api update
stainless-app[bot] Apr 8, 2025
ff03c5b
feat(api): api update
stainless-app[bot] Apr 8, 2025
1a848ad
feat(api): Update workers telemetry route methods (#2639)
stainless-app[bot] Apr 8, 2025
2ecb76c
chore: slight wording improvement in README (#2640)
stainless-app[bot] Apr 8, 2025
e3581f4
feat(api): api update
stainless-app[bot] Apr 8, 2025
9e04549
feat(api): api update
stainless-app[bot] Apr 8, 2025
2442ef4
feat(api): api update
stainless-app[bot] Apr 8, 2025
b0d60ec
feat(pipelines): add support (#2641)
stainless-app[bot] Apr 8, 2025
6d1caaa
feat(api): api update
stainless-app[bot] Apr 9, 2025
d661a85
feat(api): api update
stainless-app[bot] Apr 9, 2025
6ded951
feat(api): api update
stainless-app[bot] Apr 9, 2025
0648395
chore: configure new SDK language
stainless-app[bot] Apr 9, 2025
16d6638
feat(api): api update
stainless-app[bot] Apr 9, 2025
19242ad
feat(api): api update
stainless-app[bot] Apr 9, 2025
c02dec9
feat(api): api update
stainless-app[bot] Apr 9, 2025
e91354b
feat(api): api update
stainless-app[bot] Apr 9, 2025
866a694
feat(api): api update (#2642)
stainless-app[bot] Apr 9, 2025
b407dee
feat(api): api update
stainless-app[bot] Apr 9, 2025
cae95fc
feat(api): api update (#2643)
stainless-app[bot] Apr 9, 2025
2731e5a
feat(api): api update (#2644)
stainless-app[bot] Apr 9, 2025
c0f0403
feat(api): api update
stainless-app[bot] Apr 9, 2025
1278a59
feat(api): api update
stainless-app[bot] Apr 9, 2025
24fcaa9
feat(api): api update (#2645)
stainless-app[bot] Apr 9, 2025
c7c9bdf
feat(api): api update (#2646)
stainless-app[bot] Apr 9, 2025
bd58af6
feat(api): api update
stainless-app[bot] Apr 9, 2025
73a9508
feat(api): api update
stainless-app[bot] Apr 9, 2025
49e9a1a
feat(api): api update
stainless-app[bot] Apr 9, 2025
96c7239
feat(api): api update
stainless-app[bot] Apr 9, 2025
22cd00d
feat(api): api update
stainless-app[bot] Apr 9, 2025
8f1dc2f
feat(api): api update
stainless-app[bot] Apr 9, 2025
a1c546f
chore(internal): expand CI branch coverage (#2647)
stainless-app[bot] Apr 9, 2025
c43fb40
feat(api): api update (#2648)
stainless-app[bot] Apr 9, 2025
0a9a84c
feat(api): api update
stainless-app[bot] Apr 9, 2025
5c88239
feat(api): api update
stainless-app[bot] Apr 9, 2025
c922be4
feat(api): api update
stainless-app[bot] Apr 9, 2025
6aaabc5
feat(api): api update
stainless-app[bot] Apr 9, 2025
64d826b
feat(api): api update
stainless-app[bot] Apr 9, 2025
cd9cb6a
feat(api): api update
stainless-app[bot] Apr 9, 2025
77f2bd3
feat(api): patch and put endpoints for d1 database
stainless-app[bot] Apr 9, 2025
19203d0
chore(internal): reduce CI branch coverage
stainless-app[bot] Apr 9, 2025
98f235a
feat(api): api update
stainless-app[bot] Apr 9, 2025
5fc996c
feat(pipelines): add terraform resource
stainless-app[bot] Apr 9, 2025
f2f7291
chore(pipelines): move pipeline nav hierarchy
stainless-app[bot] Apr 9, 2025
14e7dbc
feat(api): api update
stainless-app[bot] Apr 9, 2025
84e9f49
chore: revert auth handling (#2650)
jacobbednarz Apr 10, 2025
2e73038
feat(api): api update
stainless-app[bot] Apr 10, 2025
c979950
feat(api): api update
stainless-app[bot] Apr 10, 2025
9c120cb
feat(api): api update
stainless-app[bot] Apr 10, 2025
d252dd8
feat(api): api update
stainless-app[bot] Apr 10, 2025
3888d80
feat(api): api update
stainless-app[bot] Apr 10, 2025
3f8891a
feat(api): api update
stainless-app[bot] Apr 10, 2025
8ae828e
feat(api): api update
stainless-app[bot] Apr 10, 2025
7247ced
feat(api): api update
stainless-app[bot] Apr 10, 2025
8722b88
feat(api): api update
stainless-app[bot] Apr 10, 2025
4df3a4f
feat(api): api update
stainless-app[bot] Apr 10, 2025
4bc277e
feat(api): api update
stainless-app[bot] Apr 10, 2025
6210e57
feat(api): api update
stainless-app[bot] Apr 10, 2025
57b7463
feat(api): api update
stainless-app[bot] Apr 10, 2025
3848bd7
feat(api): api update
stainless-app[bot] Apr 10, 2025
d85a07a
feat(api): api update
stainless-app[bot] Apr 10, 2025
ce34afd
feat(api): api update
stainless-app[bot] Apr 10, 2025
953fb8d
feat(api): api update
stainless-app[bot] Apr 10, 2025
cbda17d
feat(api): api update
stainless-app[bot] Apr 10, 2025
57c7202
feat(api): api update
stainless-app[bot] Apr 10, 2025
eba5c50
feat(api): api update
stainless-app[bot] Apr 10, 2025
8f3663b
feat(api): api update
stainless-app[bot] Apr 10, 2025
23c6841
feat(api): api update
stainless-app[bot] Apr 10, 2025
f61be23
chore(internal): update shared response info for optional fields
stainless-app[bot] Apr 10, 2025
a0198a6
feat(devices): add next generation under devices
stainless-app[bot] Apr 11, 2025
7058191
test(api): skip failing tests for python
stainless-app[bot] Apr 11, 2025
b7ea434
feat: support API versioning (#2651)
jacobbednarz Apr 11, 2025
42f691a
feat(api): api update
stainless-app[bot] Apr 11, 2025
0dad5f4
feat(api): api update
stainless-app[bot] Apr 11, 2025
4438262
feat(api): api update
stainless-app[bot] Apr 11, 2025
eca3148
feat(api): api update
stainless-app[bot] Apr 11, 2025
c17b312
feat(api): api update
stainless-app[bot] Apr 11, 2025
49e2d4a
feat(api): api update
stainless-app[bot] Apr 11, 2025
23b082f
feat(api): api update
stainless-app[bot] Apr 11, 2025
78745d0
fix(perf): skip traversing types for NotGiven values
stainless-app[bot] Apr 11, 2025
e16ac57
fix(perf): optimize some hot paths
stainless-app[bot] Apr 11, 2025
273677b
feat(api): api update
stainless-app[bot] Apr 11, 2025
373f016
feat(api): api update
stainless-app[bot] Apr 11, 2025
61193fb
feat(api): api update
stainless-app[bot] Apr 11, 2025
9ad780b
feat(api): api update
stainless-app[bot] Apr 11, 2025
aa6c424
feat(api): api update
stainless-app[bot] Apr 11, 2025
f1a1c62
feat(api): api update
stainless-app[bot] Apr 11, 2025
f67e265
feat(api): api update
stainless-app[bot] Apr 11, 2025
dce5a72
feat(api): api update
stainless-app[bot] Apr 11, 2025
1e30e99
feat(api): api update
stainless-app[bot] Apr 11, 2025
bdeeabd
feat(api): api update
stainless-app[bot] Apr 11, 2025
251b1c5
feat(api): api update
stainless-app[bot] Apr 11, 2025
be8901a
feat(api): api update
stainless-app[bot] Apr 11, 2025
572cea5
feat(api): api update
stainless-app[bot] Apr 12, 2025
3431847
feat(api): api update
stainless-app[bot] Apr 14, 2025
6f299c2
feat(api): api update
stainless-app[bot] Apr 14, 2025
4c44ffa
chore(internal): update pyright settings
stainless-app[bot] Apr 14, 2025
3a22603
feat(api): api update
stainless-app[bot] Apr 14, 2025
bd9ff3f
feat(api): api update
stainless-app[bot] Apr 14, 2025
0c7fc17
chore(client): minor internal fixes
stainless-app[bot] Apr 14, 2025
44f4acd
feat(api): api update
stainless-app[bot] Apr 14, 2025
d0e0993
feat(api): api update
stainless-app[bot] Apr 14, 2025
f1908a6
feat(api): api update
stainless-app[bot] Apr 14, 2025
45dfe02
feat(api): api update
stainless-app[bot] Apr 14, 2025
b09c932
feat(api): api update
stainless-app[bot] Apr 14, 2025
4411185
feat(api): api update
stainless-app[bot] Apr 14, 2025
30711dc
feat(api): api update
stainless-app[bot] Apr 14, 2025
aed9105
feat(api): api update
stainless-app[bot] Apr 14, 2025
eb6fae8
feat(api): api update
stainless-app[bot] Apr 14, 2025
e16267a
feat(api): api update
stainless-app[bot] Apr 14, 2025
38264b9
feat(api): api update
stainless-app[bot] Apr 14, 2025
a89f918
feat(api): api update
stainless-app[bot] Apr 14, 2025
613b066
feat(api): api update
stainless-app[bot] Apr 14, 2025
c865424
feat(api): api update
stainless-app[bot] Apr 14, 2025
0993c37
feat(api): api update
stainless-app[bot] Apr 14, 2025
689a5d5
release: 4.2.0
stainless-app[bot] Apr 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
name: lint
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v4

Expand All @@ -40,7 +39,6 @@ jobs:
name: test
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- uses: actions/checkout@v4

Expand All @@ -61,6 +59,7 @@ jobs:
examples:
name: examples
runs-on: ubuntu-latest
if: github.repository == 'cloudflare/cloudflare-python'
timeout-minutes: 5

steps:
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "4.1.0"
".": "4.2.0"
}
6 changes: 4 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
configured_endpoints: 1655
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-0ed9f898b31619623e50d660d04beca50e44987bfd3eb3a6ff98d3bca2a9c569.yml
configured_endpoints: 1711
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-2445b18a5453d17bb106dd9e3d672bf2400bc2c67e921797ac410661a13ffef4.yml
openapi_spec_hash: 1282c2a366839e635aab91b1ec2a3cb3
config_hash: ea8f45dbac8e2ed462221c2e2781e7ed
223 changes: 223 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,16 @@ from cloudflare import Cloudflare

client = Cloudflare()

account = client.accounts.create(
name="name",
type="standard",
unit={"id": "f267e341f3dd4697bd3b9f71dd96247f"},
zone = client.zones.create(
account={"id": "023e105f4ecef8ad9ca31a8372d0c353"},
name="example.com",
)
print(account.unit)
print(zone.account)
```

## File uploads

Request parameters that correspond to file uploads can be passed as `bytes`, a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
Request parameters that correspond to file uploads can be passed as `bytes`, or a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.

```python
from pathlib import Path
Expand Down
352 changes: 321 additions & 31 deletions api.md

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "cloudflare"
version = "4.1.0"
version = "4.2.0"
description = "The official Python library for the cloudflare API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down Expand Up @@ -147,11 +147,10 @@ exclude = [
]

reportImplicitOverride = true
reportOverlappingOverload = false

reportImportCycles = false
reportPrivateUsage = false
reportOverlappingOverload = false


[tool.ruff]
line-length = 120
Expand Down
63 changes: 60 additions & 3 deletions src/cloudflare/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@
PostParser,
RequestFiles,
HttpxSendArgs,
HttpxFileTypes,
RequestOptions,
MultipartSyntax,
HttpxRequestFiles,
ModelBuilderProtocol,
)
from ._utils import is_dict, is_list, asyncify, is_given, lru_cache, is_mapping
from ._utils import is_dict, is_list, asyncify, is_given, is_tuple, lru_cache, is_mapping, is_mapping_t, is_sequence_t
from ._compat import PYDANTIC_V2, model_copy, model_dump
from ._models import GenericModel, FinalRequestOptions, validate_type, construct_type
from ._response import (
Expand Down Expand Up @@ -331,6 +333,7 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
_client: _HttpxClientT
_version: str
_base_url: URL
_api_version: str
max_retries: int
timeout: Union[float, Timeout, None]
_strict_response_validation: bool
Expand All @@ -342,6 +345,7 @@ def __init__(
*,
version: str,
base_url: str | URL,
api_version: str,
_strict_response_validation: bool,
max_retries: int = DEFAULT_MAX_RETRIES,
timeout: float | Timeout | None = DEFAULT_TIMEOUT,
Expand All @@ -350,6 +354,7 @@ def __init__(
) -> None:
self._version = version
self._base_url = self._enforce_trailing_slash(URL(base_url))
self.api_version = api_version
self.max_retries = max_retries
self.timeout = timeout
self._custom_headers = custom_headers or {}
Expand Down Expand Up @@ -409,7 +414,8 @@ def _build_headers(self, options: FinalRequestOptions, *, retries_taken: int = 0

idempotency_header = self._idempotency_header
if idempotency_header and options.method.lower() != "get" and idempotency_header not in headers:
headers[idempotency_header] = options.idempotency_key or self._idempotency_key()
options.idempotency_key = options.idempotency_key or self._idempotency_key()
headers[idempotency_header] = options.idempotency_key

# Don't set these headers if they were already set or removed by the caller. We check
# `custom_headers`, which can contain `Omit()`, instead of `headers` to account for the removal case.
Expand All @@ -423,6 +429,8 @@ def _build_headers(self, options: FinalRequestOptions, *, retries_taken: int = 0
if timeout is not None:
headers["x-stainless-read-timeout"] = str(timeout)

headers["api-version"] = self.api_version

return headers

def _prepare_url(self, url: str) -> URL:
Expand Down Expand Up @@ -484,7 +492,24 @@ def _build_request(
raise TypeError(
f"Expected query input to be a dictionary for multipart requests but got {type(json_data)} instead."
)
kwargs["data"] = self._serialize_multipartform(json_data)

if options.multipart_syntax == 'json':
json_data = cast("Mapping[str, object]", json_data)
if is_mapping_t(files):
files = {
**files,
**self._serialize_multiapartform_json(json_data),
}
elif is_sequence_t(files):
files = [
*files,
*self._serialize_multiapartform_json(json_data).items(),
]
else:
assert not files, "this case should only be hit when there are no files"
files = self._serialize_multiapartform_json(json_data)
else:
kwargs["data"] = self._serialize_multipartform(json_data)

# httpx determines whether or not to send a "multipart/form-data"
# request based on the truthiness of the "files" argument.
Expand Down Expand Up @@ -516,6 +541,22 @@ def _build_request(
**kwargs,
)

def _serialize_multiapartform_json(self, data: Mapping[str, object]) -> dict[str, HttpxFileTypes]:
serialized: dict[str, HttpxFileTypes] = {}
for key, value in data.items():
if isinstance(value, Mapping) or is_list(value) or is_tuple(value):
serialized[key] = (None, json.dumps(value).encode("utf-8"), "application/json")
else:
serialized[key] = (
None,
self.qs._primitive_value_to_str(
value # type: ignore
).encode("utf-8"),
"text/plain",
)

return serialized

def _serialize_multipartform(self, data: Mapping[object, object]) -> dict[str, object]:
items = self.qs.stringify_items(
# TODO: type ignore is required as stringify_items is well typed but we can't be
Expand Down Expand Up @@ -785,6 +826,7 @@ def __init__(
*,
version: str,
base_url: str | URL,
api_version: str,
max_retries: int = DEFAULT_MAX_RETRIES,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
http_client: httpx.Client | None = None,
Expand Down Expand Up @@ -815,6 +857,7 @@ def __init__(
# cast to a valid type because mypy doesn't understand our type narrowing
timeout=cast(Timeout, timeout),
base_url=base_url,
api_version=api_version,
max_retries=max_retries,
custom_query=custom_query,
custom_headers=custom_headers,
Expand Down Expand Up @@ -943,6 +986,10 @@ def _request(
request = self._build_request(options, retries_taken=retries_taken)
self._prepare_request(request)

if options.idempotency_key:
# ensure the idempotency key is reused between requests
input_options.idempotency_key = options.idempotency_key

kwargs: HttpxSendArgs = {}
if self.custom_auth is not None:
kwargs["auth"] = self.custom_auth
Expand Down Expand Up @@ -1315,6 +1362,7 @@ def __init__(
*,
version: str,
base_url: str | URL,
api_version: str,
_strict_response_validation: bool,
max_retries: int = DEFAULT_MAX_RETRIES,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -1343,6 +1391,7 @@ def __init__(
super().__init__(
version=version,
base_url=base_url,
api_version=api_version,
# cast to a valid type because mypy doesn't understand our type narrowing
timeout=cast(Timeout, timeout),
max_retries=max_retries,
Expand Down Expand Up @@ -1475,6 +1524,10 @@ async def _request(
request = self._build_request(options, retries_taken=retries_taken)
await self._prepare_request(request)

if options.idempotency_key:
# ensure the idempotency key is reused between requests
input_options.idempotency_key = options.idempotency_key

kwargs: HttpxSendArgs = {}
if self.custom_auth is not None:
kwargs["auth"] = self.custom_auth
Expand Down Expand Up @@ -1794,6 +1847,7 @@ def make_request_options(
idempotency_key: str | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
post_parser: PostParser | NotGiven = NOT_GIVEN,
multipart_syntax: MultipartSyntax | None = None,
) -> RequestOptions:
"""Create a dict of type RequestOptions without keys of NotGiven values."""
options: RequestOptions = {}
Expand All @@ -1819,6 +1873,9 @@ def make_request_options(
# internal
options["post_parser"] = post_parser # type: ignore

if multipart_syntax is not None:
options["multipart_syntax"] = multipart_syntax

return options


Expand Down
Loading
Loading