Skip to main content

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.

Metadata

Release files for masscode-py 1.0.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 masscode-py 1.0.0
File Size Uploaded
masscode_py-1.0.0.tar.gz 12.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for masscode-py 1.0.0
File Interpreter ABI Platform
masscode_py-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.8 kB

Release files / masscode_py-1.0.0.tar.gz

Download URL masscode_py-1.0.0.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
812d1a63db5618a2d6c56cabe3f43d2d0fcf9c93f27512ac004b4915f15e8eb0
BLAKE2b-256 checksum
How to use checksums
41bfe5b0cde5d371add7e055dffbcd92af9317b16d98324fa92b7c10cb18a0f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 1, 2025.

Transparency log

Release files / masscode_py-1.0.0-py3-none-any.whl

Download URL masscode_py-1.0.0-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fbf2b09cc426a2a2828307e4f6bf2e93ec09da3d29d64fac555e6abd4ed47b76
BLAKE2b-256 checksum
How to use checksums
6c0a06e8f6b2093ccc50ef51b1c06a8e3ea25106ac2a623ac6a507335df56f9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 1, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.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