Skip to main content

A pure Python implementation of Picture Transfer Protocol.

Project description

# Introduction

Pure Python implementation of the PTP standard as specified in
ISO15740:2013(E).

This implementation is transport agnostic and can be used along with USB,
serial or IP layers to communicate with PTP compliant cameras.

The entire codebase, tools and examples are compatible with both Python 3 and
Python 2.

# Basic Usage

PTPy accomodates both the low-level developers wishing to test their PTP
implementation as well as users of the cameras in the market.

By default, PTPy will automatically detect which extension the camera supports
and load it so that the interaction is seamless.

> The most basic usage of PTPy with a camera connected is:

```python
from ptpy import PTPy

camera = PTPy()
print(camera.get_device_info())

with camera.session():
camera.initiate_capture()
```

Developers might want to disable the extra functionality, or impose an
extension to use. E.g. when the PTP Extension ID has not been assigned.

> It is possible to get bare PTP functionality with:

```python
from ptpy import PTPy

camera = PTPy(raw=True)
print(camera.get_device_info())

with camera.session():
# Do basic things here.
```

A developer might want to test the case where the extension is incorrectly
identified. This is possible by imposing an arbitrary extension.

> Impose MTP (Microsoft PTP Extension) to any camera:

```python
from ptpy import PTPy
from ptpy.extensions.microsoft import PTPDevice as mtp

camera = PTPy(extension=mtp)
with camera.session():
# Do bizarre things here.
```

Sessions are managed automatically with context managers.
All sessions under a top session with share the top session.

> To inspect the current session and transaction use the corresponding properties:

```python
from ptpy import PTPy

camera = PTPy()
with camera.session():
camera.get_device_info()

print('Top level session:')
print(camera.session_id)
print('Transaction ID:')
print(camera.transaction_id)

with camera.session():

camera.get_device_info()

print('Shared session:')
print(camera.session_id)

print('Transaction ID increases:')
print(camera.transaction_id)

with camera.session():
camera.get_device_info()

print('First session:')
print(camera.session_id)

print('Transaction ID:')
print(camera.transaction_id)

with camera.session():
camera.get_device_info()

print('Second session:')
print(camera.session_id)

print('Transaction ID:')
print(camera.transaction_id)
```

# Transports

## USB
A proof-of-concept USB implementation is provided using PyUSB. Though it might
not work with all USB controllers in cameras today. In some operating systems,
it might be necessary to be `root` in order to access USB devices directly.

For the USB transport, the `_shutdown` method is provided to explicitly release
the USB interface. At the end of the Python interpreter session this will happen
automatically.

## IP
A proof-of-concept PTP/IP implementation is provided using sockets. Since there
is no device discovery implemented yet, the address must be provided directly.

```python
from ptpy import PTPy
from ptpy.transports.ip import IPTransport

# Default PTP/IP port assumed
c = PTPy(transport=IPTransport, device='197.168.47.1')

# Optionally:
c = PTPy(transport=IPTransport, device=('197.168.47.1', 15740))
```

# Extensions

## State of the art

Full support for the Parrot Drone SAS extension is provided. Extensions are
meant to provice vendor-specific sets of operations, events and properties.

Partial support for Canon, Microsoft (MTP), and Nikon extensions is provided.
Full support is expected eventually.

Canon and Nikon extensions integrate their specific events mechanisms.

Extensions are managed automatically for users or can be imposed by developers.

## Framework

A developer can take any of the sample extensions as a model for others.

In general extensions do not need to overwrite any base PTP operations, events
or properties. Indeed most extensions will add some extra commands.

# Installing

To install issue `pip install .` or `pip install -e .` for developer mode. The
command `python setup.py install` should also work.

# Development

## Requirements

A `requirements.txt` file is provided for ease of development.
For developing tests, an additional `tests/requirements.txt` is provided.

Under Windows, install `libusb` or `libusb-win32` using
(zadig)[http://zadig.akeo.ie].

## Tests

Vendors might want to test their devices against the hardware tests. These
become immediately accessible when a camera is connected.

To launch tests issue `python setup.py test`.

A convenience Makefile is provided so the command becomes `make test`.

All tests are implemented using `py.test`, which can also be called directly:
`py.test ./tests`

# TODO

- Implement extension mapped codes from PTP1.1

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

ptpy-0.3.1.tar.gz (42.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ptpy-0.3.1-py3-none-any.whl (53.1 kB view details)

Uploaded Python 3

ptpy-0.3.1-py2-none-any.whl (53.1 kB view details)

Uploaded Python 2

File details

Details for the file ptpy-0.3.1.tar.gz.

File metadata

  • Download URL: ptpy-0.3.1.tar.gz
  • Upload date:
  • Size: 42.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ptpy-0.3.1.tar.gz
Algorithm Hash digest
SHA256 a45e8aaf5d9dc5faa3e945d82e71042ce4fbe53c32e90efc315d3a52df57bdba
MD5 207e4b459b2b804bc497b5bc91be9886
BLAKE2b-256 a5fb636da0461ff637a5e4928c35a1233e8c76c642e8efd11b4d965190f2199c

See more details on using hashes here.

File details

Details for the file ptpy-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: ptpy-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 53.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ptpy-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5e5198bf661a9383943b759be9a73a8b37c36263b8983c1ee472a612c63dd746
MD5 58aeabb8478b436bd1e1ec4a47ff0ca1
BLAKE2b-256 c0548842e4dc6543e20ff6471e469e7fa62e661031a70a1b33b0992fe7004c8a

See more details on using hashes here.

File details

Details for the file ptpy-0.3.1-py2-none-any.whl.

File metadata

  • Download URL: ptpy-0.3.1-py2-none-any.whl
  • Upload date:
  • Size: 53.1 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ptpy-0.3.1-py2-none-any.whl
Algorithm Hash digest
SHA256 138727a101304de553b063bb78372d929fbd5cf4e9efba7839103f049d306a87
MD5 2e5227fbfba6762306417fa82eaa624b
BLAKE2b-256 fb24ba4c2ff8e4b9499541cba620e133a5d1cd7c23e45c12128f5ce1f56d56ff

See more details on using hashes here.

Supported by

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