Skip to main content

Aspose.Email Cloud API

Project description

Aspose.Email Cloud SDK for Python PYPI License

This repository contains Aspose.Email Cloud SDK for Python source code. This SDK allows you to work with Aspose.Email Cloud REST APIs in your Python applications quickly and easily, with zero initial cost.

Aspose.Email Cloud home
API Reference

Key features

Aspose.Email Cloud is a REST API for creating email applications that work with standard email file formats. This SDK:

  • Lets developers manipulate different emails’ formats such as Outlook MSG, EML, VCard, and iCalendar files
  • Has a built-in email client
  • Supports AI functionalities:
    • The Business card recognition
    • The Name API for parsing and handling personal names

How to use the SDK?

The complete source code is available in the GIT repository. Use reference documentation, examples from this document and wiki

Prerequisites

To use this SDK, you need an App SID and an App Key; they can be looked up at Aspose Cloud Dashboard (it requires free registration in Aspose Cloud for this).

Installation

You can use it directly in your project via the source code or get a PYPI Package:

pip install aspose-email-cloud

Usage examples

To use the API, you should create an EmailApi object:

from AsposeEmailCloudSdk import api #EmailApi class is here
from AsposeEmailCloudSdk import models #REST API models are here
from AsposeEmailCloudSdk.models import requests #Request models are here (all API calls use corresponding request model class)

#...
app_sid = 'Your App SID'
app_key = 'Your App Key'
email_api = api.EmailApi(app_key, app_sid)

API calls can be synchronous or asynchronous (using ThreadPool from multiprocessing.pool):

result = email_api.get_calendar(
    requests.GetCalendarRequest(
        calendar_file,
        folder,
        storage))
# or
async_result = email_api.get_calendar_async( #returns multiprocessing.pool.AsyncResult
    requests.GetCalendarRequest(
        calendar_file,
        folder,
        storage))
result = async_result.get()

Business cards recognition API

See examples below:

Parse business card images to VCard contact files
storage = 'First Storage' # Your storage name
file_name = 'some_file_name.png' #Supports different image formats: PNG, JPEG, BMP, TIFF, GIF, etc.
image_file = 'some/business/card/image/file/on/disk.png'
folder = 'some/folder/path/on/storage'
# Upload business card image to storage
storage_location = folder + '/' + file_name
email_api.upload_file(
    requests.UploadFileRequest(storage_location, image_file, storage))

out_folder_path = 'some/other/folder/path/on/storage' # Business card recognition results will be saved here
email_api.create_folder(requests.CreateFolderRequest(out_folder_path, storage))
# Call business card recognition action
result = email_api.ai_bcr_parse_storage(requests.AiBcrParseStorageRequest(
    models.AiBcrParseStorageRq(
        images=[
            models.AiBcrImageStorageFile(
                True, #Flag isSingle determines that image contains single VCard or more.
                      #Only single VCard on image variant is supported in current version.
                models.StorageFileLocation(storage, folder, file_name))],
        out_folder=models.StorageFolderLocation(storage, out_folder_path))))
# Get file name from recognition result
contact_file = result.value[0] # result.value can contain multiple files, if we sent multicard images or multiple images
# You can download the VCard file, which produced by the recognition method ...
downloaded = email_api.download_file(requests.DownloadFileRequest(
    contact_file.folder_path + '/' + contact_file.file_name,
    storage))
# ... and print it to console
with open(downloaded, 'r') as f:
    file_data = f.read()
    print(file_data)
# Also, you can get VCard object properties’ list using Contact API
contact_properties = email_api.get_contact_properties(
    requests.GetContactPropertiesRequest(
        'VCard',
        contact_file.file_name,
        contact_file.folder_path,
        contact_file.storage))
# All VCard’s properties are available as a list. Complex properties are represented as hierarchical structures.
# Let's print all primitive properties’ values:
primitives = (prop for prop in contact_properties.internal_properties
    if  prop.type == 'PrimitiveObject')
for prop in primitives:
    print('Property name: ' + prop.name + ' value: ' + prop.value)
Parse images directly, without the using of a storage
# Read image from file and convert it to Base64 string
image_file = 'some/business/card/image/file/on/disk.png'
image_data = None
with open(image_file, 'rb') as f:
    file_data = f.read()
    image_data = str(base64.b64encode(file_data), 'utf-8')
result = email_api.ai_bcr_parse(requests.AiBcrParseRequest(
    models.AiBcrBase64Rq(images=[
        models.AiBcrBase64Image(True, image_data)])))
# Result contains all recognized VCard objects (only the one in our case)
contact_properties = result.value[0]
# VCard object is available as a list of properties, without any external calls:
primitives = (prop for prop in contact_properties.internal_properties
    if  prop.type == 'PrimitiveObject')
for prop in primitives:
    print('Property name: ' + prop.name + ' value: ' + prop.value)

Name API

See examples below:

Detect a person's gender by name
result = email_api.ai_name_genderize(
    requests.AiNameGenderizeRequest('John Cane'))
# the result contains a list of hypothesis about a person's gender.
# all hypothesis include score, so you can use the most scored version,
# which will be the first in a list:
print(result.value[0].gender) # prints 'Male'
Format person's name using defined format
result = email_api.ai_name_format(
    requests.AiNameFormatRequest(
        'Mr. John Michael Cane',
        format='%t%L%f%m'))
print(result.name) # prints 'Mr. Cane J. M.'
Compare the names to find out if they belong to the same person or not
first = 'John Michael Cane'
second = 'Cane J.'
result = email_api.ai_name_match(
    requests.AiNameMatchRequest(first, second))
print(result.similarity >= 0.5) # prints 'True', names look similar
Expand a person's name into a list of possible alternatives
name = 'Smith Bobby'
result = email_api.ai_name_expand(
    requests.AiNameExpandRequest(name))
expanded_names = list(weighted.name for weighted in result.names)
for (expanded_name in expanded_names):
    print expanded_name # prints 'Mr. Smith', 'B. Smith', etc.
Get k most probable names for given starting characters
prefix = 'Dav'
result = email_api.ai_name_complete(
    requests.AiNameCompleteRequest(prefix))
names = list(prefix + weighted.name for weighted in result.names)
for (name in names):
    print(name) # prints 'David', 'Dave', 'Davis', etc.
Parse out a person's name from an email address.
address = 'john-cane@gmail.com'
result = email_api.ai_name_parse_email_address(
    requests.AiNameParseEmailAddressRequest(address))
names = (extracted.name for extracted in result.value)
extracted_values = list(functools.reduce(lambda a,b: a+b, names))
given_name = next((x for x in extracted_values if x.category == 'GivenName'))
surname = next((x for x in extracted_values if x.category == 'Surname'))
print(given_name.value) # prints 'John'
print(surname.value) # prints 'Cane'

Licensing

All Aspose.Email Cloud SDKs, helper scripts and templates are licensed under MIT License.

Resources

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aspose-email-cloud-20.2.0.tar.gz (115.0 kB view hashes)

Uploaded Source

Built Distribution

aspose_email_cloud-20.2.0-py3-none-any.whl (491.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page