Skip to main content

Universal CLI tool for editing SVG, HTML, and XML files using XPath and CSS selectors

Project description

xqr

xpath xquery xqr

๐Ÿ› ๏ธ Universal File Editor

Powerful CLI tool for editing SVG, HTML, and XML files using XPath and CSS selectors. Edit your structured documents directly from the command line or through a web interface.

๐Ÿš€ Features

  • Multiple File Formats: SVG, HTML, XML support with automatic format detection
  • XPath Queries: Full XPath 1.0 support for precise element selection
  • CSS Selectors: CSS selector support for HTML files
  • Multiple Interfaces: CLI commands, interactive shell, and web server
  • REST API: Programmatic access via HTTP endpoints
  • Batch Processing: Automate edits across multiple files
  • Backup System: Automatic backup creation before modifications

๐Ÿ“ฆ Installation

Using Poetry (Recommended)

# Clone the repository
git clone https://github.com/yourusername/universal-file-editor.git
cd universal-file-editor

# Install with Poetry
poetry install

# Activate the environment
poetry shell

Using pip

pip install universal-file-editor

๐ŸŽฏ Quick Start

1. Create Example Files

file-editor examples

2. Basic Usage

# Load and query a file
file-editor load example.svg
file-editor query "//text[@id='text1']"

# Update content
file-editor set "//text[@id='text1']" "New Content"
file-editor save

3. Interactive Shell

file-editor shell
๐Ÿ“ > load example.html
๐Ÿ“ > query //title
๐Ÿ“ > set //title "Updated Title"
๐Ÿ“ > save
๐Ÿ“ > exit

4. Web Interface

file-editor server --port 8080
# Open http://localhost:8080 in your browser

๐Ÿ“– Usage Examples

SVG Files

# Update text elements
file-editor set "//text[@id='title']" "New Chart Title"

# Change colors
file-editor set "//rect[@id='bar1']" "blue" --type attribute --attr fill

# Update metadata
file-editor set "//metadata/description" "Updated chart description"

HTML Files

# Update page title
file-editor set "//title" "New Page Title"

# Change meta description
file-editor set "//meta[@name='description']" "New description" --type attribute --attr content

# Update content by CSS selector (in shell mode)
query #main-heading
set #main-heading "Welcome to Our Site"

XML Data Files

# Update configuration values
file-editor set "//setting[@name='timeout']" "60" --type attribute --attr value

# Modify data records
file-editor set "//record[@id='1']/email" "newemail@example.com"

# Update metadata
file-editor set "//metadata/version" "2.0"

๐Ÿ”ง Advanced Features

Batch Processing

#!/bin/bash
# Update multiple files
for file in *.svg; do
    file-editor load "$file"
    file-editor set "//metadata/updated" "$(date)"
    file-editor save
done

REST API Usage

# Load file
curl -X POST http://localhost:8080/api/load \
  -H "Content-Type: application/json" \
  -d '{"file_path": "example.svg"}'

# Query elements
curl -X POST http://localhost:8080/api/query \
  -H "Content-Type: application/json" \
  -d '{"query": "//text[@id=\"title\"]", "type": "xpath"}'

# Update element
curl -X POST http://localhost:8080/api/update \
  -H "Content-Type: application/json" \
  -d '{"xpath": "//text[@id=\"title\"]", "type": "text", "value": "New Title"}'

XPath Examples

# Find elements by ID
//element[@id='myid']

# Find elements by attribute value
//rect[@fill='red']

# Find elements containing text
//text[contains(., 'Hello')]

# Find elements by position
//record[position()=1]

# Find elements with specific child
//record[email='john@example.com']

CSS Selector Examples (HTML only)

# By ID
#main-title

# By class
.navigation-item

# By attribute
input[type='text']

# Descendant selectors
div.content p

# Pseudo-selectors
li:first-child

๐Ÿ—๏ธ Project Structure

universal-file-editor/
โ”œโ”€โ”€ pyproject.toml          # Poetry configuration
โ”œโ”€โ”€ README.md              # This file
โ”œโ”€โ”€ file_editor/           # Main package
โ”‚   โ”œโ”€โ”€ __init__.py        # Package initialization
โ”‚   โ”œโ”€โ”€ core.py           # Core FileEditor class
โ”‚   โ”œโ”€โ”€ cli.py            # Command-line interface
โ”‚   โ”œโ”€โ”€ server.py         # HTTP server
โ”‚   โ””โ”€โ”€ examples.py       # Example file generator
โ””โ”€โ”€ tests/                # Test suite
    โ”œโ”€โ”€ __init__.py
    โ”œโ”€โ”€ test_core.py
    โ”œโ”€โ”€ test_cli.py
    โ””โ”€โ”€ test_server.py

๐Ÿงช Development

Setting up Development Environment

# Clone repository
git clone https://github.com/yourusername/universal-file-editor.git
cd universal-file-editor

# Install with development dependencies
poetry install

# Install pre-commit hooks
pre-commit install

# Run tests
poetry run pytest

# Run with coverage
poetry run pytest --cov=file_editor

# Format code
poetry run black file_editor/

# Type checking
poetry run mypy file_editor/

Running Tests

# Run all tests
poetry run pytest

# Run specific test file
poetry run pytest tests/test_core.py

# Run with verbose output
poetry run pytest -v

# Run with coverage report
poetry run pytest --cov=file_editor --cov-report=html

๐Ÿ“‹ Requirements

  • Python: 3.8+
  • lxml: For XPath support (automatically installed)
  • beautifulsoup4: For CSS selector support (automatically installed)

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite (poetry run pytest)
  6. Format your code (poetry run black file_editor/)
  7. Commit your changes (git commit -am 'Add amazing feature')
  8. Push to the branch (git push origin feature/amazing-feature)
  9. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ”— Links

๐ŸŒŸ Why Universal File Editor?

Traditional file editing requires specialized tools for each format:

  • SVG files โ†’ Inkscape, Adobe Illustrator
  • HTML files โ†’ Web browsers, text editors
  • XML files โ†’ XML editors, IDEs

Universal File Editor provides a single, consistent interface for all structured document formats, enabling:

  • Automation: Script repetitive edits across thousands of files
  • Integration: Embed in CI/CD pipelines and build processes
  • Consistency: Use the same XPath/CSS knowledge across all formats
  • Accessibility: No specialized software required - works anywhere Python runs

Perfect for developers, system administrators, and content managers who work with structured data files.

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

xqr-0.1.0.tar.gz (20.4 kB view details)

Uploaded Source

Built Distribution

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

xqr-0.1.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file xqr-0.1.0.tar.gz.

File metadata

  • Download URL: xqr-0.1.0.tar.gz
  • Upload date:
  • Size: 20.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.15.3-200.fc42.x86_64

File hashes

Hashes for xqr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 eb081c3c3a4c311c055498965d4c6630ba86032706399e2ca2c018011b2081b2
MD5 dcb3badbb604f31039c0242c04f208a0
BLAKE2b-256 931e2ed74695060bc577268d085b843f3223c2f0555b7f45dbf5c6ea21e58ceb

See more details on using hashes here.

File details

Details for the file xqr-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: xqr-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.12 Linux/6.15.3-200.fc42.x86_64

File hashes

Hashes for xqr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc980ee702e601dec07862c8e72f0781adb0a6de7d86dfde725b1f763cf845ae
MD5 21b2741d2be9e6b206d80f4e5e8d4927
BLAKE2b-256 e14f72b2abcc54673ceec7bbbc2e0f1e7ea1eeb153cd8d77ad60a111d89fa400

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