Skip to main content

Minimal reimplementation of json-stream for CircuitPython

Project description

Introduction

Documentation Status Discord Build Status Code Style: Ruff

This library is a reimplementation and subset of json_stream. It enables reading JSON data from a stream rather that loading it all into memory at once. The interface works like lists and dictionaries that are usually returned from json.load() but require in-order access. Out of order accesses will lead to missing keys and list entries.

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle or individual libraries can be installed using circup.

Installing from PyPI

This library is on PyPI for editors that use it for CircuitPython. In CPython, it is recommended to use json_stream itself.

Installing to a Connected CircuitPython Device with Circup

Make sure that you have circup installed in your Python environment. Install it with the following command if necessary:

pip3 install circup

With circup installed and your CircuitPython device connected use the following command to install:

circup install adafruit_json_stream

Or the following command to update an existing version:

circup update

Usage Example

import ssl
import time
import adafruit_requests
import socketpool
import wifi
import adafruit_json_stream as json_stream

pool = socketpool.SocketPool(wifi.radio)
session = adafruit_requests.Session(pool, ssl.create_default_context())

SCORE_URL = "http://site.api.espn.com/apis/site/v2/sports/baseball/mlb/scoreboard"

while True:
    resp = session.get(SCORE_URL)
    json_data = json_stream.load(resp.iter_content(32))
    for event in json_data["events"]:
        if "Seattle" not in event["name"]:
            continue
        for competition in event["competitions"]:
            for competitor in competition["competitors"]:
                print(competitor["team"]["displayName"], competitor["score"])
    resp.close()
    time.sleep(60)

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

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

adafruit_circuitpython_json_stream-0.9.4.tar.gz (34.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file adafruit_circuitpython_json_stream-0.9.4.tar.gz.

File metadata

File hashes

Hashes for adafruit_circuitpython_json_stream-0.9.4.tar.gz
Algorithm Hash digest
SHA256 9b4a0091141c1630ddb131f9faeb9fd863628cc649deab2a8cb26cec8f316c49
MD5 5b44a26938cdaa1970e16e30233f3641
BLAKE2b-256 1ec5e370e35dd1bf46940ada862718f3df2dfa1bfc1247774420ddaa2049885d

See more details on using hashes here.

File details

Details for the file adafruit_circuitpython_json_stream-0.9.4-py3-none-any.whl.

File metadata

File hashes

Hashes for adafruit_circuitpython_json_stream-0.9.4-py3-none-any.whl
Algorithm Hash digest
SHA256 970368919004381ac89454856828ac31e72fe0ef486fc7e139aa491d7099884d
MD5 8352f6b7caca5f2b174d7f2574cf9934
BLAKE2b-256 becafb814e19fca0606984dc112a77c0e985438a18ee4ad44e6d75887b987802

See more details on using hashes here.

Supported by

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