Skip to main content

pydevice

Python interface for the Device Magic API

Installation

PyPi:

pip3 install pydevice

Git:

git clone https://github.com/aseli1/pydevice.git
cd pydevice
python3 setup.py install

Tested on Python 3.6 -- works on Mac

Usage

>>> from pydevice import DeviceMagic
>>> args = {'org_id': 3000,'database_id': 580, 'form_id': 6000, 'resource_id': 103, 'file_path': 'path/to/file'}
>>> dm = DeviceMagic(args)
>>> dm.form.all() # destination, device, resource, group, and dispatch also have this method
{'forms': [{'id': 40015631, 'name': 'Daily Report'...}

Authentication

Authentication is handled by the DeviceMagic class. The class can handle authentication automatically if the environment variable DEVICEMAGIC_API_KEY is set with your api key.

>>> import os
>>> os.environ['DEVICEMAGIC_API_KEY'] = 'Basic c3ppZhh39fj3Wjk6eA=='
>>> dm = DeviceMagic(args)

In preference, you can pass the key explicitly:

>>> dm = DeviceMagic({'api_key': 'Basic c3ppZhh39fj3Wjk6eA=='})

Database

>>> args = {'database_id': 500}
>>> dm = DeviceMagic(args)
>>>
>>> dm.database.json() # All submissions
{'per_page': 30, 'current_page': 1, 'total_pages': 1, 'current_count': 13, 'total_count': 13, 'submissions': [{'form'...
>>>
>>> dm.database.json("from_date=2018-5-1 00:00", "to_date=2018-5-31 00:00") # Filter submissions
{...'total_count': 1, 'submissions': [{'form': {'id': 6009105, 'name': 'Sales Report'...}

Destination

>>> args = {'form_id': 700}
>>> dm = DeviceMagic(args)
>>>
>>> from some_file import destination_json
>>> docx_to_email = 17443 # Destination id
>>> google_sheet = 17465
>>> old_destination = 17432
>>> new_form = 8475
>>>
>>> dm.destination.all() # All form destinations
{'destinations': [{'id': 17442, 'description': None, 'active': True...}]}
>>>
>>> dm.destination.details(docx_to_email)
{'destination': {'id': 17443, 'description': '', 'active': True, 'form_id': 7225921, 'format_type': 'word_format', 'format_id': 14990, 'transport_type': 'email_transport'...
>>>
>>> dm.destination.create(destination_json) # Create a destination
>>>
>>> dm.destination.update(google_sheet, destination_json)
>>>
>>> dm.destination.delete(old_destination)
>>>
>>> dm.destination.copy(docx_to_email) # Copy a destination
>>> dm.destination.copy(docx_to_email, form_id=new_form) # Copy to another form

Device

>>> args = {'org_id': 800}
>>> dm = DeviceMagic(args)
>>>
>>> omaha_tablet = 281 # Device id
>>> new_device = 543
>>> old_device = 93
>>>
>>> dm.device.all() # All devices in organization
{'devices': [{'id': 281, 'identifier': 'Android_d5c2a9d...
>>>
>>> dm.device.details(omaha_tablet) # Device details
{'id': 281, 'identifier': 'Android_d5c2a9d...
>>>
>>> dm.device.delete(old_device)
>>>
>>> dm.device.approve(new_device)
>>>
>>> device_json = {
        'device':{
            'owner':'Audrey',
            'description':'Abroad helping others',
            'groups':'Outreach'
        }
    }
>>>
>>> dm.device.update(new_device, device_json) # Change device name, description and group(s)

Form

>>> args = {'org_id': 800}
>>> dm = DeviceMagic(args)
>>>
>>> from some_file import group_json
>>> site_survey = 400 # Form id
>>> old_form = 235
>>>
>>> dm.form.all() # All forms in organization
{'forms': [{'id': 400, 'name': 'Site Survey'...
>>>
>>> dm.form.details(site_survey)
{'type': 'root', 'children': [{'identifier': 'Time_on_site'...
>>>
>>> with open('form.json') as json:
...     dm.form.create(json.read())
...
{'type': 'root', 'children': [{'identifier': 'Serial_number'...
>>>
>>> dm.form.update(site_survey, form_json)
>>>
>>> dm.form.delete(old_form)
>>>
>>> dm.form.new_group(site_survey, group_json) # Change form group

Resource

>>> args = {'file_path': 'path/to/material_list.xlsx'}
>>> dm = DeviceMagic(args)
>>>
>>> cost_of_material = 7898 # Resource id
>>> customer_list = 9789
>>> old_resource = 6778
>>> file_as_string = 'eyJub3J0aCI6IjM4L...'
>>> mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
>>>
>>> dm.resource.all() # All organization resources
{'resources': [{'id': 6958, 'original_filename': 'Equipment List.xlsx...'}
>>>
>>> dm.resource.details(customer_list)
{'resource': {'id': 9789, 'identifier': '52945f50-408...'}
>>>
>>> dm.resource.download(customer_list) # Download file
>>>
>>> dm.resource.create('Copy of all materials', 'material_list.xlsx') # Create a resource
>>>
>>> dm.resource.create('Copy of all materials', 'material_list.xlsx', file_as_string, mime) # Pass a file directly
>>>
>>> dm.resource.update(cost_of_material, 'With updated pricing', 'cost_of_material.xlsx') # Optionally, pass a file
>>>
>>> dm.resource.clone(cost_of_material, mime) # Clone an existing resource
>>>
>>> dm.resource.delete(old_resource)

Group

>>> args = {'org_id': 400}
>>> dm = DeviceMagic(args)
>>>
>>> from some_file import group_json
>>> old_group = 879 # Group id
>>> technician = 900
>>>
>>> dm.group.all() # All organization groups
{'groups': [{'id': 3643, 'name': 'Engineer', 'form_ids': [...]}
>>>
>>> dm.group.create(group_json) # Create a group
>>>
>>> dm.group.update(technician, group_json)
>>>
>>> dm.group.delete(old_group)

Dispatch

>>> args = {'org_id': 600}
>>> dm = DeviceMagic(args)
>>>
>>> from some_file import dispatch_json
>>> new_brunswick_tab = 'Android_d5c2a9db-7c7e-465b'
>>> ontario_phone = 'iPhone_8775938_48795749'
>>> service_call = 13434 # Dispatch id
>>> old_dispatch = 11947
>>>
>>> dm.dispatch.all() # All outstanding dispatches
'[{"form": {"id": 72343, "name": "Daily Inspection","namespace"...'
>>>
>>> dm.dispatch.push(new_brunswick, dispatch_json) # Dispatch a form
>>>
>>> dm.dispatch.update(new_brunswick, service_call, dispatch_json)
>>>
>>> dm.dispatch.delete(ontario_phone, dispatch_id=old_dispatch) # Delete a single dispatch
>>>
>>> dm.dispatch.delete(ontario_phone) # Remove all

Official Device Magic API docs

Metadata

Release files for pydevice 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydevice 0.3.3
File Size Uploaded Provenance
pydevice-0.3.3.tar.gz 9.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pydevice 0.3.3
File Interpreter ABI Platform
pydevice-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 20.3 kB

Release files / pydevice-0.3.3.tar.gz

Download URL pydevice-0.3.3.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d715da6d6523098b7ee4a68bd61005defb14fe45ff0760a95983f874c0b6ac79
BLAKE2b-256 checksum
How to use checksums
0b66fcb3797c9132b065b973d344dffd52e0fa21bf76585ca0dbd465d5a0c8b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.3 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.3 CPython/3.9.1

Release files / pydevice-0.3.3-py3-none-any.whl

Download URL pydevice-0.3.3-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2bcb1ecc91c91b5943b4380999fb59ba7a71bf1657ac1e427a0821a5ec096dc
BLAKE2b-256 checksum
How to use checksums
b06b9e5ca63f758def6d0ab67c4a4aea1fdb4fa58e810dbeab411182266bd23c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.3 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.3 CPython/3.9.1

Security for pydevice 0.3.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page