diff --git a/.gitignore b/.gitignore index a031648..236cce2 100755 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ __pycache__/ -.idea \ No newline at end of file +.idea +.vscode + +build/ +dist/ +*.egg-info \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c4c8192 --- /dev/null +++ b/README.md @@ -0,0 +1,48 @@ +# etcd3_wrapper +A thin wrapper around Python module [etcd3](https://pypi.org/project/etcd3/) to make it a little easier to deal with etcd. + +**Warning: The API isn't fully stable and can changed significantly in future.** + +For Example, you want to get an entry from etcd. +You would write something like this + +```python +from etcd3_wrapper import Etcd3Wrapper + +client = Etcd3Wrapper() +entry = client.get("/planet/earth") + +if entry: + # It would print key and value of entry + # in bytes format b'....' + print(entry.key, entry.value) + +``` + +Output + +``` +b'/planet/earth' b'{"population": "7.53 Billion"}' +``` + +```python +# If you know that the value in etcd is in JSON +# format. You can do the following + +json_entry = client.get("/planet/earth", value_in_json=True) + +if json_entry: + # Now, entry.value is of type dict + print(entry.key, entry.value) + + # So, you can do this too + print(f"Earth population is {entry.value['population']}") + +``` + +Output + +``` +/planet/earth {"population": "7.53 Billion"} +Earth population is 7.53 Billion +``` \ No newline at end of file diff --git a/etcd3_wrapper/Pipfile b/etcd3_wrapper/Pipfile deleted file mode 100755 index 522136f..0000000 --- a/etcd3_wrapper/Pipfile +++ /dev/null @@ -1,12 +0,0 @@ -[[source]] -name = "pypi" -url = "https://pypi.org/simple" -verify_ssl = true - -[dev-packages] - -[packages] -etcd3 = "*" - -[requires] -python_version = "3.7" diff --git a/etcd3_wrapper/Pipfile.lock b/etcd3_wrapper/Pipfile.lock deleted file mode 100755 index 2262d2a..0000000 --- a/etcd3_wrapper/Pipfile.lock +++ /dev/null @@ -1,102 +0,0 @@ -{ - "_meta": { - "hash": { - "sha256": "9d949b208819a1194b22b3a4111eaff4c8d7903c8414f667edee92bcf707580c" - }, - "pipfile-spec": 6, - "requires": { - "python_version": "3.7" - }, - "sources": [ - { - "name": "pypi", - "url": "https://pypi.org/simple", - "verify_ssl": true - } - ] - }, - "default": { - "etcd3": { - "hashes": [ - "sha256:25a524b9f032c6631ff0097532907dea81243eaa63c3744510fd1598cc4e0e87" - ], - "index": "pypi", - "version": "==0.10.0" - }, - "grpcio": { - "hashes": [ - "sha256:0232add03144dd3cf9b660e2718244cb8e175370dca4d3855cb4e489a7811b53", - "sha256:0f20e6dcb1b8662cdca033bb97c0a8116a5343e3ebc7f71c5fe7f89039978350", - "sha256:10b07a623d33d4966f45c85d410bc6a79c5ac6341f06c3beda6c22be12cbfe07", - "sha256:10c0476d5a52d21f402fc073745dc43b87cc8e080a1f49bbff4e1059019310fb", - "sha256:289dae0b35c59d191c524e976dd0a6f8c995d2062e72621eb866ad0f4472a635", - "sha256:2be726f16142d358a0df1e81d583d6820ee561a7856a79cca2fbe49989308be7", - "sha256:4338d2a81f5b4ca022e085040b3cfce19419a5ce44aa7e6810ac1df05365bed7", - "sha256:4c535b46f20e66bee3097583231977e721acdfcb1671d1490c99b7be8902ce18", - "sha256:557154aef70a0e979700cc9528bc8b606b668084a29a0d57dbc4b06b078a2f1c", - "sha256:5bfdd7e6647498f979dc46583723c852d97b25afe995d55aa1c76a5f9816bc1f", - "sha256:87d8943ae7aa6ca5bbad732867d7f17d2550e4966a0c15b52088e8b579422e47", - "sha256:89d8719d8de4d137678f7caa979e1b0a6fd4026f8096ceef8c2d164bbabefaf2", - "sha256:9c3f4af989ce860710ac1864dc2e867dd87e6cee51a2368df1b253596868e52f", - "sha256:9da52c3c728883aee429bb7c315049f50b2139f680cd86bb1165418e4f93a982", - "sha256:9e9736659987beab42d18525ed10d21f80a1ba8389eac03425fbfd5684e6bbf0", - "sha256:9ebcbb1a054cab362d29d3be571d43d6b9b23302d9fc4b43e5327000da1680a9", - "sha256:a93e08636623e24c939851e2e0c0140b14f524b2980c9cdc4ea52b70a871c7e0", - "sha256:ac322d86d1a079e0a118d544443ee16f320af0062c191b4754c0c6ec2fc79310", - "sha256:b1fb101459868f52df6b61e7bb13375e50badf17a160e39fe1d51ae19e53f461", - "sha256:b39aac96cceac624a23d540473835086a3ffa77c91030189988c073488434493", - "sha256:b65507bc273c6dbf539175a786a344cc0ac78d50e5584f72c6599733f8a3301f", - "sha256:be5bb6e47417e537c884a2e2ff2e1a8b2c064a998fcfdfcc67528d4e63e7ebaf", - "sha256:c92de6a28a909c4f460dc1bbbcb50d676cf0b1f40224b222761f73fdd851b522", - "sha256:c9f5962eb7fa7607b20eb0e4f59ed35829bd600fc0eacb626a6db83229a3e445", - "sha256:d00bdf9c546ed6e649f785c55b05288e8b2dbb6bf2eb74b6c579fa0d591d35bd", - "sha256:da804b1dd8293bd9d61b1e6ea989c887ba042a808a4fbdd80001cfa059aafed2", - "sha256:ead6c5aa3e807345913649c3be395aaca2bbb2d225f18b8f31f37eab225508f6", - "sha256:eb4d81550ce6f826af4ec6e8d98be347fe96291d718bf115c3f254621ae8d98d", - "sha256:ef6a18ec8fd32ec81748fe720544ea2fb2d2dc50fd6d06739d5e2eb8f0626a1c", - "sha256:fad42835656e0b6d3b7ffc900598e776722e30f43b7234a48f2576ca30f31a47", - "sha256:fb98dbfee0d963b49ae5754554028cf62e6bd695f22de16d242ba9d2f0b7339b", - "sha256:fb9cd9bb8d26dc17c2dd715a46bca3a879ec8283879b164e85863110dc6e3b2a" - ], - "version": "==1.21.1" - }, - "protobuf": { - "hashes": [ - "sha256:03f43eac9d5b651f976e91cf46a25b75e5779d98f0f4114b0abfed83376d75f8", - "sha256:0c94b21e6de01362f91a86b372555d22a60b59708599ca9d5032ae9fdf8e3538", - "sha256:2d2a9f30f61f4063fadd7fb68a2510a6939b43c0d6ceeec5c4704f22225da28e", - "sha256:34a0b05fca061e4abb77dd180209f68d8637115ff319f51e28a6a9382d69853a", - "sha256:358710fd0db25372edcf1150fa691f48376a134a6c69ce29f38f185eea7699e6", - "sha256:41e47198b94c27ba05a08b4a95160656105745c462af574e4bcb0807164065c0", - "sha256:8c61cc8a76e9d381c665aecc5105fa0f1878cf7db8b5cd17202603bcb386d0fc", - "sha256:a6eebc4db759e58fdac02efcd3028b811effac881d8a5bad1996e4e8ee6acb47", - "sha256:a9c12f7c98093da0a46ba76ec40ace725daa1ac4038c41e4b1466afb5c45bb01", - "sha256:cb95068492ba0859b8c9e61fa8ba206a83c64e5d0916fb4543700b2e2b214115", - "sha256:cd98476ce7bb4dcd6a7b101f5eecdc073dafea19f311e36eb8fba1a349346277", - "sha256:ce64cfbea18c535176bdaa10ba740c0fc4c6d998a3f511c17bedb0ae4b3b167c", - "sha256:dcbb59eac73fd454e8f2c5fba9e3d3320fd4707ed6a9d3ea3717924a6f0903ea", - "sha256:dd67f34458ae716029e2a71ede998e9092493b62a519236ca52e3c5202096c87", - "sha256:e3c96056eb5b7284a20e256cb0bf783c8f36ad82a4ae5434a7b7cd02384144a7", - "sha256:f612d584d7a27e2f39e7b17878430a959c1bc09a74ba09db096b468558e5e126", - "sha256:f6de8a7d6122297b81566e5bd4df37fd5d62bec14f8f90ebff8ede1c9726cd0a", - "sha256:fa529d9261682b24c2aaa683667253175c9acebe0a31105394b221090da75832" - ], - "version": "==3.8.0" - }, - "six": { - "hashes": [ - "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", - "sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73" - ], - "version": "==1.12.0" - }, - "tenacity": { - "hashes": [ - "sha256:a0c3c5f7ae0c33f5556c775ca059c12d6fd8ab7121613a713e8b7d649908571b", - "sha256:b87c1934daa0b2ccc7db153c37b8bf91d12f165936ade8628e7b962b92dc7705" - ], - "version": "==5.0.4" - } - }, - "develop": {} -} diff --git a/etcd3_wrapper/__init__.py b/etcd3_wrapper/__init__.py index 594ca77..1b57050 100755 --- a/etcd3_wrapper/__init__.py +++ b/etcd3_wrapper/__init__.py @@ -1 +1,2 @@ -from .etcd_wrapper import * \ No newline at end of file +from .etcd3_wrapper import Etcd3Wrapper, EtcdEntry +name = "etcd3_wrapper" \ No newline at end of file diff --git a/etcd3_wrapper/etcd_wrapper.py b/etcd3_wrapper/etcd3_wrapper.py similarity index 98% rename from etcd3_wrapper/etcd_wrapper.py rename to etcd3_wrapper/etcd3_wrapper.py index 8559b34..cef57ba 100755 --- a/etcd3_wrapper/etcd_wrapper.py +++ b/etcd3_wrapper/etcd3_wrapper.py @@ -11,9 +11,11 @@ PseudoEtcdMeta = namedtuple("PseudoEtcdMeta", ["key"]) @dataclass(init=False) class EtcdEntry: + key: str + value: str + def __init__(self, meta, value, value_in_json=False): self.key = meta.key.decode("utf-8") - self.value = value.decode("utf-8") if value_in_json: @@ -22,11 +24,8 @@ class EtcdEntry: except json.JSONDecodeError as e: print(f"Json Error: {e}, value={value}") - key: str - value: str - -class Etcd3Wrapper(object): +class Etcd3Wrapper: def __init__(self, *args, **kwargs): self.client = etcd3.client(*args, **kwargs) diff --git a/setup.py b/setup.py index 50286bf..921d7fd 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,23 @@ -from setuptools import setup +import setuptools -setup( +with open('README.md') as fh: + long_description = fh.read() + +setuptools.setup( name='etcd3_wrapper', - version='1.0', - description='A wrapper for etcd3', + version='0.5', + description='A wrapper around etcd3 package', + long_description=long_description, + long_description_content_type='text/markdown', + url='https://code.ungleich.ch/ungleich-public/etcd3_wrapper', author='ungleich', - author_email='info@ungleich.ch', - packages=['etcd3_wrapper'] #same as name + author_email='hacking@ungleich.ch', + packages=setuptools.find_packages(), + install_requires=[ + 'etcd3', + ], + classifiers=[ + 'Programming Language :: Python :: 3', + ], + python_requires='>=3.6', )