Skip to content

Commit 201fd79

Browse files
docs(boxsdkgen): Add migration guides (box/box-codegen#866) (#1128)
1 parent d94bb2a commit 201fd79

File tree

7 files changed

+1036
-766
lines changed

7 files changed

+1036
-766
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "fa0419f", "specHash": "fa34496", "version": "0.1.0" }
1+
{ "engineHash": "4a6585f", "specHash": "fa34496", "version": "0.1.0" }

migration-guides/from-box-python-sdk-gen-v1-to-box-python-sdk-v10.md

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Migration guide from v1 version of the `box-python-sdk-gen` to the `box-python-sdk`
2+
3+
Note: This guide applies only to migrations targeting Box Python SDK v4.X.Y or v10.X.Y.
4+
It does not apply to other major versions (e.g., v5.X, v11.X).
5+
6+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
7+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
8+
9+
- [Introduction](#introduction)
10+
- [Installation](#installation)
11+
- [How to migrate](#how-to-migrate)
12+
- [Usage](#usage)
13+
- [Using the Box Python SDK v10](#using-the-box-python-sdk-v10)
14+
- [Using the Box Python SDK v4](#using-the-box-python-sdk-v4)
15+
16+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
17+
18+
## Introduction
19+
20+
From the `box-python-sdk-gen` you can migrate either to v4 or v10 of the Box Python SDK.
21+
Your choice should depend on whether you want to continue using the manually maintained SDK (Box Python SDK v3) alongside the generated one or not.
22+
23+
The v4 version of the Box Python SDK consolidates both the legacy SDK package `boxsdk` and the generated one `box_sdk_gen`.
24+
25+
- If previously you were using both artifacts `boxsdk` v3 and `box-sdk-gen` v1, migrate to v4 version of the Box Python SDK which consolidates `boxsdk` and `box_sdk_gen` packages.
26+
- If you were only using the generated artifact `box-sdk-gen`, migrate to v10 version of the Box Python SDK which contains only the generated `box_sdk_gen` package.
27+
28+
| Scenario | Your current usage | Recommended target | Packages included in target | Why this choice | Notes |
29+
| -------------------------------------------- | -------------------------------------------------- | ------------------ | --------------------------------------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ |
30+
| Using both manual and generated SDK together | `boxsdk` v3 + `box-sdk-gen` v1 in the same project | v4.X.Y | `boxsdk` (manual) + `box_sdk_gen` (generated) | Keep existing v3 code while adopting new features from the generated SDK | Run both modules side-by-side; use type aliases to avoid name conflicts if necessary |
31+
| Using only the generated SDK | `box-sdk-gen` v1 only | v10.X.Y | `box_sdk_gen` (generated) only | Clean upgrade path with no legacy module; simpler dependency surface | Best when you don’t need the manual `boxsdk` package |
32+
33+
## Installation
34+
35+
In order to start using v4 or v10 version of the Box Python SDK, you need to change the dependency in your project.
36+
The artifact name has changed from `box-sdk-gen` to `boxsdk`.
37+
You also need to set the version to `4` if you are migrating to v4 or `10` if you are migrating to v10.
38+
You can find the latest version of each major version on [PyPI](https://pypi.org/project/boxsdk/).
39+
40+
### How to migrate
41+
42+
To start using v4 or v10 version of Box Python SDK in your project, replace the dependency in your `requirements.txt`
43+
or installation command.
44+
45+
**Old (`box-python-sdk-gen-v1`)**
46+
47+
```console
48+
pip install box-sdk-gen
49+
```
50+
51+
**New (`box-python-sdk-v10`)**
52+
53+
```console
54+
pip install boxsdk>=10
55+
```
56+
57+
**New (`box-python-sdk-v4`)**
58+
59+
```console
60+
pip install boxsdk~=4.0
61+
```
62+
63+
## Usage
64+
65+
### Using the Box Python SDK v10
66+
67+
After migration from `box-sdk-gen` to the `boxsdk` v10, you can still use the `box_sdk_gen` package in the same way as before.
68+
To access the client for interacting with the Box API, simply import `BoxClient` and any other necessary classes from the `box_sdk_gen` package.
69+
70+
```python
71+
from box_sdk_gen import BoxClient, BoxDeveloperTokenAuth
72+
73+
auth: BoxDeveloperTokenAuth = BoxDeveloperTokenAuth(
74+
token="INSERT YOUR DEVELOPER TOKEN HERE"
75+
)
76+
client: BoxClient = BoxClient(auth=auth)
77+
for item in client.folders.get_folder_items("0").entries:
78+
print(item.name)
79+
```
80+
81+
### Using the Box Python SDK v4
82+
83+
After migration to Box Python SDK v4, you can use both the manual Box Python SDK package `boxsdk` and the generated one `box_sdk_gen`.
84+
You just need to import the required classes from the appropriate package depending on which SDK you intend to use.
85+
If both packages contain classes with the same name, you can use type aliases to resolve any naming conflicts.
86+
87+
```python
88+
from boxsdk import JWTAuth, Client
89+
from boxsdk.object.folder import Folder as FolderOld
90+
from box_sdk_gen import BoxJWTAuth, JWTConfig, BoxClient, Folder
91+
92+
93+
def main():
94+
auth = JWTAuth.from_settings_file("/path/to/settings.json")
95+
legacy_client = Client(auth)
96+
97+
jwt_config = JWTConfig.from_config_file(config_file_path="/path/to/settings.json")
98+
auth = BoxJWTAuth(config=jwt_config)
99+
new_client = BoxClient(auth=auth)
100+
101+
folder: FolderOld = legacy_client.folder(folder_id="0").create_subfolder(
102+
"My Subfolder"
103+
)
104+
updated_folder: Folder = new_client.folders.update_folder(
105+
folder_id=folder.id, name="My Updated Subfolder"
106+
)
107+
print(
108+
f"Created folder with ID {folder.id} has been updated to {updated_folder.name}"
109+
)
110+
111+
112+
if __name__ == "__main__":
113+
main()
114+
```

0 commit comments

Comments
 (0)