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

Uploaded Source

Built Distribution

asyncj-1.1.2-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: asyncj-1.1.2.tar.gz
  • Upload date:
  • Size: 3.0 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.2.tar.gz
Algorithm Hash digest
SHA256 53afe2984b1d23382219a9a7d75f2a25de86d19ef92471883908120bf5442c72
MD5 6f3484378b46bc667550a94276287666
BLAKE2b-256 da27d169fc01eab71d9eddf7ab7413611aa43d76fa20508157c5069b213b0829

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asyncj-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.9 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1fbfdb0cfe6a59e1b718e4f4d13656443818eac8a73a8c689039348d22ec876d
MD5 8c00d103555913b75e532ef16851d0bf
BLAKE2b-256 f4abd8daf3efc5d24410be974f76528acbe6815c3da85e1884c091add4e8aa23

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