Box Python SDK¶
Installing¶
pip install boxsdk
Source Code¶
Quickstart¶
Create a developer token from your app’s configuration page (https://app.box.com/developers/services).
You’ll be prompted for it on the command line.
$ from boxsdk import DevelopmentClient
$ client = DevelopmentClient()
>>> Enter developer token: <enter your developer token>
$ me = client.user().get()
GET https://api.box.com/2.0/users/me {'headers': {u'Authorization': u'Bearer ----KkeV',
u'User-Agent': u'box-python-sdk-1.4.3'},
'params': None}
{"type":"user","id":"----6009","name":"Jeffrey Meadows","login":"jmeadows@box.com",...}
$ me.name
>>> Jeffrey Meadows
The DevelopmentClient
uses Box developer tokens for auth (and will prompt you for a new token upon
expiration), and logs API requests and responses, making it really easy to get started learning the SDK and Box API.
Creating an App for Users¶
Authorization¶
If you’d like other users to use your app, you need to set up a way for them to authorize your app and
grant it access to their Box account. The auth
module contains several classes to help you do that.
The simplest class is the OAuth2
class. To use it, instantiate it with your client_id
and client_secret
.
Follow the tutorial on GitHub for
instructions on how to get an authorized client for a user. Using the store_tokens
callback, you may persist
the user’s auth and refresh tokens for the next time they use your app. Once they return to your app, you can
create an authorized client like so:
from boxsdk import OAuth2, Client
oauth = OAuth2(
client_id='YOUR_CLIENT_ID',
client_secret='YOUR_CLIENT_SECRET',
store_tokens=your_store_tokens_callback_method,
access_token=persisted_access_token,
refresh_token=persisted_refresh_token,
)
client = Client(oauth)
Making requests to Box¶
Once you have an authorized client, you can use it to make requests to Box on your user’s behalf. The client has several methods to help you get started, many of which return Box objects, which, in turn, have methods that correspond to Box API endpoints.
The module documentation below describes each of these methods and which parameters they require. Some API endpoints
do not have corresponding SDK methods; for those, you can use the generic make_request
method of the client.
Module Documentation¶
- boxsdk package
- Subpackages
- boxsdk.auth package
- boxsdk.client package
- boxsdk.network package
- boxsdk.object package
- Submodules
- boxsdk.object.api_json_object module
- boxsdk.object.base_api_json_object module
- boxsdk.object.base_endpoint module
- boxsdk.object.base_object module
- boxsdk.object.cloneable module
- boxsdk.object.collaboration module
- boxsdk.object.collaboration_whitelist module
- boxsdk.object.collaboration_whitelist_entry module
- boxsdk.object.collaboration_whitelist_exempt_target module
- boxsdk.object.collection module
- boxsdk.object.comment module
- boxsdk.object.device_pinner module
- boxsdk.object.email_alias module
- boxsdk.object.enterprise module
- boxsdk.object.event module
- boxsdk.object.events module
- boxsdk.object.file module
- boxsdk.object.file_version module
- boxsdk.object.file_version_retention module
- boxsdk.object.folder module
- boxsdk.object.group module
- boxsdk.object.group_membership module
- boxsdk.object.invite module
- boxsdk.object.item module
- boxsdk.object.legal_hold module
- boxsdk.object.legal_hold_policy module
- boxsdk.object.legal_hold_policy_assignment module
- boxsdk.object.metadata module
- boxsdk.object.metadata_cascade_policy module
- boxsdk.object.metadata_template module
- boxsdk.object.recent_item module
- boxsdk.object.retention_policy module
- boxsdk.object.retention_policy_assignment module
- boxsdk.object.search module
- boxsdk.object.storage_policy module
- boxsdk.object.storage_policy_assignment module
- boxsdk.object.task module
- boxsdk.object.task_assignment module
- boxsdk.object.terms_of_service module
- boxsdk.object.terms_of_service_user_status module
- boxsdk.object.trash module
- boxsdk.object.upload_session module
- boxsdk.object.user module
- boxsdk.object.watermark module
- boxsdk.object.web_link module
- boxsdk.object.webhook module
- Module contents
- boxsdk.pagination package
- Submodules
- boxsdk.pagination.box_object_collection module
- boxsdk.pagination.dict_page module
- boxsdk.pagination.limit_offset_based_dict_collection module
- boxsdk.pagination.limit_offset_based_object_collection module
- boxsdk.pagination.marker_based_dict_collection module
- boxsdk.pagination.marker_based_object_collection module
- boxsdk.pagination.page module
- Module contents
- boxsdk.session package
- boxsdk.util package
- Submodules
- boxsdk.util.api_call_decorator module
- boxsdk.util.chain_map module
- boxsdk.util.compat module
- boxsdk.util.enum module
- boxsdk.util.json module
- boxsdk.util.log module
- boxsdk.util.lru_cache module
- boxsdk.util.multipart_stream module
- boxsdk.util.shared_link module
- boxsdk.util.text_enum module
- boxsdk.util.translator module
- Module contents
- Submodules
- boxsdk.config module
- boxsdk.exception module
- boxsdk.version module
- Module contents
- Subpackages