TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Codegen – OSS Python Library for Advanced Code Manipulation

15 pointsby _jayhack_4 months ago
Hey HN! We&#x27;ve just open-sourced Codegen (<a href="https:&#x2F;&#x2F;github.com&#x2F;codegen-sh&#x2F;codegen-sdk">https:&#x2F;&#x2F;github.com&#x2F;codegen-sh&#x2F;codegen-sdk</a>), a Python library for manipulating Python + JS&#x2F;React codebases.<p>Codegen was engineered backwards from real-world, large-scale codebase analysis + refactors we performed on multi-million-line enterprise codebases. It provides a scriptable interface to a powerful, multi-lingual language server built on Tree-sitter.<p>We realized that many code transformation tasks that impact large teams - refactors, enforcing patterns, analyzing control flow - are fundamentally programmatic operations. Yet existing tools like LibCST and Jscodeshift often require you to think in terms of ASTs and parser internals rather than the high-level changes you want to make.<p>Therefore, we built Codegen to match how developers actually think about code changes:<p><pre><code> # Move a symbol to a new file # Handles imports, references, dependencies function.move_to_file(&quot;new_file.py&quot;) # Rename across the codebase class_def.rename(&quot;NewName&quot;) # Updates all usages, preserves formatting # Analyze call patterns for usage in function.usages: print(f&quot;Used in {usage.file.name}&quot;) </code></pre> Codegen handles the edge cases automatically - updating imports, preserving dependencies, maintaining references, and resolving naming conflicts. You focus on intent, we handle the details.<p>Under the hood, Codegen performs static analysis to build a rich graph representation of your code. This enables:<p>- Versatile and comprehensive operations<p>- Built-in visualization capabilities<p>- Blazing fast execution of large-scale refactors<p>We&#x27;ve seen a wide variety of advanced code manipulation programs emerge, including:<p>- Mining codebases for LLM pre-training data<p>- Analyzing security vulnerabilities<p>- Large-scale API migrations<p>- Enforcing code patterns<p>We&#x27;re excited to share this with the community and look forward to your feedback. Give it a spin and let us know what you think!<p><pre><code> uv tool install codegen codegen notebook --demo </code></pre> Docs: <a href="https:&#x2F;&#x2F;docs.codegen.com" rel="nofollow">https:&#x2F;&#x2F;docs.codegen.com</a> GitHub: <a href="https:&#x2F;&#x2F;github.com&#x2F;codegen-sh&#x2F;codegen-sdk">https:&#x2F;&#x2F;github.com&#x2F;codegen-sh&#x2F;codegen-sdk</a> Community: <a href="https:&#x2F;&#x2F;community.codegen.com" rel="nofollow">https:&#x2F;&#x2F;community.codegen.com</a><p>Let us know if you have any questions or interesting use cases you&#x27;d like to explore.

2 comments

solarkraft4 months ago
Man, at first glance the documentation looks so good.<p>I’ve been meaning to build a PoC for directly manipulating symbols instead of text with the idea to eventually eliminate the possibility of syntax errors.<p>The task always looked one step too big for me to be worth it - the foundation for programmatically manipulating code seemed to be missing, maybe Roslyn fits the bill, but C# isn’t interesting to me ecosystem wise.<p>It seems like this may be what I was waiting for - pretty cool!
hnisoss4 months ago
How does this compare to Codemodder? Can it be used for transpilation?
评论 #42873868 未加载