Skip to main content

A package to detect if text is likely code

Project description

Code Detector

A Python package to detect if text is likely code.

Installation

You can install the package via pip:

pip install code-detector

Usage

from code_detector import is_code

# Check if a string is likely code
text = "for i in range(10): print(i)"
result = is_code(text)  # Returns True

# Check if a string is not code
text = "This is just regular text explaining something."
result = is_code(text)  # Returns False

# Process multiple texts in batch
from code_detector.utils import batch_process
texts = [
    "for i in range(10): print(i)",
    "This is just regular text.",
    "npm install react --save"
]
results = batch_process(texts)  # Returns [True, False, True]

# Get statistics for a corpus
from code_detector.utils import get_statistics
stats = get_statistics(texts)
# Returns: {'total': 3, 'code_count': 2, 'non_code_count': 1, 'code_percentage': 66.66...}

Features

  • Detects various programming languages and code patterns
  • Recognizes command line instructions
  • Distinguishes between code and natural language descriptions of code
  • Handles code within backticks
  • Detects package manager commands
  • Recognizes specialized patterns for R, CSS, and other languages
  • Works with both simple and complex code examples

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

code_detector-0.1.0-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: code_detector-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for code_detector-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da399ebd9cabf9f8632cb75e649b9a839ac77efcb4102285d79289941e47fd1a
MD5 15e5b9fdae8b7c3bc4100531eb7966b2
BLAKE2b-256 c59c6c7d1dd1f7903a9ff53b46b065ae3e97422817cf07b34f57af6ff2782905

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