Skip to the documentation
Python

Files

`files.list`, `list_all`, `iterate`, `get`, `download`, `list_links`, `list_all_links`, `iterate_links`, `create_link`, `revoke_link`, `stats`, `upload`, `delete` and `delete_many`.

Every method

files.py
from pathlib import Path from openemail import openemail page = openemail.files.list(kind='pdf', sort='largest')file = page['items'][0] Path(file['filename']).write_bytes(openemail.files.download(file['id'])) links = openemail.files.list_all_links(file['id'])print([(link['url'], link['downloads']) for link in links]) stats = openemail.files.stats()print(stats['totals']['files'], stats['uploaded']['bytes'])

Every file the mailbox holds, attachments sent and received and the files uploaded to it, the Files page of the app. download returns the whole file as bytes, the links are the download links a file went out as, with how often each was fetched, and stats is the Analytics tab.

list, list_all and iterate take q, kind and sort, and also direction (inbound, outbound or uploaded), address, the files of one address compared without regard to case, and since and until, a datetime or an ISO 8601 string. since includes its moment and until stops before it.

Reading needs files:read, and uploading, deleting and publishing or revoking links need files:write, which includes files:read. A key made before files had scopes of their own was given the matching ones. A key limited to particular addresses or domains sees only the files on them.

Upload and delete

upload.py
from pathlib import Path from openemail import openemail upload = openemail.files.upload(    Path('price-list.pdf').read_bytes(),    filename='price-list.pdf',    content_type='application/pdf',) if upload['deletable']:    openemail.files.delete(upload['id']) result = openemail.files.delete_many([    'file_0c4e7a91d2b84f63a5e19b7d',    'file_6bb640f5b99e47deb758f1f5',])for kept in result['kept']:    print(kept['filename'], kept['reason'])

upload stores the bytes as they are, up to 100 MB, under filename, and returns the file, whose id a send attaches as {'fileId': upload['id']}. Pass content_type, or the bytes are stored as application/octet-stream. It is never retried, because a second attempt would store a second copy.

Only an upload that nothing depends on can be deleted, and deletable and usage on each file say so ahead of time. delete refuses any other file with a 409 file_in_use. delete_many takes up to 100 ids, deletes what it can, and reports the rest in kept, each with its reason, and in missing.

upload takes bytes, bytearray or memoryview. It waits at least 600 seconds for an answer, however short the client’s timeout, unless you pass timeout= to the call, and a blank filename raises ValueError before anything is sent.

Reference