NewSmile
Another Smile Format Decoder/Encoder for Python 3
Encoding
- Import SmileEncoder
from newsmile import SmileEncoder
- Create Encoder object, with arguments:
- raw_binary (bool), default = False: contains binary data
- shared_values (bool), default = False: maintains shared values buffer and references
- shared_keys (bool), default = True: maintains shared keys buffer and references
- float_precision (0|4|8), default = 0: float values precisions (0=auto)
- encoding (string), default = 'utf-8': encoding used for unicode values and keys
(Note: specs implies shared values are defaulted to False)
encoder = SmileEncoder(shared_values=True)
- Encode data
If data is a dictionnary, it is encoded as is. If data is a string, it is considered as a json string.
# Example with a dictionary
an_object = {'a': 123, 'b':[4, 5, 6], 'c':{'d': 'a_string', 'e':None}}
result = encoder.encode(an_object)
print(result)
>>> b':)\n\x03\xfa\x80a$\x03\xb6\x80b\xf8\xc8\xca\xcc\xf9\x80c\xfa\x80dGa_string\x80e!\xfb\xfb'
# Example with json
import json
an_object = {'a': 123, 'b':[4, 5, 6], 'c':{'d': 'a_string', 'e':None}}
result = encoder.encode(json.dumps(an_object))
print(result)
>>> b':)\n\x03\xfa\x80a$\x03\xb6\x80b\xf8\xc8\xca\xcc\xf9\x80c\xfa\x80dGa_string\x80e!\xfb\xfb'
Decoding
- Import SmileEncoder
from newsmile import SmileDecoder
- Create Decoder object, with arguments:
- encoding (string), default = 'utf-8': encoding used for unicode values and keys
decoder = SmileDecoder()
- Decode value
decoder.decode(result)
decoded_object = decoder.decode(result)
print(decoded_object)
>>> {'a': 123, 'b': [4, 5, 6], 'c': {'d': 'a_string', 'e': None}}
Encoding example, from file
import json
from newsmile import SmileEncoder
encoder = SmileEncoder(shared_values=True, encoding='iso-8859-1')
dico = {'a': 1, 'b': [2, 3, 4], 'c': {'subkey': 'a string'}}
smile_data = encoder.encode(json.dumps(dico))
Decoding example, from file
from newsmile import SmileDecoder
decoder = SmileDecoder()
with open('smile-data-file', 'rb') as smile_file:
data = decoder.decode(smile_file.read())
Running tests
cd tests
python test.py
Metadata
Release files for newsmile 1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| newsmile-1.1.tar.gz | 299.9 kB | Without provenance | Details for newsmile-1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| newsmile-1.1-py3-none-any.whl | Python 3 | none | any | Details for newsmile-1.1-py3-none-any.whl |
Total release size: 308.0 kB
Release files / newsmile-1.1.tar.gz
| Download URL | newsmile-1.1.tar.gz |
|---|---|
| Size | 299.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f4a1e5694caf1cfac9d0282ec27175474895eb2847b9e30f3a22a150d8635cf
|
|
BLAKE2b-256 checksum How to use checksums |
5d92144afef942290b37fda8e72cacb749998e4a98669dce901c8fdb51ebeed0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.8
|
Release files / newsmile-1.1-py3-none-any.whl
| Download URL | newsmile-1.1-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ea22483625a3471e2b9d47665acadf46c5becf428be6c2dfcd113130018fb8e
|
|
BLAKE2b-256 checksum How to use checksums |
888336ea5528c8475ab5b0a153f00257d232352b379798d20514f571acb189b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.8
|
Security for newsmile 1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.