Skip to main content

Schema-agnostic JSON data store with dot notation, chainable queries, bulk operations, and built-in security features

Project description

Nitro DataStore

A flexible, schema-free data store for JSON in Python. Access nested data with dot notation, dictionary style, or path strings.

from nitro_datastore import NitroDataStore

data = NitroDataStore({'site': {'name': 'Nitro', 'url': 'https://nitro.sh'}})

data.site.name              # Dot notation
data['site']['name']        # Dictionary style
data.get('site.name')       # Path-based with defaults

No more config.get('site', {}).get('theme', {}).get('color', '#000'). Just config.get('site.theme.color', '#000').

Installation

pip install nitro-datastore

For AI coding assistants (Claude Code, etc.):

npx skills add nitrosh/nitro-datastore

Quick Start

Creating a DataStore

# From a dictionary
data = NitroDataStore({'title': 'Hello', 'settings': {'theme': 'dark'}})

# From a JSON file
data = NitroDataStore.from_file('config.json')

# From a directory (auto-merges all JSON files alphabetically)
data = NitroDataStore.from_directory('data/')

Reading & Writing

# Get with defaults
name = data.get('user.name', 'Anonymous')

# Set (creates intermediate dicts automatically)
data.set('config.cache.ttl', 3600)

# Check existence
if data.has('user.email'):
    email = data.get('user.email')

# Delete
data.delete('user.temp_token')

# Merge another datastore
data.merge(other_data)

Saving

data.save('output.json', indent=2)
plain_dict = data.to_dict()

Query Builder

Filter and transform collections with a chainable API:

data = NitroDataStore({
    'posts': [
        {'title': 'Python Tips', 'views': 150, 'published': True},
        {'title': 'Web Dev', 'views': 200, 'published': True},
        {'title': 'Draft', 'views': 0, 'published': False}
    ]
})

# Filter, sort, limit
results = (data.query('posts')
    .where(lambda p: p.get('published'))
    .sort(key=lambda p: p.get('views'), reverse=True)
    .limit(10)
    .execute())

# Utilities
count = data.query('posts').where(lambda p: p.get('published')).count()
titles = data.query('posts').pluck('title')
by_category = data.query('posts').group_by('category')
first = data.query('posts').first()

Path Discovery

Explore unknown data structures:

# List all paths
paths = data.list_paths()

# Glob patterns (* = single segment, ** = any depth)
titles = data.find_paths('posts.*.title')
urls = data.find_paths('**.url')

# Find all occurrences of a key
all_urls = data.find_all_keys('url')

# Find values by predicate
emails = data.find_values(lambda v: isinstance(v, str) and '@' in v)

Bulk Operations

# Update all matching values
count = data.update_where(
    condition=lambda path, value: 'http://' in str(value),
    transform=lambda value: value.replace('http://', 'https://')
)

# Clean up
data.remove_nulls()
data.remove_empty()

Transformations

Transformations return new instances (immutable):

# Transform all values
upper = data.transform_all(lambda path, v: v.upper() if isinstance(v, str) else v)

# Transform all keys (e.g., kebab-case to snake_case)
snake = data.transform_keys(lambda k: k.replace('-', '_'))

Comparison

data1.equals(data2)  # True/False

diff = old.diff(new)
# {'added': {...}, 'removed': {...}, 'changed': {...}}

Security

Built-in protections for file operations:

# Path traversal protection
data = NitroDataStore.from_file(user_path, base_dir='/safe/directory')

# File size limits
data = NitroDataStore.from_file(path, max_size=10*1024*1024)

Also includes: path validation, circular reference detection.

Common Gotchas

Issue Solution
Kebab-case keys (user-name) Use data['user-name'] instead of dot notation
Keys with dots (key.name) Use data['key.name'] - path methods treat dots as separators
Transform doesn't mutate Assign the result: data = data.transform_keys(...)

Examples

See the examples/ directory for comprehensive demos:

  • 01_basic_operations.py - Access patterns and CRUD
  • 02_file_operations.py - Load, save, directory merging
  • 03_querying.py - Query builder usage
  • 04_path_operations.py - Path discovery and patterns
  • 05_bulk_operations.py - Batch updates and cleanup
  • 06_data_introspection.py - describe(), stats(), flatten()
  • 07_comparison.py - diff() and equals()
  • 08_comprehensive_example.py - Real-world workflow
  • 09_security_features.py - Security protections

Ecosystem

License

MIT License. See LICENSE for details.

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

nitro_datastore-1.0.1.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

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

nitro_datastore-1.0.1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file nitro_datastore-1.0.1.tar.gz.

File metadata

  • Download URL: nitro_datastore-1.0.1.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nitro_datastore-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e6665dd6b57eae3e77bd79b14ca8adc207a4ad039642ba562680cdb1f4c8e56b
MD5 2d3128c10d1bf47efb35bab5a46764ea
BLAKE2b-256 8fe527d947ae487d20cbcacfe2abf02e9d1955daefb444a5d72a6702fe891117

See more details on using hashes here.

File details

Details for the file nitro_datastore-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for nitro_datastore-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4134b15a4c097651642f9fb573fc55f7e6981d3f6a8b5334f7437f21479ad5ca
MD5 109b44e8dd758e9bdc370dacb21da5cd
BLAKE2b-256 9bf8c77037ab2775be82339ecd98eb0c3ecbe709862c1d9ed033e55398d96a17

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