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

Uploaded Source

Built Distribution

asyncj-1.1.1-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: asyncj-1.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 e5a724c03164f0b8f1c704c4045ea62ebfbdf1ac05ad1cedcb815def64e51f9d
MD5 ddc8b7aef2283f52af86302055f74386
BLAKE2b-256 bafe97264a890b6ee8998b76b1633f6a41f57d3912a3e338ddf7fd4c2e39eed5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asyncj-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 654071fdb9a23c309a83856a0366921d4f90d96bdc8706befa5a0d5c74439a6c
MD5 1e43a165471d398283db65f223e4a167
BLAKE2b-256 2f86892eda54521c091f16cecd7fcd24831c4f01aa67965647b16e9292554a32

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