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.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

asyncj-1.1.0-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file asyncj-1.1.0.tar.gz.

File metadata

  • Download URL: asyncj-1.1.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for asyncj-1.1.0.tar.gz
Algorithm Hash digest
SHA256 f1098c0fbf8f83695d003404f4795658cbc6049040ed64510496def2c749fc84
MD5 eea1fe1a050e6776a38c4333edbcb430
BLAKE2b-256 7659aae46f571fbd26be6c29cc44313969b56c5c257c389b89ae2cce2dedd3f6

See more details on using hashes here.

File details

Details for the file asyncj-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: asyncj-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for asyncj-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95039fe8733bcd1d7bc7e042a93e80d80cf549ddf70ff92713cee084e12955e9
MD5 a55080c30db447bd01c177a6c8d84853
BLAKE2b-256 edcbc296a806947844ec5cff8d38a7d708700b6b172a858998e08bb5f94acfdc

See more details on using hashes here.

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