sdkagent

semgrep API reference

173 public APIs from semgrep (semgrep/semgrep) — 68 classes, 73 functions, 32 methods. Signatures extracted by static analysis of the actual source.

Repository: semgrep/semgrep

KindCount
Classes68
Functions73
Methods32

API list

funccli.src.semdep.golang_version.cmp_golang_versions(parsed_version:ParsedGolangVersion, specifier_version:ParsedGolangVersion) -> int
Compares the package version and the spec version.
funccli.src.semdep.golang_version.compare_golang_specifier(specifier:str, version:str) -> bool
Returns if version satisfies specifier arguments
classcli.src.semdep.matchers.base.ManifestOnlyMatcher
A matcher for lone manifests.
classcli.src.semdep.matchers.gradle.GradleMatcher
Matcher for gradle project root directories.
funccli.src.semdep.maven_version.compare_maven_specifier(specifier:str, version:str) -> bool
Returns if version satisfies specifier requirement i.e.
funccli.src.semdep.parsers.pnpm.get_key_values(yaml:YamlTree[YamlMap], field:str) -> List[str]
Extracts all keys from a specified field in a YamlMap.
funccli.src.semdep.parsers.pnpm.parse_dependency_version(version_str:str) -> ParseResult
Parses a dependency version string into its components.
funccli.src.semdep.parsers.pnpm.parse_direct_pre_v6(yaml:YamlTree[YamlMap]) -> List[str]
Extracts direct dependencies for pnpm-lock.yaml version <=5.4.
funccli.src.semdep.parsers.pnpm.parse_package_key_post_v9(key:str) -> Optional[Tuple[str, str]]
Parses the package key for pnpm-lock.yaml version >=9.0.
funccli.src.semdep.parsers.pnpm.parse_package_key_pre_v6(key:str) -> Optional[Tuple[str, str]]
Parses the package key for pnpm-lock.yaml version <=5.4.
classcli.src.semdep.parsers.util.ParsedDependency
A dependency parsed from a lockfile.
funccli.src.semdep.parsers.util.become(p1:Parser[A], p2:Parser[A]) -> None
Gives [p1] the behavior of [p2] by side effect.
funccli.src.semdep.parsers.util.not_any(*chars:str) -> Parser[str]
[chars] must contain only single character strings.
funccli.src.semdep.parsers.util.quoted(p:Parser[A]) -> Parser[A]
Parse [p], surrounded by quotes, ignoring the quotes in the output
funccli.src.semdep.parsers.util.to_parser(parser:LegacyDependencyParser) -> DependencyParser
Converts a legacy parser to a new parser format.
funccli.src.semdep.parsers.util.upto(*include_other:bool=False, *consume_other:bool=False, *allow_newline:bool=False, *s:str) -> Parser[str]
[s] must be a list of single character strings.
funccli.src.semdep.parsers.yarn.get_manifest_deps(parsed_manifest:Optional[JSON]) -> Optional[Set[Tuple[str, str]]]
Extract a set of constraints from a package.json file
funccli.src.semgrep.app.auth.set_token(token:str) -> None
Save api token to settings file
classcli.src.semgrep.app.session.AppSession
Send requests to Semgrep App with this session.
classcli.src.semgrep.app.session.UserAgent
Generates the user agent string we send to Semgrep App.
classcli.src.semgrep.commands.scan.ScanResult
The return type of the scan function
methodcli.src.semgrep.config_resolver.ConfigLoader.includes_remote_config(configs:Optional[Sequence[str]]) -> bool
Returns True if any of the configs are remote
methodcli.src.semgrep.config_resolver.ConfigLoader.load_config() -> List[ConfigFile]
Loads a config based on self's state.
classcli.src.semgrep.config_resolver.ParsedConfig
Result of parsing a single config string into rules.
funccli.src.semgrep.config_resolver.is_registry_id(config_str:str) -> bool
Starts with r/, p/, s/ for registry, pack, and snippet respectively
funccli.src.semgrep.config_resolver.read_config_at_path(loc:Path, base_path:Optional[Path]=None) -> ConfigFile
Assumes file at loc exists
funccli.src.semgrep.config_resolver.registry_id_to_url(registry_id:str) -> str
Convert from registry_id to semgrep.dev url
funccli.src.semgrep.core_runner.parse_core_output_json(output_json:Any) -> out.CoreOutput
Convert JSON tree into CoreOutput and import profiling data
classcli.src.semgrep.error.DependencyResolutionSemgrepError
An error that occurred during dependency resolution.
classcli.src.semgrep.error_handler.ErrorHandler
Send scan status to the fail-open endpoint
methodcli.src.semgrep.error_handler.ErrorHandler.configure(suppress_errors:Optional[bool]=False) -> None
Configures whether to always or never send fail-open status.
methodcli.src.semgrep.error_handler.ErrorHandler.is_enabled() -> bool
Returns whether scan status should be sent.
methodcli.src.semgrep.error_handler.ErrorHandler.send(exit_code:int) -> int
Send scan status to the fail-open server.
classcli.src.semgrep.error_location.Position
Position within a file.
classcli.src.semgrep.error_location.Span
Spans are immutable objects, representing segments of code.
methodcli.src.semgrep.error_location.Span.with_context(before:Optional[int]=None, after:Optional[int]=None) -> 'Span'
Expand
funccli.src.semgrep.formatter.text.to_severity_indicator(rule_match:RuleMatch, color_output:bool=False) -> Tuple[str, str]
Return a color and severity icon.
funccli.src.semgrep.git.is_git_repo_empty() -> bool
Checks if the repo is empty.
funccli.src.semgrep.git.zsplit(s:str) -> List[str]
Split a string on null characters.
funccli.src.semgrep.join_rule.create_config_map(semgrep_config_strings:List[str]) -> Dict[str, Rule]
Create a mapping of Semgrep config strings to Rule objects.
funccli.src.semgrep.join_rule.run_join_rule(join_rule:Dict[str, Any], scanning_roots:List[Path], fips_mode:bool, allow_local_builds:bool=False, ptt_enabled:bool=False) -> Tuple[List[RuleMatch], List[SemgrepError]]
Run a 'join' mode rule.
classcli.src.semgrep.mcp.hooks.inject_secure_defaults.EmptyStdinError
Exception raised when the stdin is empty.
funccli.src.semgrep.mcp.hooks.inject_secure_defaults.fetch_readme() -> str
Fetch the README from GitHub and cache it.
funccli.src.semgrep.mcp.hooks.inject_secure_defaults.get_cached_content() -> str | None
Get content from cache if available.
funccli.src.semgrep.mcp.hooks.inject_secure_defaults.get_fallback_content() -> str
Return fallback content if GitHub fetch fails.
funccli.src.semgrep.mcp.hooks.stop.load_file_path() -> tuple[str, str]
Returns the file path and the workspace root
funccli.src.semgrep.mcp.server.get_deployment_slug() -> str
Fetches and caches the deployment slug from Semgrep API.
funccli.src.semgrep.mcp.server.get_semgrep_rule_yaml(rule_id:str=RULE_ID_FIELD) -> str
Full Semgrep rule in YAML format from the Semgrep registry.
funccli.src.semgrep.mcp.server.health(request:Request) -> JSONResponse
Health check endpoint
funccli.src.semgrep.mcp.server.semgrep_whoami(ctx:Context) -> WhoamiResult
Returns the identity of the current user.
funccli.src.semgrep.mcp.server.server_lifespan(_server:FastMCP) -> AsyncIterator[SemgrepContext]
Manage server startup and shutdown lifecycle.
funccli.src.semgrep.mcp.server.validate_absolute_path(path_to_validate:str, param_name:str) -> str
Validates an absolute path to ensure it's safe to use
funccli.src.semgrep.mcp.server.validate_config(config:str | None=None) -> str
Validates semgrep configuration parameter
funccli.src.semgrep.mcp.utilities.tracing.start_tracing(name:str) -> Generator[trace.Span | None, None, None]
Initialize OpenTelemetry tracing.
funccli.src.semgrep.mcp.utilities.utils.findings_elicitation_enabled() -> bool
Check if findings elicitation is enabled.
funccli.src.semgrep.mcp.utilities.utils.get_anonymous_user_id() -> str
Returns the anonymous user ID, if it exists
funccli.src.semgrep.mcp.utilities.utils.get_deployment_from_jwt() -> dict[str, Any]
Returns the deployment data the JWT is for.
funccli.src.semgrep.mcp.utilities.utils.get_deployment_id() -> int | None
Returns the deployment ID, if it exists.
funccli.src.semgrep.mcp.utilities.utils.get_deployment_name() -> str | None
Returns the deployment name, if it exists.
funccli.src.semgrep.mcp.utilities.utils.get_identity() -> dict[str, Any]
Fetches the identity from Semgrep API.
funccli.src.semgrep.mcp.utilities.utils.get_semgrep_access_token() -> str | None
Returns the JWT access token, if it exists.
funccli.src.semgrep.mcp.utilities.utils.get_semgrep_app_token() -> str | None
Returns the Semgrep app token, if it exists
funccli.src.semgrep.mcp.utilities.utils.is_oauth_authenticated() -> bool
Check if the user is authenticated using OAuth.
classcli.src.semgrep.meta.AzurePipelinesMeta
Gather metadata from Azure pipelines.
classcli.src.semgrep.meta.BitbucketMeta
Gather metadata from BitBucket.
classcli.src.semgrep.meta.BuildkiteMeta
Gather metadata from Buildkite.
classcli.src.semgrep.meta.CircleCIMeta
Gather metadata from Circle CI.
classcli.src.semgrep.meta.GitMeta
Gather metadata only from local filesystem.
methodcli.src.semgrep.meta.GitMeta.commit_datetime() -> str
Returns epoch time as str of head commit
classcli.src.semgrep.meta.GithubMeta
Gather metadata from GitHub Actions.
classcli.src.semgrep.meta.GitlabMeta
Gather metadata from GitLab 10.0+
classcli.src.semgrep.meta.JenkinsMeta
Gather metadata from Jenkins CI.
methodcli.src.semgrep.meta.JenkinsMeta.repo_name() -> str
Constructs the repo name from the git url.
classcli.src.semgrep.meta.SemgrepManagedScanMeta
Gather metadata from Semgrep Managed Scanning.
classcli.src.semgrep.meta.SemgrepMcpMeta
Gather metadata from Semgrep MCP.
classcli.src.semgrep.meta.TravisMeta
Gather metadata from Travis CI.
funccli.src.semgrep.meta.get_repo_name_from_repo_url(repo_url:Optional[str]) -> Optional[str]
Pulls repository name from the url using a git url parser
funccli.src.semgrep.meta.get_url_from_sstp_url(sstp_url:Optional[str]) -> Optional[str]
Gets regular url from sstp url.
classcli.src.semgrep.metrics.Metrics
To prevent sending unintended metrics: 1.
methodcli.src.semgrep.metrics.Metrics.add_parse_rates(parse_rates:ParsingData) -> None
Adds parse rates, grouped by language
methodcli.src.semgrep.metrics.Metrics.add_project_url(project_url:Optional[str]) -> None
Standardizes url then hashes
methodcli.src.semgrep.metrics.Metrics.is_enabled() -> bool
Returns whether metrics should be sent.
methodcli.src.semgrep.metrics.Metrics.send() -> None
Send metrics to the metrics server.
classcli.src.semgrep.metrics.MetricsState
Configures metrics upload.
classcli.src.semgrep.output.OutputHandler
Handle all output in a central location.
classcli.src.semgrep.resolve_dependency_source.ResolveDependenciesRpcResult
The result of _resolve_dependencies_rpc
methodcli.src.semgrep.rule.Rule.full_hash() -> str
sha256 hash of the whole rule object instead of just the id.
methodcli.src.semgrep.rule.Rule.is_blocking() -> bool
Returns if this rule indicates matches should block CI
funccli.src.semgrep.rule.rule_without_metadata(rule:Rule) -> Rule
Key used to deduplicate rules.
funccli.src.semgrep.rule_lang.build_rule_spans(yaml_tree:YamlTree) -> Dict[str, Span]
Extract rule_id -> YAML Span from a parsed YamlTree.
funccli.src.semgrep.rule_lang.parse_yaml_preserve_spans(contents:str, filename:Optional[str], allow_null:bool=False) -> Optional[YamlTree]
parse yaml into a YamlTree object.
funccli.src.semgrep.rule_lang.run_rpc_validate_exn(rules_tmp_path:str) -> None
Applies validation to a file at rules_tmp_path via semgrep-core.
funccli.src.semgrep.rule_lang.sanitize_rule_id_fragment(s:str) -> str
Make a valid fragment for a rule ID.
methodcli.src.semgrep.rule_match.RuleMatch.get_ordering_key() -> Tuple[str, Position, Position, str, str]
Used to sort findings in output.
methodcli.src.semgrep.rule_match.RuleMatch.get_path_changed_ci_unique_key(rename_dict:Dict[str, Path]) -> Tuple[str, str, str, int]
A unique key that accounts for filepath renames.
methodcli.src.semgrep.rule_match.RuleMatch.get_previous_line() -> str
Return the line preceding the match, if any.
methodcli.src.semgrep.rule_match.RuleMatch.get_syntactic_id() -> str
A 32-character hash representation of ci_unique_key.
methodcli.src.semgrep.rule_match.RuleMatch.is_blocking() -> bool
Returns if this finding indicates it should block CI
methodcli.src.semgrep.rule_match.RuleMatch.to_app_finding_format(commit_date:str, remove_dataflow_content:bool) -> out.Finding
commit_date here for legacy reasons.
funccli.src.semgrep.safe_set.intersection(a:FrozenSet[T], b:Collection[T]) -> FrozenSet[T]
Intersect two sets containing elements of the same type.
funccli.src.semgrep.safe_set.union(a:FrozenSet[T], b:Collection[T]) -> FrozenSet[T]
Take the union of two sets containing elements of the same type.
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.AnalysisType
Original type: analysis_type = [ ...
methodcli.src.semgrep.semgrep_interfaces.semgrep_metrics.AnalysisType.kind() -> str
Name of the class representing this variant.
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Any_
Original type: secrets_origin = [ ...
methodcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Any_.kind() -> str
Name of the class representing this variant.
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.CodeConfig
Original type: code_config = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Datetime
Original type: datetime
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.EngineConfig
Original type: engine_config = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Environment
Original type: environment = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Error
Original type: error
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Errors
Original type: errors = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Extension
Original type: extension = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.FileStats
Original type: file_stats = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Finding
Original type: finding = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Guardian
Original type: guardian = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.InstallPro
Original type: install_pro = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Interfile
Original type: analysis_type = [ ...
methodcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Interfile.kind() -> str
Name of the class representing this variant.
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Interprocedural
Original type: analysis_type = [ ...
methodcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Interprocedural.kind() -> str
Name of the class representing this variant.
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Intraprocedural
Original type: analysis_type = [ ...
methodcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Intraprocedural.kind() -> str
Name of the class representing this variant.
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Lang
Original type: lang
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Mcp
Original type: mcp = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.NoCommunity
Original type: secrets_origin = [ ...
methodcli.src.semgrep.semgrep_interfaces.semgrep_metrics.NoCommunity.kind() -> str
Name of the class representing this variant.
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.ParseStat
Original type: parse_stat = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Payload
Original type: payload = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Performance
Original type: performance = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.ProFeatures
Original type: pro_features = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.RuleStats
Original type: rule_stats = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.SecretsConfig
Original type: secrets_config = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.SecretsOrigin
Original type: secrets_origin = [ ...
methodcli.src.semgrep.semgrep_interfaces.semgrep_metrics.SecretsOrigin.kind() -> str
Name of the class representing this variant.
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Semgrep
Original type: secrets_origin = [ ...
methodcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Semgrep.kind() -> str
Name of the class representing this variant.
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Sha256
Original type: sha256
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.SupplyChainConfig
Original type: supply_chain_config = { ...
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Uuid
Original type: uuid
classcli.src.semgrep.semgrep_interfaces.semgrep_metrics.Value
Original type: value = { ...
methodcli.src.semgrep.settings.Settings.delete(key:SettingsKeys) -> None
Deletes key KEY from settings file if it exists Noop otherwise
methodcli.src.semgrep.settings.Settings.get_default_contents() -> SettingsSchema
If file exists, read file.
classcli.src.semgrep.simple_profiling.ProfilingEntry
Mutable accumulator for execution time
funccli.src.semgrep.simple_profiling.export_simple_profiling() -> list[out.ProfilingEntry]
Produce a list sorted by decreasing total_time
funccli.src.semgrep.simple_profiling.import_simple_profiling(entries:list[out.ProfilingEntry]) -> None
Import profiling data from semgrep-core
funccli.src.semgrep.state.get_context() -> click.Context
Get the current CLI invocation's click context.
funccli.src.semgrep.state.get_state() -> SemgrepState
Get the current CLI invocation's global state.
funccli.src.semgrep.subproject.count_resolved_dependencies(d:Dict[out.DependencyChild, List[out.ResolvedDependency]]) -> int
Count the number of dependencies
funccli.src.semgrep.subproject.subproject_sort_key(subproject:Union[out.ResolvedSubproject, out.UnresolvedSubproject]) -> Tuple[Tuple[int, int], str]
Used to sort subprojects in the table.
funccli.src.semgrep.subproject.subproject_to_stats(sub:Union[out.ResolvedSubproject, out.UnresolvedSubproject]) -> out.SubprojectStats
Convert a subproject to subproject stats.
classcli.src.semgrep.target_manager.FileTargetingLog
Keeps track of which paths were ignored for what reason.
classcli.src.semgrep.target_manager.ScanningRoot
Represents one path that was given as a scanning root.
methodcli.src.semgrep.target_manager.ScanningRoot.files_from_git_diff() -> FrozenSet[Path]
Get only changed files since baseline commit.
methodcli.src.semgrep.target_manager.ScanningRoot.validate_path(_:Any, value:Path) -> None
Check whether the targeted path exists.
classcli.src.semgrep.terminal.Terminal
Fundamental settings on how to log output.
classcli.src.semgrep.types.FilteredFiles
The return value of functions that filters target files.
classcli.src.semgrep.types.FilteredMatches
The return value of functions that filter matches files.
classcli.src.semgrep.types.SelectedTargets
Immutable container for selected targets that were obtained.
classcli.src.semgrep.types.TargetAccumulator
Accumulate targets that are scanned by Semgrep rules.
funccli.src.semgrep.types.fake_target_of_path(path:Path) -> Target
For tests only!
funccli.src.semgrep.types.fake_targets_of_paths(paths:Iterable[Path]) -> FrozenSet[Target]
For tests only!
funccli.src.semgrep.util.get_lines_from_file(path:Path, start_line:int, end_line:int) -> List[str]
Return lines in the given file.
funccli.src.semgrep.util.get_lines_from_git_blob(blob_sha:Sha1, start_line:int, end_line:int) -> List[str]
Return lines in the given git blob.
funccli.src.semgrep.util.has_color() -> bool
Determine if color should be used in the output.
funccli.src.semgrep.util.is_secrets_ai_ruleset(metadata:Mapping[str, Any]) -> bool
Check if a rule or match is from the semgrep-secrets-ai ruleset.
funccli.src.semgrep.util.is_truthy(value:Any) -> bool
Returns True if the value is a truthy value, False otherwise.
funccli.src.semgrep.util.json_win_paths_to_posix(json:Any) -> Any
Convert all Windows relative paths in a JSON object to POSIX paths.
funccli.src.semgrep.util.listendswith(l:List[T], tail:List[T]) -> bool
E.g.
funccli.src.semgrep.util.redact_credentials(s:str) -> str
Strip URL userinfo and Authorization-header values from [s].
funccli.src.semgrep.util.welcome() -> None
Print a welcome message with the Semgrep logo.
funccli.src.semgrep.util.with_logo_color(text:str) -> str
Wrap text with our brand color if color is enabled.
classperf.config.BenchmarkRunSetupData
Stores data about an individual benchmark run
classperf.config.SemgrepBenchmarkConfig
Stores data needed to start a benchmarking run.

About this data

These signatures were extracted from the public source of semgrep/semgrep using Python's ast module. Argument names, default values, type annotations and return types are taken verbatim from the code. Implementation bodies are never stored. See how it works for details.

Back to all 805 libraries