cryptodweet#
A python module for very basic APIs of the free dweet service with encryption.
Dweet is a simple machine-to-machine (M2M) service from https://dweet.io/ . The free service is public and any data is accessible by anyone. This package adds encryption to it and make it a bit more secure. Only the minimal APIs are supported.
Installation#
pip install cryptodweet
Usage#
>>> from cryptodweet import CryptoDweet
>>> cd = CryptoDweet("YOUR KEY")
>>> cd.dweet_for("YOUR THING", {"YOUR DATA": "YOUR VALUE"})
{'thing': '9ee9b47833d5a13043c5f47e8802596a', 'created': '2022-08-30T05:40:44.885Z',
'content': {'8c94428bc640de621c7c3ceea1d00b96': '05d6f2dbc1ce3afa7e6072c0c4c6f6a7'},
'transaction': '5786ee01-ef5c-4bd1-9734-ed9334180600'}
>>> cd.get_latest_dweet_for("YOUR THING")
[{'thing': 'YOUR THING', 'created': '2022-08-30T05:40:44.885Z',
'content': {'YOUR DATA': 'YOUR VALUE'}}]
API Reference#
A python module for very basic APIs of the free dweet service with encryption.
- Author: Quan Lin
- License: MIT
CryptoDweet(aes_cbc_key=b'aes_cbc_key', aes_cbc_iv=None, base_url=BASE_URL)
#
A class for the free dweet service with encryption.
Initialization options:
CryptoDweet()
: With default key and iv, not secure.CryptoDweet("YOUR KEY")
: Only set key, and iv is the same as key.CryptoDweet("YOUR KEY", "YOUR IV")
: Set both key and iv, strongest encryption.
The given key is padded with space to 16 bytes (if shorter than 16 bytes) or padded with space to 32 bytes (if length is between 16 and 32) or truncated to 32 bytes (if longer than 32 bytes). The given iv is padded with space or truncated to 16 bytes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
aes_cbc_key |
bytes
|
The key of AES CBC mode. |
b'aes_cbc_key'
|
aes_cbc_iv |
bytes
|
The IV of AES CBC mode. |
None
|
base_url |
str
|
The base url of the dweet server. |
BASE_URL
|
dweet_for(thing, content_dict)
#
The 'dweet for' API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
thing |
str
|
The thing name. |
required |
content_dict |
dict
|
The content dict. |
required |
Returns:
Type | Description |
---|---|
dict
|
The result dict of 'dweet for' API. |
get_dweets_for(thing)
#
The 'get dweets for' API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
thing |
str
|
The thing name. |
required |
Returns:
Type | Description |
---|---|
list
|
The result list of dict of 'get dweets for' API. |
get_latest_dweet_for(thing)
#
The 'get latest dweet for' API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
thing |
str
|
The thing name. |
required |
Returns:
Type | Description |
---|---|
list
|
The result list of dict of 'get latest dweet for' API. |
from_bytes(msg)
#
Convert to str
with utf_8
codec.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg |
bytes
|
The message bytes to convert. |
required |
Returns:
Type | Description |
---|---|
str
|
Message string with |
to_bytes(msg)
#
Convert to bytes
with utf_8
codec.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg |
str
|
The message to convert. |
required |
Returns:
Type | Description |
---|---|
bytes
|
Message bytes with |