Skip to main content

SBSV: Square Brackets Separated Values

Project description

SBSV: square bracket separated values

A flexible, schema-based structured log data format.

Install

python3 -m pip install sbsv

Use

You can read this log-like data:

[meta-data] [id 1] [format string]
[meta-data] [id 2] [format token]
[data] [string] [id 1] [actual some long string...]
[data] [token] [id 2] [actual [some] [multiple] [tokens]]
[stat] [rows 2]
import sbsv

parser = sbsv.parser()
parser.add_schema("[meta-data] [id: int] [format: str]")
parser.add_schema("[data] [string] [id: int] [actual: str]")
parser.add_schema("[data] [token] [id: int] [actual: list[str]]")
parser.add_schema("[stat] [rows: int]")
with open("testfile.svsb", "r") as f:
  result = parser.load(f)

Result would looks like:

{
  "meta-data": [{"id": 1, "format": "string"}, {"id": 2, "format": "string"}],
  "data": {
    "string": [{"id": 1, "actual": "some long string..."}],
    "token": [{"id": 2, "actual": ["some", "multiple", "tokens"]}]
  },
  "stat": [{"rows": 2}]
}

Details

Basic schema

Schema is consisted with schema name, variable name and type annotation.

[schema-name] [var-name: type]

You can use [A-Za-z0-9-_] for names.

Sub schema

[my-schema] [sub-schema] [some: int] [other: str] [data: bool]

You can add any sub schema. But if you add sub schema, you cannot add new schema with same schema name without sub schema.

[my-schema] [no: int] [sub: str] [schema: str]
# this will cause error

Ignore

  • Not available yet
[2024-03-04 13:22:56] [DEBUG] [necessary] [from] [this part]

Regular log file may contain unnecessary data. You can specify parser to ignore [2024-03-04 13:22:56] [DEBUG] part.

parser.add_schema("[$ignore] [$ignore] [necessary] [from] [this: str]")

Duplicating names

  • Not available yet Sometimes, you may want to use same name multiple times.
[my-schema] [node 1] [node 2] [node 3]

You can distinguish them using index.

parser.add_schema("[my-schema] [node$0: int] [node$1: int] [node$2: int]")

Primitive types

Primitive types are str, int, float, bool, null.

Complex types

  • Not available yet

list

[data] [token] [id 2] [actual [some] [multiple] [tokens]]
parser.add_schema("[data] [token] [id: int] [actual: list[str]]")

obj

[car] [id 1] [data [speed 100] [power 2] [price 20000]]
parser.add_schema("[car] [id: int] [data: obj[speed: int, power: int, price: int]])

map

[map-example] [mymap [id: 1, name: alice, email: wd@email.com]]
parser.add_schema("[map-example] [mymap: map]")

nullable

[car] [id 1] [data [speed 100] [power 2] [price]]
[car] [id] [data [speed 120] [power 3] [price 33000]]
parser.add_schema("[car] [id?: int] [data: obj[speed: int, power: int, price?: int]]")

Contribute

python3 -m pip install --upgrade pip
python3 -m pip install black

You should run black linter before commit.

python3 -m black .

Before implementing new features or fixing bugs, add new tests in tests/.

python3 -m unittest

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

sbsv-0.0.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

sbsv-0.0.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file sbsv-0.0.2.tar.gz.

File metadata

  • Download URL: sbsv-0.0.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.13

File hashes

Hashes for sbsv-0.0.2.tar.gz
Algorithm Hash digest
SHA256 22321b71156282168471180bc1b31286fc5ff6208019d553c1b414a98d97f8e5
MD5 89a3e3154f717e871bea491a9281d433
BLAKE2b-256 2c2acd8563f83a5637788510ba5dde70aba976c9345818d8e51faeda013f2f79

See more details on using hashes here.

File details

Details for the file sbsv-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: sbsv-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.13

File hashes

Hashes for sbsv-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 220e050958e074bb227e40b7631c73233ac764ffedbe3407abead83898ac869e
MD5 9c9c2babb0be17db30c933b30326e9e9
BLAKE2b-256 613a229c4a02290317ba5e5ddce9f52f276087c73b1a824dcea2e99c15ff0d8d

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