Skip to main content

python wrapper for masscode

Project description

masscode.py

A Python wrapper for massCode - a free and open source code snippets manager for developers.

Install

pip install masscode-py

Features

  • Full API client for massCode
  • Direct file access to massCode database
  • Rich query capabilities with Python expressions
  • Command-line interface (CLI) for quick access
  • Type-safe models with TypedDict
  • Automatic file watching and reloading

Usage

API Client

from masscode import MasscodeApi

# Initialize API client
api = MasscodeApi()
api.start_masscode()  # Start massCode if not running

# Create a new snippet
snippet = api.create_snippet(
    name="Hello World",
    content=[{"label": "Python", "language": "python", "value": "print('Hello World')"}]
)

# Query snippets
snippets = api.query_snippet(
    name="*hello*",
    isFavorites=True,
    query='(x["name"].startswith("py") and len(x["content"]) > 1)'
)

File Access

from masscode import MasscodeDBFile

# Initialize file client
db = MasscodeDBFile("path/to/db.json")

# Access database
folders = db.folders
snippets = db.snippets
tags = db.tags

CLI Commands

The CLI provides easy access to massCode functionality from the command line:

# List all snippets
masscode snippets

# List all folders
masscode folders

# List all tags
masscode tags

# Query commands
masscode query tag --name "python" --query '(x["name"].startswith("py"))'
masscode query folder --name "*py*" --is-open
masscode query snippet --folder "python" --tags "web" "api"

Query Options

Tag Query
  • --name/-n: Tag name (supports wildcards)
  • --query/-q: Python expression to evaluate
  • --created-at/-c: Creation timestamp
  • --updated-at/-u: Update timestamp
Folder Query
  • --name/-n: Folder name (supports wildcards)
  • --default-language/-l: Default language
  • --parent/-p: Parent folder name or ID
  • --is-open/-o: Is folder open flag
  • --is-system/-s: Is system folder flag
  • --created-at/-c: Creation timestamp
  • --updated-at/-u: Update timestamp
  • --query/-q: Python expression to evaluate
Snippet Query
  • --name/-n: Snippet name (supports wildcards)
  • --folder/-f: Folder name or ID
  • --is-deleted/-d: Is deleted flag
  • --is-favorites/-v: Is favorites flag
  • --tags/-t: Tag names or IDs (can be specified multiple times)
  • --created-at/-C: Creation timestamp
  • --updated-at/-u: Update timestamp
  • --query/-q: Python expression to evaluate

Query Expressions

Query expressions are Python expressions that get evaluated on the object (x) with access to all its fields. This allows for complex filtering:

# Find folders with Python in name and are open
masscode query folder -q '(x["name"].startswith("py") and x["isOpen"])'

# Find snippets with multiple content fragments
masscode query snippet -q '(len(x["content"]) > 1 and any(c["language"] == "python" for c in x["content"]))'

# Find tags created in the last hour
masscode query tag -q '(time.time() - x["createdAt"]/1000 < 3600)'

Development

Project Structure

masscode/
├── core/
│   ├── api.py      # API client implementation
│   ├── i.py        # Interface definitions
│   └── discovery.py # massCode discovery utilities
├── model/
│   ├── db.py       # Database models
│   └── query.py    # Query models
├── utils/
│   ├── prop.py     # Property utilities
│   └── proc.py     # Process utilities
└── cli.py          # Command-line interface

Memory Bank

The project maintains a memory bank for documentation and context:

  • projectbrief.md: Core requirements and goals
  • productContext.md: Project purpose and user experience
  • systemPatterns.md: Architecture and design patterns
  • techContext.md: Technical details and dependencies
  • activeContext.md: Current work focus and decisions
  • progress.md: Project status and evolution

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file 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

masscode_py-1.0.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

masscode_py-1.0.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file masscode_py-1.0.0.tar.gz.

File metadata

  • Download URL: masscode_py-1.0.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for masscode_py-1.0.0.tar.gz
Algorithm Hash digest
SHA256 812d1a63db5618a2d6c56cabe3f43d2d0fcf9c93f27512ac004b4915f15e8eb0
MD5 db13baa3ec84574e6ded75c09e4eafbd
BLAKE2b-256 41bfe5b0cde5d371add7e055dffbcd92af9317b16d98324fa92b7c10cb18a0f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for masscode_py-1.0.0.tar.gz:

Publisher: python-publish.yml on ZackaryW/masscode.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file masscode_py-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: masscode_py-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for masscode_py-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fbf2b09cc426a2a2828307e4f6bf2e93ec09da3d29d64fac555e6abd4ed47b76
MD5 b556b176cf0786f422baefb56748380d
BLAKE2b-256 6c0a06e8f6b2093ccc50ef51b1c06a8e3ea25106ac2a623ac6a507335df56f9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for masscode_py-1.0.0-py3-none-any.whl:

Publisher: python-publish.yml on ZackaryW/masscode.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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