Skip to main content

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 hashes)

Uploaded Source

Built Distribution

asyncj-1.1.4-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page