What is the API to get all the keys (not values) in etcd3?

See original GitHub issue

The get_all() API returns the values of all the keys, but not the keys themselves.

After putting the following keys and values, what is the API to get a list of just the keys /foo, /bar, /baz and /qux?

>>> etcd.put("/foo", "a")
>>> etcd.put("/bar", "b")
>>> etcd.put("/baz", "c")
>>> etcd.put("/qux", "d")

I was not able to find this in the documentation in https://python-etcd3.readthedocs.io/en/latest/usage.html.

It is possible to get just the keys in etcd3 using etcdctl the following way:

ETCDCTL_API=3 etcdctl get --prefix=true "" | grep '/'
/bar
/baz
/foo
/qux

But, I wasn’t able to find the python API to do the above. Let me know if I’m missing anything.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
kragnizcommented, Mar 12, 2018

There isn’t a method to do this, but you can get all and extract only the keys:

>>> c = etcd3.client()
>>> [m.key for (_, m) in c.get_all()]
[b'/bar', b'/baz', b'/foo', b'/qux'] 
0reactions
vhosakotcommented, Mar 12, 2018

Thanks @kragniz, that works!

>>> etcd.put("/foo", "a")
>>> etcd.put("/bar", "b")
>>> etcd.put("/baz", "c")
>>> etcd.put("/qux", "d")

>>> [m.key for (_, m) in etcd.get_all()]
['/bar', '/baz', '/foo', '/qux']

>>> for (_,m) in etcd.get_all():
...     print m.key
... 
/bar
/baz
/foo
/qux
Read more comments on GitHub >

github_iconTop Results From Across the Web

etcd3 API | etcd
All Responses from etcd API have an attached response header which includes cluster ... Keys_Only - return only the keys and not the...
Read more >
API Usage — python-etcd3 0.8.1 documentation
Get all keys currently stored in etcd. Returns: sequence of (value, metadata) tuples. put (key, ...
Read more >
In etcd v3.0.x, how do I request all keys with a given prefix?
If the range_end is one bit larger than the given key, then the range requests get the all keys with the prefix (the...
Read more >
Using etcd3 Features - Compose Help
If you are running etcd3 on your deployment, you can only use v3 of the API. The v2 API is not supported. Prefixes....
Read more >
etcd3 API
etcd3 API. NOTE: this doc is not finished! Response header. All Responses from etcd API have a response header attached. The response header...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found