Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

amazon-photos

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amazon-photos

Amazon Photos API

  • 0.0.97
  • PyPI
  • Socket score

Maintainers
1

Amazon Photos API

Table of Contents

  • Installation
  • Setup
  • Examples
  • Search
  • Nodes
  • Notes
  • Custom Image Labeling (Optional)

It is recommended to use this API in a Jupyter Notebook, as the results from most endpoints are a DataFrame which can be neatly displayed and efficiently manipulated with vectorized ops. This becomes increasingly important if you have "large" amounts of data (e.g. >1 million photos/videos).

Installation

pip install amazon-photos -U

Output Examples

ap.db

dateTimeDigitizedidname...modelapertureValuefocalLengthwidthheightsize
02019-07-06T18:22:00.000ZHeMReF-vvJiTTkdPIeWuoP1694252973839.png...iPhone XS54823/3232517/430244032432777
12023-01-18T09:36:22.000Zz_HiIvASAKqWmdrkjWiqMZ1692626817154.jpg...iPhone XS54823/3232517/430244032234257
22022-08-14T14:13:21.000ZLKXEZbqoVrhrOYBezisGEQ1798219686789.jpg...iPhone 11 Pro Max54823/3232517/430244032423987
32020-06-28T19:32:30.000ZEPUeciHtfKkGiYkfUyEuMa1593482220567.jpg...iPhone XS54823/3232517/430244032898957
42021-07-07T17:12:55.000ZfdfKzRJbEyoVeGcfCoJgE-1592299282720.png...iPhone XR54823/3232517/430244032432556
52021-08-18T18:32:41.000ZcrskJSmKPFRhxbpfkivyLm1592902159105.png...iPhone XR54823/3232517/430244032123123
62023-08-23T19:12:21.000ZqkBFUlyIdkUwVVSaVWWKEF1598138358650.png...iPhone 1154823/3232517/430244032437887
72021-06-19T17:14:13.000ZTXKMKC-mHvSUrtRfwmtyDe1622199863606.jpg...iPhone 12 Pro14447/1065321/515362048758432
82023-02-15T22:45:40.000ZFRDvvjcZdpFWiwrIZfTNHO1581874518054.jpg...iPhone 8 Plus54823/32325399/10013482049862883

ap.print_tree()

~ 
├── Documents 
├── Pictures 
│   ├── iPhone 
│   └── Web 
│       ├── foo 
│       └── bar
├── Videos 
└── Backup 
    ├── LAPTOP-XYZ 
    │   └── Desktop 
    └── DESKTOP-IJK 
        └── Desktop

Setup

[Update] Jan 04 2024: To avoid confusion, setting env vars is no longer supported. One must pass cookies directly as shown below.

Log in to Amazon Photos and copy the following cookies:

  • session-id
  • ubid*
  • at*

Canada/Europe

where xx is the TLD (top-level domain)

  • ubid-acbxx
  • at-acbxx

United States

  • ubid_main
  • at_main

E.g.

from amazon_photos import AmazonPhotos

ap = AmazonPhotos(
    ## US
    # cookies={
    #     'ubid_main': ...,
    #     'at_main': ...,
    #     'session-id': ...,
    # },

    ## Canada
    # cookies={
    #     'ubid-acbca': ...,
    #     'at-acbca': ...,
    #     'session-id': ...,
    # }

    ## Italy
    # cookies={
    #     'ubid-acbit': ...,
    #     'at-acbit': ...,
    #     'session-id': ...,
    # }
)

Examples

A database named ap.parquet will be created during the initial setup. This is mainly used to reduce upload conflicts by checking your local file(s) md5 against the database before sending the request.

from amazon_photos import AmazonPhotos

ap = AmazonPhotos(
    # see cookie examples above
    cookies={...},
    # optionally cache all intermediate JSON responses
    tmp='tmp',
    # pandas options
    dtype_backend='pyarrow',
    engine='pyarrow',
)

# get current usage stats
ap.usage()

# get entire Amazon Photos library
nodes = ap.query("type:(PHOTOS OR VIDEOS)")

