Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: A new user-focused API #1086

Closed
bfirsh opened this issue Jun 8, 2016 · 3 comments
Closed

Proposal: A new user-focused API #1086

bfirsh opened this issue Jun 8, 2016 · 3 comments

Comments

@bfirsh
Copy link
Contributor

bfirsh commented Jun 8, 2016

Problem

The current API is a great wrapper around the REST API, but many common tasks that users want to do don't necessarily map directly to REST API calls. For example, simply running a container is a rather convoluted process.

Proposal

I am proposing we add a higher-level API focused on what users want to do. It should be the default, recommended way of using docker-py.

It could look something like this:

>>> import docker
>>> client = docker.from_env()

>>> client.containers.run("ubuntu", "echo hello world")
'hello world\n'

>>> client.containers.run("ubuntu", "tasks/reticulate-splines", detach=True)
<Container '45e6d2de7c54'>

>>> client.containers.list()
[<Container '45e6d2de7c54'>, <Container 'db18e4f20eaa'>, ...]

>>> container = client.containers.get('45e6d2de7c54')

>>> for line in container.logs(stream=True):
...   print line
Reticulating spline 2...
Reticulating spline 3...

See this sketch of a README for a more examples of how it could work. It intentionally starts with a common thing that users want to do which is complex with the current API: running containers.

Backwards compatibility

This is a good excuse for 2.0. ;)

The new API can be built on top of the current lower-level API. The current API can be made available to users in case they want that extra flexibility and to give them a seamless migration path (client.api.create_container(...) or something like that).

See also

@TomasTomecek
Copy link
Contributor

I agree that having the OO abstraction in docker-py would be great since that's what likely everyone is doing in their python projects using docker-py. (e.g. this is what I have in sen: common base class and object specific classes for container and image -- hence I would love to contribute some of the code back to this new API)

But please, make it backwards compatible. There's so many tools built on top of docker-py already. So I don't see why you would have to remove deprecate the already-used, stable and efficient low-level API.

@bfirsh
Copy link
Contributor Author

bfirsh commented Sep 4, 2016

A prototype here, if anyone's interested: https://github.com/bfirsh/docker-sdk-python

@bfirsh bfirsh mentioned this issue Sep 6, 2016
17 tasks
bfirsh added a commit to bfirsh/docker-py that referenced this issue Nov 8, 2016
See docker#1086

Signed-off-by: Ben Firshman <[email protected]>
bfirsh added a commit to bfirsh/docker-py that referenced this issue Nov 17, 2016
See docker#1086

Signed-off-by: Ben Firshman <[email protected]>
bfirsh added a commit to bfirsh/docker-py that referenced this issue Nov 17, 2016
See docker#1086

Signed-off-by: Ben Firshman <[email protected]>
bfirsh added a commit to bfirsh/docker-py that referenced this issue Nov 18, 2016
See docker#1086

Signed-off-by: Ben Firshman <[email protected]>
bfirsh added a commit to bfirsh/docker-py that referenced this issue Nov 18, 2016
See docker#1086

Signed-off-by: Ben Firshman <[email protected]>
bfirsh added a commit to bfirsh/docker-py that referenced this issue Nov 18, 2016
See docker#1086

Signed-off-by: Ben Firshman <[email protected]>
bfirsh added a commit to bfirsh/docker-py that referenced this issue Nov 22, 2016
See docker#1086

Signed-off-by: Ben Firshman <[email protected]>
@bfirsh
Copy link
Contributor Author

bfirsh commented Nov 28, 2016

Implemented in #1186!

@bfirsh bfirsh closed this as completed Nov 28, 2016
shin- pushed a commit that referenced this issue Dec 8, 2016
See #1086

Signed-off-by: Ben Firshman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants