protonbites 🧪 EXPR1
Most sane way to store JSON data. Simple, light, strongly-typed and secure. (Probably, overall)
Step 1. Create a dataclass.
from dataclasses import dataclass
@dataclass
class Person:
name: str
age: int
For floats and ints, you can use
typing.Annotated[int, '<dtype>']where<dtype>is the desired datatype. Below are the avilable dtypes:ints
- int8 / uint8
- int16 / uint16
- int32 / uint32
- int64 / uint64
floats
- float32
- float64
Step 2. Create a schema from the dataclass.
from protonbites import get_schema
schema = get_schema(Person)
Step 3. Use the schema to encode/decode data.
# Init a new dataclass
person = Person(name="Jesse Pinkman", age=28)
encoded = schema.encode(person)
decoded = schema.decode(encoded)
assert isinstance(decoded, Person)
API Documentation incomplete
Oopsy daisy.
def encode
def encode(
obj: PythonBackendDataTypes,
/,
*,
force_keep_str: bool = False
) -> bytes
Encode data to a proton.
Args:
- obj (
PythonBackendDataTypes): Object. - force_keep_str (
bool): Force keep the string? Usually, when the expected text length is more than 102 characters, we usegzipto compress the text data. If you wish to keep the string, set this toTrue.
Simple Example:
encode({
"name": "Mr. Penguin",
"tags": ["depressed"],
"friends": [
{
"name": "Fernando Miguel",
"tags": ["dancing", "noot"]
}
]
})
# => b"\x01\x0f'Mr. Penguin'\x11\x03\x0f'depressed'\x11\x04\x11\x03\x01\x0f'Fernando Miguel'\x11\x03\x0f'dancing'\x11\x0f'noot'\x11\x04\x11\x02\x11\x04\x11\x02"
encode({ "text": "what the fish " * 9_999 })
# => b'\x01\x0f1f8b0800a6ed516602ffe…bf2c1f2a24c7aad4220200\x11\x02'
Example using custom ints and floats:
from protonbites import uint8, float32
encode({
"a": uint8(10),
"b": float32(10.98535)
})
def decode
def decode(__c: bytes, /) -> PythonBackendTypes
Decode the data.
Args:
- __c: The encoded data.
Example:
a = decode(b"\x01…\x02")
# => [ …, …, … ]
reveal_type(a) # PythonBackendDataTypes (type_checking)
# To ensure the decoded data is the entrypoint
b = decoded_safely(a)
reveal_type(b) # list (type_checking)
def get_schema
get_schema(__dc: type[T], /) -> Schema[T]
where T: DataclassProtocol
Args:
- __dc: The dataclass.
@dataclass
class Person:
name: str
age: int
schema = get_schema()
schema.encode(Person(name="Jesse Pinkman", age=28))
Were you looking for Mr. Penguin?
I'm standing in a void. No light. No sound. And as I stand there... In front of me, a penguin manifests. He merely stands. Observing. But I. I am filled with dread. I dare think it, but not say it. Are you the embodiment of my end? His gaze, so vacant, pierces my very soul. Then, from the all-encompassing abyss itself, the noots of a hundred penguins billow out. The noots coalesce, forming bodies. But from those bodies, arise not life, but... flames. Their joyful noots mutate into agonized screams. Suddenly, they're engulfed by the void. Yet, the most haunting realization? In their fleeting, fiery visages, I glimpse my own reflection.
(c) 2024 AWeirdDev
Metadata
Release files for protonbites 0.2
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 | |
|---|---|---|---|---|
| protonbites-0.2.tar.gz | 6.8 kB | Without provenance | Details |
Release files / protonbites-0.2.tar.gz
| Download URL | protonbites-0.2.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a2a66810c0e1c03fd2bc50f2fa05e1e48fe561a3da15ffb10cb0eb0cdd0c00e1
|
|
BLAKE2b-256 checksum How to use checksums |
9a0888143ce85c6b51d2376acd8f7d90f14b0080e53879102b8e5f8cec0843e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for protonbites 0.2
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.