frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Show HN: Valid8r, Functional validation for Python CLIs using Maybe monads

https://github.com/mikelane/valid8r
5•lanemik•16h ago
I built Valid8r because I got tired of writing the same input validation code for every CLI tool. You know the pattern: parse a string, check if it's valid, print an error if not, ask again. Repeat for every argument.

The library uses Maybe monads (Success/Failure instead of exceptions) so you can chain parsers and validators:

  # Try it: pip install valid8r
  from valid8r.core import parsers, validators
  
  # Parse and validate in one pipeline
  result = (
      parsers.parse_int(user_input)
      .bind(validators.minimum(1))
      .bind(validators.maximum(65535))
  )
  
  match result:
      case Success(port): print(f"Using port {port}")
      case Failure(error): print(f"Invalid: {error}")
I built integrations for argparse, Click, and Typer so you can drop valid8r parsers directly into your existing CLIs without refactoring everything.

The interesting technical bit: it's 4-300x faster than Pydantic for simple parsing (ints, emails, UUIDs) because it doesn't build schemas or do runtime type checking. It just parses strings and returns Maybe[T]. For complex nested validation, Pydantic is still better. I benchmarked both and documented where each one wins.

I'm not trying to replace Pydantic. If you're building a FastAPI service, use Pydantic. But if you're building CLI tools or parsing network configs, Maybe monads compose really nicely and keep your code functional.

The docs are at https://valid8r.readthedocs.io/ and the benchmarks are in the repo. It's MIT licensed.

Would love feedback on the API design. Is the Maybe monad pattern too weird for Python, or does it make validation code cleaner?

---

Here are a few more examples showing different syntax options for the same port validation:

  from valid8r.core import parsers, validators

  # Option 1: Combine validators with & operator
  validator = validators.minimum(1) & validators.maximum(65535)
  result = parsers.parse_int(user_input).bind(validator)

  # Option 2: Use parse_int_with_validation (built-in)
  result = parsers.parse_int_with_validation(
      user_input,
      validators.minimum(1) & validators.maximum(65535)
  )

  # Option 3: Interactive prompting (keeps asking until valid)
  from valid8r.prompt import ask

  port = ask(
      "Enter port number (1-65535): ",
      parser=lambda s: parsers.parse_int(s).bind(
          validators.minimum(1) & validators.maximum(65535)
      )
  )
  # port is guaranteed valid here, no match needed

  # Option 4: Create a reusable parser function
  def parse_port(text):
      return parsers.parse_int(text).bind(
          validators.minimum(1) & validators.maximum(65535)
      )

  result = parse_port(user_input)
The & operator is probably the cleanest for combining validators. And the interactive prompt is nice because you don't need to match Success/Failure, it just keeps looping until the user gives you valid input.

Show HN: What Is Hacker News Working On?

https://waywo.eamag.me/
140•eamag•3d ago•30 comments

Show HN: Eyes-follow cursor widget for playful UI feedback

https://rlu.ai/ai/eyes-follow-mouse-widget
2•su466120534•1h ago•0 comments

Show HN: DroidDock – A sleek macOS app for browsing Android device files via ADB

https://rajivm1991.github.io/DroidDock/
64•rajivm1991•13h ago•33 comments

Show HN: Reverse perspective camera for OpenGL (Three.js)

https://github.com/bntre/reverse-perspective-threejs
2•bntr•3h ago•1 comments

Show HN: Free AI Grammar Checker – Instant Corrections

https://grammarchecker.cc
2•john_davis_0122•5h ago•0 comments

Show HN: Hephaestus – Autonomous Multi-Agent Orchestration Framework

https://github.com/Ido-Levi/Hephaestus
76•idolevi•1w ago•13 comments

Show HN: I Accidentally Created a Custom Clothing Brand for Developers

https://giTshirt.com
3•GeorgiMY•6h ago•0 comments

Show HN: Trilogy Studio, open-source browser-based SQL editor and visualizer

https://trilogydata.dev/trilogy-studio-core/#screen=dashboard-import&import=https%3A%2F%2Ftrilogy...
16•efromvt•15h ago•2 comments

Show HN: Sparktype – a CMS and SSG that runs entirely in the browser

https://app.sparktype.org
44•mattkevan•6d ago•9 comments

Show HN: PingStalker – A macOS tool for network engineers

https://www.pingstalker.com/?hn
72•n1sni•6d ago•29 comments

Show HN: I built an HTTP client that perfectly mimics Chrome 142

https://github.com/arman-bd/httpmorph
38•armanified•1d ago•6 comments

Show HN: Find matching acrylic paints for any HEX color

https://acrylicmatch.com/
56•dotspencer•6d ago•19 comments

Show HN: TidesDB – Fast, transactional storage optimized for flash and RAM

https://github.com/tidesdb/tidesdb
13•alexpadula•22h ago•1 comments

Show HN: Alignmenter – Measure brand voice and consistency across model versions

https://www.alignmenter.com
2•justingrosvenor•14h ago•1 comments

Show HN: I scraped 3B Goodreads reviews to train a better recommendation model

https://book.sv
596•costco•4d ago•258 comments

Show HN: Valid8r, Functional validation for Python CLIs using Maybe monads

https://github.com/mikelane/valid8r
5•lanemik•16h ago•0 comments

Show HN: I built a self-hosted error tracker in Rails

https://telebugs.com
75•kyrylo•1w ago•52 comments

Show HN: qqqa – A fast, stateless LLM-powered assistant for your shell

https://github.com/matisojka/qqqa
160•iagooar•4d ago•85 comments

Show HN: See chords as flags – Visual harmony of top composers on musescore

https://rawl.rocks/
126•vitaly-pavlenko•4d ago•28 comments

Show HN: OtterLang – Pythonic scripting language that compiles to native code

https://github.com/jonathanmagambo/otterlang
15•otterlang•1d ago•9 comments

Show HN: UniWorld V2 – Region-Aware AI Image Editing with RL Accuracy

https://www.uniworldv2.com/?i=d1d5k
2•lu794377•8h ago•0 comments

Show HN: I'm a pastor/dev and built a 200M token generative Bible

https://www.anselm-project.com/bible/genesis/Genesis%201:1-2:3
12•mrprmiller•18h ago•4 comments

Show HN: Dynamic code and feedback walkthroughs with your coding Agent in VSCode

https://www.intraview.ai/hn-demo
44•cyrusradfar•3d ago•11 comments

Show HN: React Source Lens – Jump from UI components to source code in one click

https://www.npmjs.com/package/react-source-lens
2•ombedzi•23h ago•0 comments

Show HN: Three Emojis, a daily word puzzle for language learners

https://threeemojis.com/en-US/play/hex/en-US/2025-11-07
31•knuckleheads•2d ago•27 comments

Show HN: TabPFN-2.5 – SOTA foundation model for tabular data

https://priorlabs.ai/technical-reports/tabpfn-2-5-model-report
72•onasta•3d ago•12 comments

Show HN: Every-few-days satellite timeline for any spot, Sentinel-2 SR

https://mzoom.space
3•varik•1d ago•2 comments

Show HN: Patternia – A compile-time compile-time pattern matching DSL for C++

https://github.com/SentoMK/paaternia
2•sentomk•1d ago•1 comments

Show HN: Complex Zeta Function in JavaScript – deep math

https://www.zeta-calculator.com/
2•cpuXguy•1d ago•0 comments

Show HN: A CSS-Only Terrain Generator

https://terra.layoutit.com
368•rofko•6d ago•82 comments