boxsdk


Nameboxsdk JSON
Version 3.9.2 PyPI version JSON
download
home_pagehttps://github.com/box/box-python-sdk
SummaryOfficial Box Python SDK
upload_time2023-10-18 15:30:35
maintainer
docs_urlhttps://pythonhosted.org/boxsdk/
authorBox
requires_python
licenseApache Software License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0
keywords box oauth2 sdk
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <img src="https://github.com/box/sdks/blob/master/images/box-dev-logo.png" alt= “box-dev-logo” width="30%" height="50%">
</p>

# Box Python SDK

[![image](http://opensource.box.com/badges/active.svg)](http://opensource.box.com/badges)
[![Documentation Status](https://readthedocs.org/projects/box-python-sdk/badge/?version=latest)](http://box-python-sdk.readthedocs.org/en/latest)
[![image](https://github.com/box/box-python-sdk/workflows/build/badge.svg)](https://github.com/box/box-python-sdk/actions)
[![image](https://img.shields.io/pypi/v/boxsdk.svg)](https://pypi.python.org/pypi/boxsdk)
[![image](https://img.shields.io/pypi/dm/boxsdk.svg)](https://pypi.python.org/pypi/boxsdk)
[![image](https://coveralls.io/repos/github/box/box-python-sdk/badge.svg?branch=main)](https://coveralls.io/github/box/box-python-sdk?branch=main)

Getting Started Docs: <https://developer.box.com/guides/tooling/sdks/python/>

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Installing](#installing)
- [Getting Started](#getting-started)
- [Authorization](#authorization)
  - [Server-to-Server Auth with JWT](#server-to-server-auth-with-jwt)
  - [Traditional 3-legged OAuth2](#traditional-3-legged-oauth2)
  - [Other Auth Options](#other-auth-options)
- [Usage Documentation](#usage-documentation)
  - [Making API Calls Manually](#making-api-calls-manually)
- [Other Client Options](#other-client-options)
  - [Logging Client](#logging-client)
  - [Developer Token Client](#developer-token-client)
  - [Development Client](#development-client)
- [Customization](#customization)
  - [Custom Subclasses](#custom-subclasses)
- [FIPS 140-2 Compliance](#fips-140-2-compliance)
- [Versions](#versions)
  - [Supported Version](#supported-version)
  - [Version schedule](#version-schedule)
- [Contributing](#contributing)
  - [Developer Setup](#developer-setup)
  - [Testing](#testing)
- [Questions, Bugs, and Feature Requests?](#questions-bugs-and-feature-requests)
- [Copyright and License](#copyright-and-license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# Installing

``` console
pip install boxsdk
```

The current version of the SDK is v3.x --- With this release support for
Python 3.5 and earlier (including 2.x) has been dropped. if you're
looking for the code or documentation for v1.5.x, please see the [1.5
branch](https://github.com/box/box-python-sdk/tree/1.5).

# Getting Started

To get started with the SDK, get a Developer Token from the
Configuration page of your app in the [Box Developer
Console](https://app.box.com/developers/console). You can use this token
to make test calls for your own Box account.

The SDK provides an interactive `DevelopmentClient` that makes it easy
to test out the SDK in a REPL. This client will automatically prompt for
a new Developer Token when it requires one, and will log HTTP requests
and responses to aid in debugging and understanding how the SDK makes
API calls.

``` pycon
>>> from boxsdk import DevelopmentClient
>>> client = DevelopmentClient()
Enter developer token: <ENTER DEVELOPER TOKEN HERE>
>>> user = client.user().get()
GET https://api.box.com/2.0/users/me {'headers': {'Authorization': '---wXyZ',
            'User-Agent': 'box-python-sdk-2.0.0',
            'X-Box-UA': 'agent=box-python-sdk/2.0.0; env=python/3.6.5'},
'params': None}
"GET https://api.box.com/2.0/users/me" 200 454
{'Date': 'Thu, 01 Nov 2018 23:32:11 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Strict-Transport-Security': 'max-age=31536000', 'Cache-Control': 'no-cache, no-store', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'BOX-REQUEST-ID': '0b50luc09ahp56m2jmkla8mgmh2', 'Age': '0'}
{'address': '',
'avatar_url': 'https://cloud.app.box.com/api/avatar/large/123456789',
'created_at': '2012-06-07T11:14:50-07:00',
'id': '123456789',
'job_title': '',
'language': 'en',
'login': 'user@example.com',
'max_upload_size': 16106127360,
'modified_at': '2018-10-30T17:01:27-07:00',
'name': 'Example User',
'phone': '',
'space_amount': 1000000000000000.0,
'space_used': 14330018065,
'status': 'active',
'timezone': 'America/Los_Angeles',
'type': 'user'}

>>> print(f'The current user ID is {user.id}')
The current user ID is 123456789
```

Outside of a REPL, you can initialize a new `Client` with just the
Developer Token to get started.

``` python
from boxsdk import OAuth2, Client

auth = OAuth2(
    client_id='YOUR_CLIENT_ID',
    client_secret='YOUR_CLIENT_SECRET',
    access_token='YOUR_DEVELOPER_TOKEN',
)
client = Client(auth)

user = client.user().get()
print(f'The current user ID is {user.id}')
```

# Authorization

The Box API uses OAuth2 for auth. The SDK makes it relatively painless
to work with OAuth2 tokens.

## Server-to-Server Auth with JWT

The Python SDK supports your [JWT
Authentication](https://developer.box.com/en/guides/authentication/jwt/)
applications.

Authenticating with a JWT requires some extra dependencies. To get them,
simply

``` console
pip install "boxsdk[jwt]"
```

Instead of instantiating your `Client` with an instance of `OAuth2`,
instead use an instance of `JWTAuth`.

``` python
from boxsdk import JWTAuth
from boxsdk import Client

auth = JWTAuth(
    client_id='YOUR_CLIENT_ID',
    client_secret='YOUR_CLIENT_SECRET',
    enterprise_id='YOUR_ENTERPRISE_ID',
    jwt_key_id='YOUR_JWT_KEY_ID',
    rsa_private_key_file_sys_path='CERT.PEM',
    rsa_private_key_passphrase='PASSPHRASE',
)

access_token = auth.authenticate_instance()
client = Client(auth)
```

This client is able to create application users:

``` python
ned_stark_user = client.create_user('Ned Stark')
```

These users can then be authenticated:

``` python
ned_auth = JWTAuth(
    client_id='YOUR_CLIENT_ID',
    client_secret='YOUR_CLIENT_SECRET',
    user=ned_stark_user,
    jwt_key_id='YOUR_JWT_KEY_ID',
    rsa_private_key_file_sys_path='CERT.PEM',
    rsa_private_key_passphrase='PASSPHRASE'
)
ned_auth.authenticate_user()
ned_client = Client(ned_auth)
```

Requests made with `ned_client` (or objects returned from
`ned_client`'s methods) will be performed on behalf of the newly
created app user.

## Traditional 3-legged OAuth2

### Get the Authorization URL

``` python
from boxsdk import OAuth2

oauth = OAuth2(
    client_id='YOUR_CLIENT_ID',
    client_secret='YOUR_CLIENT_SECRET',
    store_tokens=your_store_tokens_callback_method,
)

auth_url, csrf_token = oauth.get_authorization_url('http://YOUR_REDIRECT_URL')
```

store_tokens is a callback used to store the access token and refresh
token. You might want to define something like this:

``` python
def store_tokens(access_token, refresh_token):
    # store the tokens at secure storage (e.g. Keychain)
```

The SDK will keep the tokens in memory for the duration of the Python
script run, so you don't always need to pass store_tokens.

### Authenticate (Get Access/Refresh Tokens)

If you navigate the user to the auth_url, the user will eventually get
redirected to <http://YOUR_REDIRECT_URL?code=YOUR_AUTH_CODE>. After
getting the code, you will be able to use the code to exchange for an
access token and refresh token.

The SDK handles all the work for you; all you need to do is run:

``` python
# Make sure that the csrf token you get from the `state` parameter
# in the final redirect URI is the same token you get from the
# get_authorization_url method.
assert 'THE_CSRF_TOKEN_YOU_GOT' == csrf_token
access_token, refresh_token = oauth.authenticate('YOUR_AUTH_CODE')
```

### Create an Authenticated Client

``` python
from boxsdk import Client

client = Client(oauth)
```

And that's it! You can start using the client to do all kinds of cool
stuff and the SDK will handle the token refresh for you automatically.

### Instantiate a Client Given an Access and a Refresh Token

Alternatively, you can instantiate an OAuth2 object with the access
token and refresh token. Once you have an oauth object you can pass that
into the Client object to instantiate a client and begin making calls.

``` python
from boxsdk import Client, OAuth2

oauth = OAuth2(
    client_id='YOUR_CLIENT_ID',
    client_secret='YOUR_CLIENT_SECRET',
    access_token='ACCESS_TOKEN',
    refresh_token='REFRESH_TOKEN',
)

client = Client(oauth)
user = client.user().get()
```

This will retrieve the current user! From here you can use the client
you created to start making calls.

## Other Auth Options

For advanced uses of the SDK, three additional auth classes are
provided:

-   `CooperativelyManagedOAuth2`: Allows multiple auth instances to
    share tokens.
-   `RemoteOAuth2`: Allows use of the SDK on clients without access to
    your application's client secret. Instead, you provide a
    `retrieve_access_token` callback. That callback should perform the
    token refresh, perhaps on your server that does have access to the
    client secret.
-   `RedisManagedOAuth2`: Stores access and refresh tokens in Redis.
    This allows multiple processes (possibly spanning multiple machines)
    to share access tokens while synchronizing token refresh. This could
    be useful for a multiprocess web server, for example.

# Usage Documentation

Full documentation of the available functionality with example code is
available in the [SDK documentation
pages](https://github.com/box/box-python-sdk/blob/main/docs/usage), and
there is also method-level documentation available on
[ReadTheDocs](https://box-python-sdk.readthedocs.io/en/stable/index.html).

## Making API Calls Manually

The Box API is continually evolving. As such, there are API endpoints
available that are not specifically supported by the SDK. You can still
use these endpoints by using the `make_request` method of the `Client`.

``` python
# https://developer.box.com/en/reference/get-metadata-templates-id/
# Returns a Python dictionary containing the result of the API request
json_response = client.make_request(
    'GET',
    client.get_url('metadata_templates', 'enterprise', 'customer', 'schema'),
).json()
```

`make_request()` takes two parameters:

-   `method` - an HTTP verb like `GET` or `POST`
-   `url` - the URL of the requested API endpoint

The `Client` class and Box objects have a `get_url` method. Pass it an
endpoint to get the correct URL for use with that object and endpoint.

For API calls which require body or query params, you can use `**kwargs`
to pass extra params:

-   `data` - takes a jsonified dictionary of body parameters
-   `params` - takes a dictionary of query parameters

``` python
# https://developer.box.com/reference/post-folders/
# Creates a new folder

# JSONify the body
body = json.dumps({
        'name': 'test-subfolder',
        'parent': {
            'id': '0',
        }
})

client.make_request(
    'POST',
    client.get_url('folders'),
    params={'fields': 'name,id'},
    data=body
)
```

# Other Client Options

## Logging Client

For more insight into the network calls the SDK is making, you can use
the `LoggingClient` class. This class logs information about network
requests and responses made to the Box API.

``` pycon
>>> from boxsdk import LoggingClient
>>> client = LoggingClient()
>>> client.user().get()
GET https://api.box.com/2.0/users/me {'headers': {u'Authorization': u'Bearer ---------------------------kBjp',
             u'User-Agent': u'box-python-sdk-1.5.0'},
 'params': None}
{"type":"user","id":"..","name":"Jeffrey Meadows","login":"..",..}
<boxsdk.object.user.User at 0x10615b8d0>
```

## Developer Token Client

The Box Developer Console allows for the creation of short-lived
developer tokens. The SDK makes it easy to use these tokens. Use the
`get_new_token_callback` parameter to control how the client will get
new developer tokens as needed. The default is to prompt standard input
for a token.

## Development Client

For exploring the Box API, or to quickly get going using the SDK, the
`DevelopmentClient` class combines the `LoggingClient` with the
`DeveloperTokenClient`.

# Customization

## Custom Subclasses

Custom object subclasses can be defined:

``` pycon
from boxsdk import Client
from boxsdk import Folder

class MyFolderSubclass(Folder):
    pass

client = Client(oauth)
client.translator.register('folder', MyFolderSubclass)
folder = client.folder('0')

>>> print folder
>>> <Box MyFolderSubclass - 0>
```

If an object subclass is registered in this way, instances of this
subclass will be returned from all SDK methods that previously returned
an instance of the parent. See `BaseAPIJSONObjectMeta` and `Translator`
to see how the SDK performs dynamic lookups to determine return types.

# FIPS 140-2 Compliance

The Python SDK allows the use of FIPS 140-2 validated SSL libraries, such as OpenSSL 3.0.
However, some actions are required to enable this functionality.

Currently, the latest distributions of Python default to OpenSSL v1.1.1, which is not FIPS compliant.
Therefore, if you want to use OpenSSL 3.0 in your network communication,
you need to ensure that Python uses a custom SSL library.
One way to achieve this is by creating a custom Python distribution with the ssl module replaced.

If you are using JWT for authentication, it is also necessary to ensure that the cryptography library,
which is one of the extra dependencies for JWT, uses OpenSSL 3.0.
To enable FIPS mode for the `cryptography` library, you need to install a FIPS-compliant version of OpenSSL
during the installation process of cryptography using the `pip` command.

# Versions
We use a modified version of [Semantic Versioning](https://semver.org/) for all changes. See [version strategy](VERSIONS.md) for details which is effective from 30 July 2022.

## Supported Version

Only the current MAJOR version of SDK is supported. New features, functionality, bug fixes, and security updates will only be added to the current MAJOR version.

A current release is on the leading edge of our SDK development, and is intended for customers who are in active development and want the latest and greatest features.  Instead of stating a release date for a new feature, we set a fixed minor or patch release cadence of maximum 2-3 months (while we may release more often). At the same time, there is no schedule for major or breaking release. Instead, we will communicate one quarter in advance the upcoming breaking change to allow customers to plan for the upgrade. We always recommend that all users run the latest available minor release for whatever major version is in use. We highly recommend upgrading to the latest SDK major release at the earliest convenient time and before the EOL date.

## Version schedule

| Version | Supported Environments                                  | State     | First Release | EOL/Terminated |
|---------|---------------------------------------------------------|-----------|---------------|----------------|
| 3       | Python 3.6+                                             | Supported | 17 Jan 2022   | TBD            |
| 2       |                                                         | EOL       | 01 Nov 2018   | 17 Jan 2022    |
| 1       |                                                         | EOL       | 10 Feb 2015   | 01 Nov 2018    |

# Contributing

See
[CONTRIBUTING.md](https://github.com/box/box-python-sdk/blob/main/CONTRIBUTING.md).

## Developer Setup

Create a virtual environment and install packages -

``` console
mkvirtualenv boxsdk
pip install -r requirements-dev.txt
```

## Testing

Run all tests using -

``` console
tox
```

The tox tests include code style checks via pep8 and pylint.

The tox tests are configured to run on Python 3.6, 3.7, 3.8, 3.9, 3.10, 3.11
and PyPy (our CI is configured to run PyPy tests on pypy-3.6, pypy-3.7, pypy-3.8).

# Questions, Bugs, and Feature Requests?

Need to contact us directly? [Browse the issues
tickets](https://github.com/box/box-python-sdk/issues)! Or, if that
doesn't work, [file a new
one](https://github.com/box/box-python-sdk/issues/new) and we will get
back to you. If you have general questions about the Box API, you can
post to the [Box Developer
Forum](https://community.box.com/t5/Developer-Forum/bd-p/DeveloperForum).

# Copyright and License

    Copyright 2019 Box, Inc. All rights reserved.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/box/box-python-sdk",
    "name": "boxsdk",
    "maintainer": "",
    "docs_url": "https://pythonhosted.org/boxsdk/",
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "box oauth2 sdk",
    "author": "Box",
    "author_email": "oss@box.com",
    "download_url": "https://files.pythonhosted.org/packages/85/19/ea14622e93be7eda5acdf3ec89915f89a8ffa7b9c911d623199da68a4f62/boxsdk-3.9.2.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <img src=\"https://github.com/box/sdks/blob/master/images/box-dev-logo.png\" alt= \u201cbox-dev-logo\u201d width=\"30%\" height=\"50%\">\n</p>\n\n# Box Python SDK\n\n[![image](http://opensource.box.com/badges/active.svg)](http://opensource.box.com/badges)\n[![Documentation Status](https://readthedocs.org/projects/box-python-sdk/badge/?version=latest)](http://box-python-sdk.readthedocs.org/en/latest)\n[![image](https://github.com/box/box-python-sdk/workflows/build/badge.svg)](https://github.com/box/box-python-sdk/actions)\n[![image](https://img.shields.io/pypi/v/boxsdk.svg)](https://pypi.python.org/pypi/boxsdk)\n[![image](https://img.shields.io/pypi/dm/boxsdk.svg)](https://pypi.python.org/pypi/boxsdk)\n[![image](https://coveralls.io/repos/github/box/box-python-sdk/badge.svg?branch=main)](https://coveralls.io/github/box/box-python-sdk?branch=main)\n\nGetting Started Docs: <https://developer.box.com/guides/tooling/sdks/python/>\n\n<!-- START doctoc generated TOC please keep comment here to allow auto update -->\n<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->\n\n- [Installing](#installing)\n- [Getting Started](#getting-started)\n- [Authorization](#authorization)\n  - [Server-to-Server Auth with JWT](#server-to-server-auth-with-jwt)\n  - [Traditional 3-legged OAuth2](#traditional-3-legged-oauth2)\n  - [Other Auth Options](#other-auth-options)\n- [Usage Documentation](#usage-documentation)\n  - [Making API Calls Manually](#making-api-calls-manually)\n- [Other Client Options](#other-client-options)\n  - [Logging Client](#logging-client)\n  - [Developer Token Client](#developer-token-client)\n  - [Development Client](#development-client)\n- [Customization](#customization)\n  - [Custom Subclasses](#custom-subclasses)\n- [FIPS 140-2 Compliance](#fips-140-2-compliance)\n- [Versions](#versions)\n  - [Supported Version](#supported-version)\n  - [Version schedule](#version-schedule)\n- [Contributing](#contributing)\n  - [Developer Setup](#developer-setup)\n  - [Testing](#testing)\n- [Questions, Bugs, and Feature Requests?](#questions-bugs-and-feature-requests)\n- [Copyright and License](#copyright-and-license)\n\n<!-- END doctoc generated TOC please keep comment here to allow auto update -->\n\n# Installing\n\n``` console\npip install boxsdk\n```\n\nThe current version of the SDK is v3.x --- With this release support for\nPython 3.5 and earlier (including 2.x) has been dropped. if you're\nlooking for the code or documentation for v1.5.x, please see the [1.5\nbranch](https://github.com/box/box-python-sdk/tree/1.5).\n\n# Getting Started\n\nTo get started with the SDK, get a Developer Token from the\nConfiguration page of your app in the [Box Developer\nConsole](https://app.box.com/developers/console). You can use this token\nto make test calls for your own Box account.\n\nThe SDK provides an interactive `DevelopmentClient` that makes it easy\nto test out the SDK in a REPL. This client will automatically prompt for\na new Developer Token when it requires one, and will log HTTP requests\nand responses to aid in debugging and understanding how the SDK makes\nAPI calls.\n\n``` pycon\n>>> from boxsdk import DevelopmentClient\n>>> client = DevelopmentClient()\nEnter developer token: <ENTER DEVELOPER TOKEN HERE>\n>>> user = client.user().get()\nGET https://api.box.com/2.0/users/me {'headers': {'Authorization': '---wXyZ',\n            'User-Agent': 'box-python-sdk-2.0.0',\n            'X-Box-UA': 'agent=box-python-sdk/2.0.0; env=python/3.6.5'},\n'params': None}\n\"GET https://api.box.com/2.0/users/me\" 200 454\n{'Date': 'Thu, 01 Nov 2018 23:32:11 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Strict-Transport-Security': 'max-age=31536000', 'Cache-Control': 'no-cache, no-store', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'BOX-REQUEST-ID': '0b50luc09ahp56m2jmkla8mgmh2', 'Age': '0'}\n{'address': '',\n'avatar_url': 'https://cloud.app.box.com/api/avatar/large/123456789',\n'created_at': '2012-06-07T11:14:50-07:00',\n'id': '123456789',\n'job_title': '',\n'language': 'en',\n'login': 'user@example.com',\n'max_upload_size': 16106127360,\n'modified_at': '2018-10-30T17:01:27-07:00',\n'name': 'Example User',\n'phone': '',\n'space_amount': 1000000000000000.0,\n'space_used': 14330018065,\n'status': 'active',\n'timezone': 'America/Los_Angeles',\n'type': 'user'}\n\n>>> print(f'The current user ID is {user.id}')\nThe current user ID is 123456789\n```\n\nOutside of a REPL, you can initialize a new `Client` with just the\nDeveloper Token to get started.\n\n``` python\nfrom boxsdk import OAuth2, Client\n\nauth = OAuth2(\n    client_id='YOUR_CLIENT_ID',\n    client_secret='YOUR_CLIENT_SECRET',\n    access_token='YOUR_DEVELOPER_TOKEN',\n)\nclient = Client(auth)\n\nuser = client.user().get()\nprint(f'The current user ID is {user.id}')\n```\n\n# Authorization\n\nThe Box API uses OAuth2 for auth. The SDK makes it relatively painless\nto work with OAuth2 tokens.\n\n## Server-to-Server Auth with JWT\n\nThe Python SDK supports your [JWT\nAuthentication](https://developer.box.com/en/guides/authentication/jwt/)\napplications.\n\nAuthenticating with a JWT requires some extra dependencies. To get them,\nsimply\n\n``` console\npip install \"boxsdk[jwt]\"\n```\n\nInstead of instantiating your `Client` with an instance of `OAuth2`,\ninstead use an instance of `JWTAuth`.\n\n``` python\nfrom boxsdk import JWTAuth\nfrom boxsdk import Client\n\nauth = JWTAuth(\n    client_id='YOUR_CLIENT_ID',\n    client_secret='YOUR_CLIENT_SECRET',\n    enterprise_id='YOUR_ENTERPRISE_ID',\n    jwt_key_id='YOUR_JWT_KEY_ID',\n    rsa_private_key_file_sys_path='CERT.PEM',\n    rsa_private_key_passphrase='PASSPHRASE',\n)\n\naccess_token = auth.authenticate_instance()\nclient = Client(auth)\n```\n\nThis client is able to create application users:\n\n``` python\nned_stark_user = client.create_user('Ned Stark')\n```\n\nThese users can then be authenticated:\n\n``` python\nned_auth = JWTAuth(\n    client_id='YOUR_CLIENT_ID',\n    client_secret='YOUR_CLIENT_SECRET',\n    user=ned_stark_user,\n    jwt_key_id='YOUR_JWT_KEY_ID',\n    rsa_private_key_file_sys_path='CERT.PEM',\n    rsa_private_key_passphrase='PASSPHRASE'\n)\nned_auth.authenticate_user()\nned_client = Client(ned_auth)\n```\n\nRequests made with `ned_client` (or objects returned from\n`ned_client`'s methods) will be performed on behalf of the newly\ncreated app user.\n\n## Traditional 3-legged OAuth2\n\n### Get the Authorization URL\n\n``` python\nfrom boxsdk import OAuth2\n\noauth = OAuth2(\n    client_id='YOUR_CLIENT_ID',\n    client_secret='YOUR_CLIENT_SECRET',\n    store_tokens=your_store_tokens_callback_method,\n)\n\nauth_url, csrf_token = oauth.get_authorization_url('http://YOUR_REDIRECT_URL')\n```\n\nstore_tokens is a callback used to store the access token and refresh\ntoken. You might want to define something like this:\n\n``` python\ndef store_tokens(access_token, refresh_token):\n    # store the tokens at secure storage (e.g. Keychain)\n```\n\nThe SDK will keep the tokens in memory for the duration of the Python\nscript run, so you don't always need to pass store_tokens.\n\n### Authenticate (Get Access/Refresh Tokens)\n\nIf you navigate the user to the auth_url, the user will eventually get\nredirected to <http://YOUR_REDIRECT_URL?code=YOUR_AUTH_CODE>. After\ngetting the code, you will be able to use the code to exchange for an\naccess token and refresh token.\n\nThe SDK handles all the work for you; all you need to do is run:\n\n``` python\n# Make sure that the csrf token you get from the `state` parameter\n# in the final redirect URI is the same token you get from the\n# get_authorization_url method.\nassert 'THE_CSRF_TOKEN_YOU_GOT' == csrf_token\naccess_token, refresh_token = oauth.authenticate('YOUR_AUTH_CODE')\n```\n\n### Create an Authenticated Client\n\n``` python\nfrom boxsdk import Client\n\nclient = Client(oauth)\n```\n\nAnd that's it! You can start using the client to do all kinds of cool\nstuff and the SDK will handle the token refresh for you automatically.\n\n### Instantiate a Client Given an Access and a Refresh Token\n\nAlternatively, you can instantiate an OAuth2 object with the access\ntoken and refresh token. Once you have an oauth object you can pass that\ninto the Client object to instantiate a client and begin making calls.\n\n``` python\nfrom boxsdk import Client, OAuth2\n\noauth = OAuth2(\n    client_id='YOUR_CLIENT_ID',\n    client_secret='YOUR_CLIENT_SECRET',\n    access_token='ACCESS_TOKEN',\n    refresh_token='REFRESH_TOKEN',\n)\n\nclient = Client(oauth)\nuser = client.user().get()\n```\n\nThis will retrieve the current user! From here you can use the client\nyou created to start making calls.\n\n## Other Auth Options\n\nFor advanced uses of the SDK, three additional auth classes are\nprovided:\n\n-   `CooperativelyManagedOAuth2`: Allows multiple auth instances to\n    share tokens.\n-   `RemoteOAuth2`: Allows use of the SDK on clients without access to\n    your application's client secret. Instead, you provide a\n    `retrieve_access_token` callback. That callback should perform the\n    token refresh, perhaps on your server that does have access to the\n    client secret.\n-   `RedisManagedOAuth2`: Stores access and refresh tokens in Redis.\n    This allows multiple processes (possibly spanning multiple machines)\n    to share access tokens while synchronizing token refresh. This could\n    be useful for a multiprocess web server, for example.\n\n# Usage Documentation\n\nFull documentation of the available functionality with example code is\navailable in the [SDK documentation\npages](https://github.com/box/box-python-sdk/blob/main/docs/usage), and\nthere is also method-level documentation available on\n[ReadTheDocs](https://box-python-sdk.readthedocs.io/en/stable/index.html).\n\n## Making API Calls Manually\n\nThe Box API is continually evolving. As such, there are API endpoints\navailable that are not specifically supported by the SDK. You can still\nuse these endpoints by using the `make_request` method of the `Client`.\n\n``` python\n# https://developer.box.com/en/reference/get-metadata-templates-id/\n# Returns a Python dictionary containing the result of the API request\njson_response = client.make_request(\n    'GET',\n    client.get_url('metadata_templates', 'enterprise', 'customer', 'schema'),\n).json()\n```\n\n`make_request()` takes two parameters:\n\n-   `method` - an HTTP verb like `GET` or `POST`\n-   `url` - the URL of the requested API endpoint\n\nThe `Client` class and Box objects have a `get_url` method. Pass it an\nendpoint to get the correct URL for use with that object and endpoint.\n\nFor API calls which require body or query params, you can use `**kwargs`\nto pass extra params:\n\n-   `data` - takes a jsonified dictionary of body parameters\n-   `params` - takes a dictionary of query parameters\n\n``` python\n# https://developer.box.com/reference/post-folders/\n# Creates a new folder\n\n# JSONify the body\nbody = json.dumps({\n        'name': 'test-subfolder',\n        'parent': {\n            'id': '0',\n        }\n})\n\nclient.make_request(\n    'POST',\n    client.get_url('folders'),\n    params={'fields': 'name,id'},\n    data=body\n)\n```\n\n# Other Client Options\n\n## Logging Client\n\nFor more insight into the network calls the SDK is making, you can use\nthe `LoggingClient` class. This class logs information about network\nrequests and responses made to the Box API.\n\n``` pycon\n>>> from boxsdk import LoggingClient\n>>> client = LoggingClient()\n>>> client.user().get()\nGET https://api.box.com/2.0/users/me {'headers': {u'Authorization': u'Bearer ---------------------------kBjp',\n             u'User-Agent': u'box-python-sdk-1.5.0'},\n 'params': None}\n{\"type\":\"user\",\"id\":\"..\",\"name\":\"Jeffrey Meadows\",\"login\":\"..\",..}\n<boxsdk.object.user.User at 0x10615b8d0>\n```\n\n## Developer Token Client\n\nThe Box Developer Console allows for the creation of short-lived\ndeveloper tokens. The SDK makes it easy to use these tokens. Use the\n`get_new_token_callback` parameter to control how the client will get\nnew developer tokens as needed. The default is to prompt standard input\nfor a token.\n\n## Development Client\n\nFor exploring the Box API, or to quickly get going using the SDK, the\n`DevelopmentClient` class combines the `LoggingClient` with the\n`DeveloperTokenClient`.\n\n# Customization\n\n## Custom Subclasses\n\nCustom object subclasses can be defined:\n\n``` pycon\nfrom boxsdk import Client\nfrom boxsdk import Folder\n\nclass MyFolderSubclass(Folder):\n    pass\n\nclient = Client(oauth)\nclient.translator.register('folder', MyFolderSubclass)\nfolder = client.folder('0')\n\n>>> print folder\n>>> <Box MyFolderSubclass - 0>\n```\n\nIf an object subclass is registered in this way, instances of this\nsubclass will be returned from all SDK methods that previously returned\nan instance of the parent. See `BaseAPIJSONObjectMeta` and `Translator`\nto see how the SDK performs dynamic lookups to determine return types.\n\n# FIPS 140-2 Compliance\n\nThe Python SDK allows the use of FIPS 140-2 validated SSL libraries, such as OpenSSL 3.0.\nHowever, some actions are required to enable this functionality.\n\nCurrently, the latest distributions of Python default to OpenSSL v1.1.1, which is not FIPS compliant.\nTherefore, if you want to use OpenSSL 3.0 in your network communication,\nyou need to ensure that Python uses a custom SSL library.\nOne way to achieve this is by creating a custom Python distribution with the ssl module replaced.\n\nIf you are using JWT for authentication, it is also necessary to ensure that the cryptography library,\nwhich is one of the extra dependencies for JWT, uses OpenSSL 3.0.\nTo enable FIPS mode for the `cryptography` library, you need to install a FIPS-compliant version of OpenSSL\nduring the installation process of cryptography using the `pip` command.\n\n# Versions\nWe use a modified version of [Semantic Versioning](https://semver.org/) for all changes. See [version strategy](VERSIONS.md) for details which is effective from 30 July 2022.\n\n## Supported Version\n\nOnly the current MAJOR version of SDK is supported. New features, functionality, bug fixes, and security updates will only be added to the current MAJOR version.\n\nA current release is on the leading edge of our SDK development, and is intended for customers who are in active development and want the latest and greatest features.  Instead of stating a release date for a new feature, we set a fixed minor or patch release cadence of maximum 2-3 months (while we may release more often). At the same time, there is no schedule for major or breaking release. Instead, we will communicate one quarter in advance the upcoming breaking change to allow customers to plan for the upgrade. We always recommend that all users run the latest available minor release for whatever major version is in use. We highly recommend upgrading to the latest SDK major release at the earliest convenient time and before the EOL date.\n\n## Version schedule\n\n| Version | Supported Environments                                  | State     | First Release | EOL/Terminated |\n|---------|---------------------------------------------------------|-----------|---------------|----------------|\n| 3       | Python 3.6+                                             | Supported | 17 Jan 2022   | TBD            |\n| 2       |                                                         | EOL       | 01 Nov 2018   | 17 Jan 2022    |\n| 1       |                                                         | EOL       | 10 Feb 2015   | 01 Nov 2018    |\n\n# Contributing\n\nSee\n[CONTRIBUTING.md](https://github.com/box/box-python-sdk/blob/main/CONTRIBUTING.md).\n\n## Developer Setup\n\nCreate a virtual environment and install packages -\n\n``` console\nmkvirtualenv boxsdk\npip install -r requirements-dev.txt\n```\n\n## Testing\n\nRun all tests using -\n\n``` console\ntox\n```\n\nThe tox tests include code style checks via pep8 and pylint.\n\nThe tox tests are configured to run on Python 3.6, 3.7, 3.8, 3.9, 3.10, 3.11\nand PyPy (our CI is configured to run PyPy tests on pypy-3.6, pypy-3.7, pypy-3.8).\n\n# Questions, Bugs, and Feature Requests?\n\nNeed to contact us directly? [Browse the issues\ntickets](https://github.com/box/box-python-sdk/issues)! Or, if that\ndoesn't work, [file a new\none](https://github.com/box/box-python-sdk/issues/new) and we will get\nback to you. If you have general questions about the Box API, you can\npost to the [Box Developer\nForum](https://community.box.com/t5/Developer-Forum/bd-p/DeveloperForum).\n\n# Copyright and License\n\n    Copyright 2019 Box, Inc. All rights reserved.\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n\n",
    "bugtrack_url": null,
    "license": "Apache Software License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0",
    "summary": "Official Box Python SDK",
    "version": "3.9.2",
    "project_urls": {
        "Changelog": "https://github.com/box/box-python-sdk/blob/main/CHANGELOG.md",
        "Homepage": "https://github.com/box/box-python-sdk"
    },
    "split_keywords": [
        "box",
        "oauth2",
        "sdk"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a54b186677720f7925744a6f40dc90dc993611f1f19fd617abcd64be5db2cc0b",
                "md5": "cd2d432e6b4a049af61ace06dda264f3",
                "sha256": "44087bc208d3082e0a791f98e491c2eccc61cd5123cedc96e52d089e12c5f410"
            },
            "downloads": -1,
            "filename": "boxsdk-3.9.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cd2d432e6b4a049af61ace06dda264f3",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 139209,
            "upload_time": "2023-10-18T15:30:32",
            "upload_time_iso_8601": "2023-10-18T15:30:32.022966Z",
            "url": "https://files.pythonhosted.org/packages/a5/4b/186677720f7925744a6f40dc90dc993611f1f19fd617abcd64be5db2cc0b/boxsdk-3.9.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8519ea14622e93be7eda5acdf3ec89915f89a8ffa7b9c911d623199da68a4f62",
                "md5": "51013760824ca89b08a62fbd0a621ddc",
                "sha256": "10e23e2f82e9cff2b2e501b7ca7ffe7bac0e280d1cd4b2983dea95f826e3008b"
            },
            "downloads": -1,
            "filename": "boxsdk-3.9.2.tar.gz",
            "has_sig": false,
            "md5_digest": "51013760824ca89b08a62fbd0a621ddc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 467680,
            "upload_time": "2023-10-18T15:30:35",
            "upload_time_iso_8601": "2023-10-18T15:30:35.771202Z",
            "url": "https://files.pythonhosted.org/packages/85/19/ea14622e93be7eda5acdf3ec89915f89a8ffa7b9c911d623199da68a4f62/boxsdk-3.9.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-18 15:30:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "box",
    "github_project": "box-python-sdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "boxsdk"
}
        
Box
Elapsed time: 0.13636s