Skip to main content
# 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

Release files for ptpy 0.3.2

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

Source distribution (sdist)

Source distribution for ptpy 0.3.2
File Size Uploaded
ptpy-0.3.2.tar.gz 43.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for ptpy 0.3.2
File Interpreter ABI Platform
ptpy-0.3.2-py3-none-any.whl Python 3 none any Details
ptpy-0.3.2-py2-none-any.whl Python 2 none any Details

Total release size: 149.7 kB

Release files / ptpy-0.3.2.tar.gz

Download URL ptpy-0.3.2.tar.gz
Size 43.5 kB
Tags Source
SHA-256 checksum
How to use checksums
aeee7908406b19bdb6a8cdb53446a94c18d5cd77de92498c4db3507ee63cd8ac
BLAKE2b-256 checksum
How to use checksums
e414a026f9583d7dcfaba2b675cbe8c5c3bc4066082108b8ae9da01ca5129cd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / ptpy-0.3.2-py3-none-any.whl

Download URL ptpy-0.3.2-py3-none-any.whl
Size 53.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31028383361654448f1d5460ecaa9d2f38340984a1e78bb3d551daed77f69810
BLAKE2b-256 checksum
How to use checksums
a0949db88cbea56babbd67772db09bda0334d2ee610e556b87a9140ca93451d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / ptpy-0.3.2-py2-none-any.whl

Download URL ptpy-0.3.2-py2-none-any.whl
Size 53.1 kB
Tags Python 2
SHA-256 checksum
How to use checksums
a90bc3744d5a55967659984194990ad20a24f8a0892be5ddbc458b7389615a8f
BLAKE2b-256 checksum
How to use checksums
29573bc3435471a3e4777984bc69c71a2c0b30ffb483765535a504db194ad428
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.3.2 This release

3 release files

0.3.1

3 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

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