cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Python. Get full storage information

Python. Get full storage information

vas1992
Helpful | Level 5
Go to solution

Hello. How can I display the full size of my storage using python?

I was able to get only the occupied volume:

 

print(dbx.users_get_space_usage().used)

 

The only thing I could do was get this:

 

print(dbx.users_get_space_usage().allocation)

 

Result:

SpaceAllocation('individual', IndividualSpaceAllocation(allocated=2147483648))

 

I don't know how to extract "allocated" from here.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

@vas1992 Здравко is correct; here's what a simple usage of this may look like:

allocation = dbx.users_get_space_usage().allocation
if allocation.is_individual():
    print("Individual allocation:")
    print(allocation.get_individual().allocated)
elif allocation.is_team():
    print("Team allocation:")
    print(allocation.get_team().allocated)

 

View solution in original post

5 Replies 5

Здравко
Legendary | Level 20
Go to solution

@vas1992 wrote:

...

I don't know how to extract "allocated" from here.


Hi @vas1992,

You can do it like any other field on any other object in Python (as programing language). Just read what you have got in documentation. 'users_get_space_usage' method returns SpaceUsage class object. You have successful get in touch to 'used' field of this object (type int). 👍

The other field of the same object - 'allocation' - is not basic type, but another object! The object's type is SpaceAllocation - an union of individual and team allocation data. Since your account is individual (in the particular case, but you should check it in a common case), 'get_individual' method is applicable. This method result is of type IndividualSpaceAllocation class. I believe it's easy to see that field 'allocated' can be accessed here (int type) in the same way you are accessing 'used' field before. 😉 Take a look here too.

Hope this clarifies matter.

vas1992
Helpful | Level 5
Go to solution

Something I did not understand at all. It is possible as much as possible in detail, for stupid?

 

I use:

 

print(dropbox.users.SpaceAllocation('individual', value=None).get_individual())

 

I am getting an error:


Traceback (most recent call last):
File "/home/vas/MyScripts/UploadCSV/RMS_up_Dx.py", line 108, in <module>
space_usage(dbx)
File "/home/vas/MyScripts/UploadCSV/RMS_up_Dx.py", line 66, in space_usage
print(dropbox.users.SpaceAllocation('individual', value=None).get_individual())
File "/home/vas/.local/lib/python3.8/site-packages/stone/backends/python_rsrc/stone_base.py", line 145, in __init__
validator.validate_type_only(value)
File "/home/vas/.local/lib/python3.8/site-packages/stone/backends/python_rsrc/stone_validators.py", line 543, in validate_type_only
raise ValidationError('expected type %s, got %s' %
stone.backends.python_rsrc.stone_validators.ValidationError: expected type dropbox.users.IndividualSpaceAllocation, got null

Greg-DB
Dropbox Staff
Go to solution

@vas1992 Здравко is correct; here's what a simple usage of this may look like:

allocation = dbx.users_get_space_usage().allocation
if allocation.is_individual():
    print("Individual allocation:")
    print(allocation.get_individual().allocated)
elif allocation.is_team():
    print("Team allocation:")
    print(allocation.get_team().allocated)

 

Здравко
Legendary | Level 20
Go to solution

@vas1992 wrote:

...

I am getting an error:

...


Of course, when you are using invalid object, errors can be expected. Even more, would be strange if it passes without error.

vas1992
Helpful | Level 5
Go to solution

Thank you for helping me.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    vas1992 Helpful | Level 5
  • User avatar
    Здравко Legendary | Level 20
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?