GithubHelp home page GithubHelp logo

python-boxview's Introduction

python-boxview

Python client library for Box View API

Installation

The easiest way to install the latest version is by using pip/easy_install to pull it from PyPI:

pip install python-boxview

You may also use Git to clone the repository from Github and install it manually:

git clone https://github.com/caxap/python-boxview.git
python setup.py install

Authentication

Box View API uses token-based authentication. You need create application and generate api token at Box Developes Portal. Then use the token to create instance

from boxview import boxview

api = boxview.BoxView('<your box view api key>')

Alternatively, token can be set by environment variable BOX_VIEW_API_KEY.

Usage

python-boxview supports all methods from Box View API. List of methods and parameters description can be found here

import os
from boxview import boxview

api = boxview.BoxView('<your box view api key>')

# upload file to create new document
doc = api.create_document(file='python-boxview.pdf', name='python-boxview')

# create new document from public url
doc = api.create_document(url='https://cloud.box.com/shared/static/4qhegqxubg8ox0uj5ys8.pdf')

doc_id = doc['id']

# retrieve existings document
doc1 = api.get_document(doc_id)

# list all uploaded documents for your api key
all_docs = api.get_documents(limit=10)

# update name of existing document
doc1 = api.update_document(doc_id, name='python-boxview')

# check that document ready to view
bool(api.ready_to_view(doc_id))

# start view session for document
session = api.create_session(doc_id, duration=300)

ses_id = session['id']

# get link to box viewer
api.get_session_url(ses_id)

# retrieve original document content to string
content, mimetype = api.get_document_content_to_string(doc_id)
len(content)

# retrieve pdf version of document to file
api.get_document_content_to_file('python-boxview.pdf', doc_id, extension='.pdf')
os.path.exists('python-boxview.pdf')

# retrieve mimetype of original document content
mimetype = api.get_document_content_mimetype(doc_id)

# create webhook
api.create_webhook('http://example.com/my-webhook')

# create S3 storage profile
api.create_storage_profile('S3', 'super-awesome-bucket', 'AKIAIOSFODNN7EXAMPLE', 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY')

# and delete document
api.delete_document(doc_id)

Dealing with Rate Limiting

import time
from boxview import boxview

api = boxview.BoxView('<your box view api key>')

document_id = '2da6cf9261824fb0a4fe532f94d14625'
retry, max_retry = 0, 3
while True:
    try:
        api.get_thumbnail_to_file('thumbnail_100x100.png', document_id, 100, 100)
        break  # ok, thumbnail saved
    except boxview.RetryAfter as e:
        retry += 1
        if retry <= max_retry:
            time.sleep(e.seconds) # waiting for next call
        else:
            raise  # failed after `max_retry` attempts, exit with exception

License

The MIT License (MIT)

Contributed by Maxim Kamenkov

python-boxview's People

Contributors

caxap avatar nicolastobo avatar smcoll avatar suriya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

python-boxview's Issues

Box View and Crocodoc End of Life Notice and information on the New Box View

Hi,

Seems the old BOX View API is going to expire soon.
They are planning to end the BOX View API.
This is the below email I got from Box recently

_Four years ago, Box acquired Crocodoc to power a truly first-class content viewing experience for documents in the Box web and mobile applications. We also offered this technology as a standalone API service, known as the Box View API, which allowed developers to convert and display documents in their own applications. Additionally, we continued to support developers using Crocodoc to do the same. These API services, however, were built using legacy technologies and on a separate technology stack from the core Box API. This resulted in a poor experience for developers and made it difficult to maintain and introduce improvements to these services. To alleviate these issues, we set out to build the new Box View service.

The new Box View has been generally available since November 2016 to existing Crocodoc and Box View customers like you. The new Box View allows you to display high-fidelity, interactive viewers for documents, images, videos, 360 images and videos, 3D files and more in your web and mobile apps. Using the new Box View, you can display nearly any file type without having to build your own viewers.

You can learn how to start using the new Box View in your apps today with our Getting Started Guide.

The new Box View offers several improvements over Crocodoc and the legacy Box View API, including improved rendering fidelity, expanded support for new file types, and advanced security functionality like encryption and virus scanning. The new Box View is also built on the same technology stack as the Box web and mobile applications, allowing for continuous improvement and expanded capabilities to be introduced.

The new Box View is intended to be used in place of the existing Box View and Crocodoc API services. On January 15, 2018, we will end-of-life (EOL) Crocodoc and the legacy Box View API services. This means you will need to migrate your app and its content to the new Box View. You can check out the Migration Guide to learn more about moving your application to the new Box View. You can also explore our FAQ to answer any questions you may have.

We're excited about this new service and can't wait to see all the amazing apps you build with it! We also understand that you may have come to rely on Crocodoc or the legacy Box View API and we are striving to make the transition to the new Box View as seamless as possible. If you have any questions, please do not hesitate to email us at [email protected]._

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.