Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Solo.io wins ‘most likely to succeed’ award at VB Transform 2025 innovation showcase

    The great AI agent acceleration: Why enterprise adoption is happening faster than anyone predicted

    $8.8 trillion protected: How one CISO went from ‘that’s BS’ to bulletproof in 90 days

    Facebook X (Twitter) Instagram
    • Artificial Intelligence
    • Business Technology
    • Cryptocurrency
    • Gadgets
    • Gaming
    • Health
    • Software and Apps
    • Technology
    Facebook X (Twitter) Instagram Pinterest Vimeo
    Tech AI Verse
    • Home
    • Artificial Intelligence

      Apple sued by shareholders for allegedly overstating AI progress

      June 22, 2025

      How far will AI go to defend its own survival?

      June 2, 2025

      The internet thinks this video from Gaza is AI. Here’s how we proved it isn’t.

      May 30, 2025

      Nvidia CEO hails Trump’s plan to rescind some export curbs on AI chips to China

      May 22, 2025

      AI poses a bigger threat to women’s work, than men’s, report says

      May 21, 2025
    • Business

      Cloudflare open-sources Orange Meets with End-to-End encryption

      June 29, 2025

      Google links massive cloud outage to API management issue

      June 13, 2025

      The EU challenges Google and Cloudflare with its very own DNS resolver that can filter dangerous traffic

      June 11, 2025

      These two Ivanti bugs are allowing hackers to target cloud instances

      May 21, 2025

      How cloud and AI transform and improve customer experiences

      May 10, 2025
    • Crypto

      MoonPay Executives Might Have Fallen for $250,000 Trump-Themed Crypto Scam

      July 11, 2025

      Top 3 Altcoins Trending in Nigeria This Week

      July 11, 2025

      Tether is Removing USDT From These 5 Legacy Blockchains

      July 11, 2025

      HBAR Faces Final Hurdle After Explosive Rally; Are Bulls Tiring Out?

      July 11, 2025

      OKX Europe CEO Discusses Bitcoin’s Breakout Rally | US Crypto News

      July 11, 2025
    • Technology

      Solo.io wins ‘most likely to succeed’ award at VB Transform 2025 innovation showcase

      July 11, 2025

      The great AI agent acceleration: Why enterprise adoption is happening faster than anyone predicted

      July 11, 2025

      $8.8 trillion protected: How one CISO went from ‘that’s BS’ to bulletproof in 90 days

      July 11, 2025

      AWS doubles down on infrastructure as strategy in the AI race with SageMaker upgrades

      July 11, 2025

      The best Amazon Prime Day deals for the last day: Our top picks on headphones, TVs, robot vacuums and more

      July 11, 2025
    • Others
      • Gadgets
      • Gaming
      • Health
      • Software and Apps
    Shop Now
    Tech AI Verse
    You are at:Home»Technology»Fun with uv and PEP 723
    Technology

    Fun with uv and PEP 723

    TechAiVerseBy TechAiVerseJune 24, 2025No Comments2 Mins Read0 Views
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Fun with uv and PEP 723
    Share
    Facebook Twitter LinkedIn Pinterest WhatsApp Email

    Fun with uv and PEP 723

    Fun with uv and PEP 723 June 24, 2025

    For the longest time, I have been frustrated with Python because I couldn’t use it for one-off scripts. I had to first ensure it was running in an environment where it could find the right Python version and the dependencies installed. That is now a thing of the past.

    If you are not a Pythonista (or one possibly living under a rock), uv is an extremely fast Python package and project manager, written in Rust.

    uv also provides this nifty tool called uvx (kinda like npx from the Node/NPM ecosystem for Javascript/Typescript packages) which can be used to invoke a Python tool inside a package. uvx takes care of creating a (cached) disposable virtual environment, setting up the right Python version and installing all the dependencies before running.

    For example

    $ uvx ruff --version
    Installed 1 package in 5ms
    ruff 0.12.0

    PEP 723 is a Python Enhancement Proposal that specifies a metadata format that can be embedded in single-file Python scripts to assist launchers, IDEs and other external tools which may need to interact with such scripts.

    Here is the example directly lifted from the proposal:

    # /// script
    # requires-python = ">=3.11"
    # dependencies = [
    #   "requests<3",
    #   "rich",
    # ]
    # ///
    
    import requests
    from rich.pretty import pprint
    
    resp = requests.get("https://peps.python.org/api/peps.json")
    data = resp.json()
    pprint([(k, v["title"]) for k, v in data.items()][:10])

    Combining uv and the PEP-723 metadata inside a Python script, we can run the script in the previous section as follows:

    $ uv run pep.py
    Installed 9 packages in 24ms
    [
    │   ('1', 'PEP Purpose and Guidelines'),
    │   ('2', 'Procedure for Adding New Modules'),
    │   ('3', 'Guidelines for Handling Bug Reports'),
    │   ('4', 'Deprecation of Standard Modules'),
    │   ('5', 'Guidelines for Language Evolution'),
    │   ('6', 'Bug Fix Releases'),
    │   ('7', 'Style Guide for C Code'),
    │   ('8', 'Style Guide for Python Code'),
    │   ('9', 'Sample Plaintext PEP Template'),
    │   ('10', 'Voting Guidelines')
    ]

    We can combine things we covered in the previous sections to create a simple executable script that can extract YouTube transcripts.

    First we create a Python script with a shebang and inline metadata.

    #!/usr/bin/env -S uv run --script
    # /// script
    # requires-python = ">=3.8"
    # dependencies = [
    #     "youtube-transcript-api",
    # ]
    # ///
    
    import sys
    import re
    from youtube_transcript_api import YouTubeTranscriptApi
    from youtube_transcript_api.formatters import TextFormatter
    
    if len(sys.argv) < 2:
        print('Usage: provide YouTube URL or video_id as argument', file=sys.stderr)
        sys.exit(1)
    
    url_or_id = sys.argv[1]
    
    # Extract video ID from URL if it's a full URL
    video_id_match = re.search(r'(?:v=|/)([a-zA-Z0-9_-]{11})', url_or_id)
    if video_id_match:
        video_id = video_id_match.group(1)
    else:
        # Assume it's already a video ID
        video_id = url_or_id
    
    try:
        ytt_api = YouTubeTranscriptApi()
        transcript = ytt_api.fetch(video_id)
        formatter = TextFormatter()
        print(formatter.format_transcript(transcript))
    except Exception as e:
        print(f'Error: {e}', file=sys.stderr)
        sys.exit(1)

    Note the shebang line: #!/usr/bin/env -S uv run --script. It is important to specify uv run with the --script flag when used on the shebang line.

    We save this script as ytt and then make it executable with chmod +x ytt.

    We can now run the script like:

    $ ./ytt https://www.youtube.com/watch?v=zgSQr0d5EVg
    Installed 7 packages in 10ms
    hey it's Matt here and today I'm going
    to show you how to use UV not only to
    install packages in your python projects
    but to manage entire projects to create
    virtual environments and even how to
    manage entire versions of python with UV
    uh and hopefully you'll understand by
    any of this video UV is a dropin
    
    ……

    Fun times

    This opens up a lot of possibilities for running Python code more seamlessly. Before this I used to prefer Go for one-off scripts because it was easy to create a self-contained binary executable. But now that I could use uv, I coded up a quick MCP server in Python for extracting YouTube transcripts. Check it out on Github at cottongeeks/ytt-mcp.

    More resources

    • Running scripts | uv
    • Tools | uv
    • Using uv as an installer | aider
    Share. Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Telegram Email
    Previous ArticleMy “Are you presuming most people are stupid?” test
    Next Article Bridging Cinematic Principles and Generative AI for Automated Film Generation
    TechAiVerse
    • Website

    Jonathan is a tech enthusiast and the mind behind Tech AI Verse. With a passion for artificial intelligence, consumer tech, and emerging innovations, he deliver clear, insightful content to keep readers informed. From cutting-edge gadgets to AI advancements and cryptocurrency trends, Jonathan breaks down complex topics to make technology accessible to all.

    Related Posts

    Solo.io wins ‘most likely to succeed’ award at VB Transform 2025 innovation showcase

    July 11, 2025

    The great AI agent acceleration: Why enterprise adoption is happening faster than anyone predicted

    July 11, 2025

    $8.8 trillion protected: How one CISO went from ‘that’s BS’ to bulletproof in 90 days

    July 11, 2025
    Leave A Reply Cancel Reply

    Top Posts

    New Akira ransomware decryptor cracks encryptions keys using GPUs

    March 16, 202528 Views

    OpenAI details ChatGPT-o3, o4-mini, o4-mini-high usage limits

    April 19, 202522 Views

    6.7 Cummins Lifter Failure: What Years Are Affected (And Possible Fixes)

    April 14, 202519 Views

    Rsync replaced with openrsync on macOS Sequoia

    April 7, 202519 Views
    Don't Miss
    Technology July 11, 2025

    Solo.io wins ‘most likely to succeed’ award at VB Transform 2025 innovation showcase

    Solo.io wins ‘most likely to succeed’ award at VB Transform 2025 innovation showcase July 11,…

    The great AI agent acceleration: Why enterprise adoption is happening faster than anyone predicted

    $8.8 trillion protected: How one CISO went from ‘that’s BS’ to bulletproof in 90 days

    AWS doubles down on infrastructure as strategy in the AI race with SageMaker upgrades

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    About Us
    About Us

    Welcome to Tech AI Verse, your go-to destination for everything technology! We bring you the latest news, trends, and insights from the ever-evolving world of tech. Our coverage spans across global technology industry updates, artificial intelligence advancements, machine learning ethics, and automation innovations. Stay connected with us as we explore the limitless possibilities of technology!

    Facebook X (Twitter) Pinterest YouTube WhatsApp
    Our Picks

    Solo.io wins ‘most likely to succeed’ award at VB Transform 2025 innovation showcase

    July 11, 20251 Views

    The great AI agent acceleration: Why enterprise adoption is happening faster than anyone predicted

    July 11, 20252 Views

    $8.8 trillion protected: How one CISO went from ‘that’s BS’ to bulletproof in 90 days

    July 11, 20252 Views
    Most Popular

    Ethereum must hold $2,000 support or risk dropping to $1,850 – Here’s why

    March 12, 20250 Views

    Xiaomi 15 Ultra Officially Launched in China, Malaysia launch to follow after global event

    March 12, 20250 Views

    Apple thinks people won’t use MagSafe on iPhone 16e

    March 12, 20250 Views
    © 2025 TechAiVerse. Designed by Divya Tech.
    • Home
    • About Us
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.