Skip to main content

Nitro DataStore

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

PyPI PyPI - Python Version PyPI - License image

Installation

pip install nitro-datastore

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

npx skills add nitrosh/nitro-datastore

Quick Start

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').

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
data.posts isn't a list Dot and [] access return a live NitroList view, so data.posts.append(...) updates the store. Use data.posts.to_list() for a plain copy, e.g. before json.dumps
Keys named like methods (items, keys, get, query, ...) data.items returns the method, not your data. Use data['items'] or data.get('items')
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.

Metadata

Release files for nitro-datastore 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nitro-datastore 1.1.0
File Size Uploaded
nitro_datastore-1.1.0.tar.gz 38.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nitro-datastore 1.1.0
File Interpreter ABI Platform
nitro_datastore-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 57.0 kB

Release files / nitro_datastore-1.1.0.tar.gz

Download URL nitro_datastore-1.1.0.tar.gz
Size 38.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2735c04f8f7e9bc656fd52e776e03afcc04e09002d85d42c59b7592ba8f9dda2
BLAKE2b-256 checksum
How to use checksums
608a2d2cc71bf4ebbef33c0ad12cc3f6c92d4f2776913979a252960dacbd9ca5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / nitro_datastore-1.1.0-py3-none-any.whl

Download URL nitro_datastore-1.1.0-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bff2f6b01b9c647de2fce7c97bdcc6ebcf94b1659520e51a874e3dfa47dc6a16
BLAKE2b-256 checksum
How to use checksums
4191999cde32c7116f352aab8320e9dbc0ff6c0e606b89aecf057d313322d3b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page