# query Amazon Photos library with more filters applied
nodes = ap.query("type:(PHOTOS OR VIDEOS) AND things:(plant AND beach OR moon) AND timeYear:(2023) AND timeMonth:(8) AND timeDay:(14) AND location:(CAN#BC#Vancouver)")

# sample first 10 nodes
node_ids = nodes.id[:10]

# move a batch of images/videos to the trash bin
ap.trash(node_ids)

# get trash bin contents
ap.trashed()

# permanently delete a batch of images/videos
ap.delete(node_ids)

# restore a batch of images/videos from the trash bin
ap.restore(node_ids)

# upload media (preserves local directory structure and copies to Amazon Photos root directory)
ap.upload('path/to/files')

# download a batch of images/videos
ap.download(node_ids)

# convenience method to get photos only
ap.photos()

# convenience method to get videos only
ap.videos()

# get all identifiers calculated by Amazon.
ap.aggregations(category="all")

# get specific identifiers calculated by Amazon.
ap.aggregations(category="location")

Undocumented API, current endpoints valid Dec 2023.

For valid location and people IDs, see the results from the aggregations() method.

nametypedescription
ContentTypestr"JSON"
_int1690059771064
assetstr"ALL"
"MOBILE"
"NONE
"DESKTOP"

default: "ALL"
filtersstr"type:(PHOTOS OR VIDEOS) AND things:(plant AND beach OR moon) AND timeYear:(2019) AND timeMonth:(7) AND location:(CAN#BC#Vancouver) AND people:(CyChdySYdfj7DHsjdSHdy)"

default: "type:(PHOTOS OR VIDEOS)"
groupByForTimestr"day"
"month"
"year"
limitint200
lowResThumbnailstr"true"
"false"

default: "true"
resourceVersionstr"V2"
searchContextstr"customer"
"all"
"unknown"
"family"
"groups"

default: "customer"
sortstr"['contentProperties.contentDate DESC']"
"['contentProperties.contentDate ASC']"
"['createdDate DESC']"
"['createdDate ASC']"
"['name DESC']"
"['name ASC']"

default: "['contentProperties.contentDate DESC']"
tempLinkstr"false"
"true"

default: "false"

Nodes

Docs last updated in 2015

FieldNameFieldTypeSort AllowedNotes
isRootBooleanOnly lower case "true" is supported.
nameStringYesThis field does an exact match on the name and prefix query. Consider node1{ "name" : "sample" } node2 { "name" : "sample1" } Query filter
name:sample will return node1
name:sample* will return node1 and node2
kindStringYesTo search for all the nodes which contains kind as FILE kind:FILE
modifiedDateDate (in ISO8601 Format)YesTo Search for all the nodes which has modified from time modifiedDate:{"2014-12-31T23:59:59.000Z" TO *]
createdDateDate (in ISO8601 Format)YesTo Search for all the nodes created on createdDate:2014-12-31T23:59:59.000Z
labelsString ArrayOnly Equality can be tested with arrays.
if labels contains ["name", "test", "sample"].
Label can be searched for name or combination of values.
To get all the labels which contain name and test
labels: (name AND test)
descriptionStringTo Search all the nodes for description with value 'test'
description:test
parentsString ArrayOnly Equality can be tested with arrays.
if parents contains ["id1", "id2", "id3"].
Parent can be searched for name or combination of values.
To get all the parents which contains id1 and id2
parents:id1 AND parents:id2
statusStringYesFor searching nodes with AVAILABLE status.
status:AVAILABLE
contentProperties.sizeLongYes
contentProperties.contentTypeStringYesIf prefix query, only the major content-type (e.g. image*, video*, etc.) is supported as a prefix.
contentProperties.md5String
contentProperties.contentDateDate (in ISO8601 Format)YesRangeQueries and equals queries can be used with this field
contentProperties.extensionStringYes

Restrictions

Max # of Filter Parameters Allowed is 8

Filter TypeFilters
EqualitycreatedDate, description, isRoot, kind, labels, modifiedDate, name, parentIds, status
RangecontentProperties.contentDate, createdDate, modifiedDate
PrefixcontentProperties.contentType, name

