# Code Language Detector — Identify Any Programming Language (`maged120/programming-language-detector`) Actor

Paste any code snippet and instantly identify its programming language. Returns the detected language with a confidence score — supports 50+ languages.

- **URL**: https://apify.com/maged120/programming-language-detector.md
- **Developed by:** [Maged](https://apify.com/maged120) (community)
- **Categories:** Automation, Developer tools, Other
- **Stats:** 44 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $10.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

### What does Code Language Detector do?

**Code Language Detector** identifies the programming language of any code snippet. Paste or input any code and get back the detected language with a confidence score — supporting 50+ popular programming languages.

This Actor runs on the [Apify platform](https://apify.com). Use it for code classification, dataset labeling, developer tools, or any workflow that needs to categorize code snippets programmatically.

### Why use Code Language Detector?

- **50+ languages** — Python, JavaScript, TypeScript, Go, Rust, Java, C++, Ruby, PHP, and more
- **Confidence scores** — know how certain the detection is
- **Batch processing** — classify hundreds of snippets in one run
- **API-ready** — integrate language detection into developer tools, IDEs, or code analysis pipelines
- **No setup** — no model downloads or infrastructure needed

### How to use Code Language Detector

1. Open the Actor and click **Try for free**
2. Enter code snippets in the `snippets` input field
3. Click **Start** — detected languages appear in the Output tab
4. Download results as JSON or connect via the Apify API

### Input

```json
{
  "snippets": [
    { "id": "snippet1", "code": "def hello_world():\n    print('Hello, World!')" },
    { "id": "snippet2", "code": "const x = async () => await fetch('https://apify.com/api/data');" },
    { "id": "snippet3", "code": "fn main() { println!(\"Hello, Rust!\"); }" }
  ]
}
```

| Field | Type | Description | Default |
|---|---|---|---|
| `snippets` | array | Code snippets to classify | required |
| `snippets[].id` | string | Optional identifier for each snippet | — |
| `snippets[].code` | string | The code snippet text | required |

### Output

Results are stored in the Apify dataset. Download in JSON, CSV, HTML, or Excel.

```json
{
  "id": "snippet1",
  "detectedLanguage": "Python",
  "confidence": 0.97,
  "alternatives": [
    { "language": "Ruby", "confidence": 0.02 }
  ]
}
```

### Output fields

| Field | Type | Description |
|---|---|---|
| `id` | string | Snippet identifier (if provided) |
| `detectedLanguage` | string | Most likely programming language |
| `confidence` | number | Detection confidence score (0–1) |
| `alternatives` | array | Other possible languages with lower confidence |

### Cost

Pay-per-result pricing:

| Volume | Estimated cost |
|---|---|
| 100 snippets | ~$0.01–$0.10 |
| 1,000 snippets | ~$0.10–$1.00 |

### Supported languages

Python, JavaScript, TypeScript, Java, C, C++, C#, Go, Rust, Ruby, PHP, Swift, Kotlin, R, Scala, Perl, Haskell, Lua, Shell, SQL, HTML, CSS, YAML, JSON, XML, Markdown, and more.

### Tips

- Provide at least 3–5 lines of code for best accuracy — single-line snippets may have lower confidence
- Use the `id` field to correlate results with your source dataset
- For ambiguous snippets (e.g., plain text or config files), check the `alternatives` array

### FAQ

**What is the minimum snippet length for accurate detection?**
3–5 lines of code is recommended. Very short snippets (1–2 lines) may have lower accuracy.

**Can it detect domain-specific languages?**
The Actor focuses on popular general-purpose languages. DSLs may be misidentified.

**Is this Actor maintained?**
Yes. Report bugs or feature requests in the Issues tab.

**Need help or have questions?**
Open an issue in the Issues tab or reach out on Discord: **maged03211**

# Actor input Schema

## `sourceCode` (type: `string`):

Raw source code to analyze

## `fileUrl` (type: `string`):

URL to a file containing source code to analyze

## Actor input object example

```json
{
  "sourceCode": "def hello():\n    print(\"Hello, world!\")\n\nif __name__ == \"__main__\":\n    hello()",
  "fileUrl": "https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "sourceCode": `def hello():
    print("Hello, world!")

if __name__ == "__main__":
    hello()`,
    "fileUrl": "https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
};

// Run the Actor and wait for it to finish
const run = await client.actor("maged120/programming-language-detector").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "sourceCode": """def hello():
    print(\"Hello, world!\")

if __name__ == \"__main__\":
    hello()""",
    "fileUrl": "https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js",
}

# Run the Actor and wait for it to finish
run = client.actor("maged120/programming-language-detector").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "sourceCode": "def hello():\\n    print(\\"Hello, world!\\")\\n\\nif __name__ == \\"__main__\\":\\n    hello()",
  "fileUrl": "https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
}' |
apify call maged120/programming-language-detector --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,maged120/programming-language-detector"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/IQDN4hce1BdYTbbfM/builds/wPIUKULaSKjQuMoqq/openapi.json
