Skip to main content

Asynchronous json library with support of nested awaitable objects in data

Project description

asyncjson

Asynchronous json library with support of nested awaitable objects in data.

The most important features are supporting async functions and async generators on any level of data structure, even for dict keys.

Now the library contains async version of json.dumps function. This library was made to help stream the heavy json structures without blocking the event loop.

Be aware, this is alpha version of library.

Installing

pip install asyncjson

Example

import sys
import asyncio
import random
import string
import asyncjson

async def random_number():
    await asyncio.sleep(random.random())
    return random.randrange(0, 100)

async def random_strings():
    for i in range(random.randint(0, 10)):
        await asyncio.sleep(random.random())
        yield ''.join(random.choice(string.ascii_letters) for _ in range(random.randint(1, 10)))

async def run():
    obj = {
        'dictkey': {
            'list': [1, '2', 3.0],
            'random strings': random_strings(),
            'random number': random_number(),
            random_strings(): "joined random strings in key",
            random_number(): "random number in key"
        },
        'another random number': random_number(),
        'awaitable objects in list': ["sample", random_number(), random_strings(), [], {}],
        'intkey': 123,
        'stringkey': "qwer",
    }
    async for i in await asyncjson.dumpgen(obj):
        sys.stdout.write(i)
        sys.stdout.flush()

loop = asyncio.get_event_loop()
loop.run_until_complete(run())

Will give the result which will appear piece by piece because of sleeps added for demonstration purposes:

{
 "dictkey": {
  "list": [
   1, 
   "2", 
   3.0
  ], 
  "random strings": [
   "IuaNSw"
  ], 
  "random number": 65, 
  "ZuuBZyEMYTtqyOzYoILOZXCgnTYYsu": "joined random strings in key", 
  43: "random number in key"
 }, 
 "another random number": 85, 
 "awaitable objects in list": [
  "sample", 
  16, 
  [
   "wQ", 
   "Jp", 
   "xDfTNZCUv"
  ], 
  [], 
  {}
 ], 
 "intkey": 123, 
 "stringkey": "qwer"
}

To be done

  • Implement async versions of dump, loads, load functions
  • Implement async encoder/decoder on C in order to increase performance

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

asyncjson-0.0.1.tar.gz (12.4 kB view details)

Uploaded Source

File details

Details for the file asyncjson-0.0.1.tar.gz.

File metadata

  • Download URL: asyncjson-0.0.1.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.10

File hashes

Hashes for asyncjson-0.0.1.tar.gz
Algorithm Hash digest
SHA256 097772d34d0c43e6f30733a8e1491df9b664b45b59b7909e9d92bbe7170f2cff
MD5 fc4bac711fe11117e1b64b9a5bfad6f5
BLAKE2b-256 bb378663188da195edde799ef05fe0ab9b00b7d2be03ec20530b74fb8d717e08

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