Python module for fast asynchronous work with JSON files
Project description
AsyncJ
AsyncJ - Python module for fast asynchronous work with JSON files
Examples
Get a dictionary from a JSON file
# Importing modules
import asyncio # To run the asynchronous main() function
from asyncj import AsyncJson # Main class used in the example
# Initialize the class with filename
asyncjson: AsyncJson = AsyncJson("test.json")
# The asynchronous main() function
async def main() -> None:
# Getting a dictionary
data: dict = await asyncjson.read()
# Displaying the resulting dictionary
print(data)
# Running the asynchronous main() function
if __name__ == "__main__":
asyncio.run(main())
Change dictionary in JSON file
# Importing modules
import asyncio # To run the asynchronous main() function
from asyncj import AsyncJson # Main class used in the example
from random import randint # To generate a random number
# Initialize the class with filename
asyncjson: AsyncJson = AsyncJson("test.json")
# The asynchronous main() function
async def main() -> None:
# Getting a dictionary
data: dict = await asyncjson.read()
# Getting a random number
random_number: int = randint(100, 999)
# Setting a new random value in the dictionary for the "test" key
data["test"] = random_number
# Writing the modified dictionary to a JSON file
await asyncjson.write(data)
# Running the asynchronous main() function
if __name__ == "__main__":
asyncio.run(main())
Requirements
Python version 3.8 or higher
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
asyncj-1.1.4.tar.gz
(3.2 kB
view details)
Built Distribution
File details
Details for the file asyncj-1.1.4.tar.gz
.
File metadata
- Download URL: asyncj-1.1.4.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc9f893b77de5a19b044986f24d8574cc71f1907ff6e5ed8ad61468f672250a2 |
|
MD5 | 0571fdb619c9d9a2288ecace42c308c7 |
|
BLAKE2b-256 | 77b350d5400e94641a61812393e4e9a9bfab4ee4e12bb36d49159b9953c8e685 |
File details
Details for the file asyncj-1.1.4-py3-none-any.whl
.
File metadata
- Download URL: asyncj-1.1.4-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d38d5812f51811a6ca15d94df74cfd36a9ffb94a2e53a39cec3640c995ea944 |
|
MD5 | 3a234034f621b8c8e7b50a4d59d9b0b7 |
|
BLAKE2b-256 | ae54781ef5a7a6259e6b95228fe06e2c78be5f334514b297cd06331efdb18d61 |