Range Queries

OperationSyntax
GreaterThan{"valueToBeTested" TO *}
GreaterThan or Equal["ValueToBeTested" TO *]
LessThan{* TO "ValueToBeTested"}
LessThan or Equal{* TO "ValueToBeTested"]
Between["ValueToBeTested_LowerBound" TO "ValueToBeTested_UpperBound"]

Notes

  • This endpoint is called when downloading a batch of photos/videos in the web interface. It then returns a URL to download a zip file, then makes a request to that url to download the content. When making a request to download data for 1200 nodes (max batch size), it turns out to be much slower (~2.5 minutes) than asynchronously downloading 1200 photos/videos individually (~1 minute).

Known File Types

ExtensionCategory
.pdfpdf
.docdoc
.docxdoc
.docmdoc
.dotdoc
.dotxdoc
.dotmdoc
.asddoc
.cnvdoc
.mp3mp3
.m4amp3
.m4bmp3
.m4pmp3
.wavmp3
.aacmp3
.aifmp3
.mpamp3
.wmamp3
.flacmp3
.midmp3
.oggmp3
.xlsxls
.xlmxls
.xllxls
.xlcxls
.xarxls
.xlaxls
.xlbxls
.xlsbxls
.xlsmxls
.xlsxxls
.xltxls
.xltmxls
.xltxxls
.xlwxls
.pptppt
.pptxppt
.ppappt
.ppamppt
.pptmppt
.ppsppt
.ppsmppt
.ppsxppt
.potppt
.potmppt
.potxppt
.sldmppt
.sldxppt
.txttxt
.texttxt
.rtftxt
.xmlmarkup
.htmmarkup
.htmlmarkup
.zipzip
.rarzip
.7zzip
.jpgimg
.jpegimg
.pngimg
.bmpimg
.gifimg
.tifimg
.svgimg
.mp4vid
.m4vvid
.qtvid
.movvid
.mpgvid
.mpegvid
.3g2vid
.3gpvid
.flvvid
.f4vvid
.asfvid
.avivid
.wmvvid
.swfexe
.exeexe
.dllexe
.axexe
.ocxexe
.rpmexe

Custom Image Labeling (Optional)

Categorize your images into folders using computer vision models.

pip install amazon-photos[extras] -U

See the Model List for a list of all available models.

Sample Models

Very Large

eva02_base_patch14_448.mim_in22k_ft_in22k_in1k

Large

eva02_large_patch14_448.mim_m38m_ft_in22k_in1k

Medium

eva02_small_patch14_336.mim_in22k_ft_in1k
vit_base_patch16_clip_384.laion2b_ft_in12k_in1k
vit_base_patch16_clip_384.openai_ft_in12k_in1k
caformer_m36.sail_in22k_ft_in1k_384

Small

eva02_tiny_patch14_336.mim_in22k_ft_in1k
tiny_vit_5m_224.dist_in22k_ft_in1k
edgenext_small.usi_in1k
xcit_tiny_12_p8_384.fb_dist_in1k
run(
    'eva02_base_patch14_448.mim_in22k_ft_in22k_in1k',
    path_in='images',
    path_out='labeled',
    thresh=0.0,  # threshold for predictions, 0.9 means you want very confident predictions only
    topk=5,
    # window of predictions to check if using exclude or restrict, if set to 1, only the top prediction will be checked
    exclude=lambda x: re.search('boat|ocean', x, flags=re.I),
    # function to exclude classification of these predicted labels
    restrict=lambda x: re.search('sand|beach|sunset', x, flags=re.I),
    # function to restrict classification to only these predicted labels
    dataloader_options={
        'batch_size': 4,  # *** adjust ***
        'shuffle': False,
        'num_workers': psutil.cpu_count(logical=False),  # *** adjust ***
        'pin_memory': True,
    },
    accumulate=False,
    # accumulate results in path_out, if False, everything in path_out will be deleted before running again
    device='cuda',
    naming_style='name',  # use human-readable label names, optionally use the label index or synset
    debug=0,
)

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc