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
4•lanemik•2h 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.

Work After Work: Notes from an Unemployed New Grad Watching the Job Market Break

https://urlahmed.com/2025/11/05/work-after-work-notes-from-an-unemployed-new-grad-watching-the-jo...
1•linkregister•52s ago•0 comments

Galaxy Brain Resistance

https://vitalik.eth.limo/general/2025/11/07/galaxybrain.html
1•yurivish•1m ago•0 comments

Rain: Cloud Leakage via Hardware Vulnerabilities – Vusec

https://www.vusec.net/projects/rain/
1•SpaghettiCthulu•3m ago•0 comments

Apple Developing These 5 New Satellite Features for iPhone

https://www.macrumors.com/2025/11/09/apple-developing-new-satellite-features/
1•mgh2•4m ago•0 comments

Show HN: Mxflo – Vibe code 2D games on your phone and play instantly

https://www.mxflo.com/beta
1•adithiya_shiva•12m ago•1 comments

2026 Nissan Leaf offers 300-mile range for $30k

https://abc7.com/post/new-2026-nissan-leaf-offers-300-mile-range-30000-price-tag/18076844/
1•lxm•13m ago•0 comments

Microsoft forms superintelligence team under AI head Mustafa Suleyman

https://www.cnbc.com/2025/11/06/microsoft-forms-superintelligence-team-under-ai-head-mustafa-sule...
3•gmays•13m ago•0 comments

Intel Xeon 6 Performance Feature Benchmarks: Latency Optimized Mode

https://www.phoronix.com/review/intel-latency-optimized-mode
1•dabinat•22m ago•0 comments

Sued by Nintendo

https://www.suedbynintendo.com/
6•notepad0x90•31m ago•0 comments

Why Does So Much New Technology Feel Inspired by Dystopian Sci-Fi Movies?

https://www.nytimes.com/2025/11/05/magazine/ai-tech-industry-sora-science-fiction.html
5•bookofjoe•33m ago•1 comments

There Are No Good Anti-Scandinavians

https://lichess.org/@/CkickyCheck/blog/there-are-no-good-anti-scandinavians/vncd0VCP
1•fzliu•36m ago•0 comments

The social contract of open source

https://snarky.ca/the-social-contract-of-open-source/
2•CharlesW•42m ago•0 comments

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

https://www.alignmenter.com
2•justingrosvenor•51m ago•1 comments

A place to meet new people and connect in Bern

https://connectbern.ch
2•chagaif•54m ago•0 comments

BBC director resigns over editing of Trump speech

https://www.ctvnews.ca/world/article/bbc-director-resigns-after-criticism-of-the-broadcasters-edi...
3•embedding-shape•55m ago•0 comments

What I Talk About When I Talk About Grading

https://unintendedconsequenc.es/what-i-talk-about-when-i-talk-about-grading/
1•paulorlando•57m ago•0 comments

Historic American Music Released by UCSB Library with Dust-to-Digital Foundation

https://news.ucsb.edu/2025/022193/vast-collection-historic-american-music-released-ucsb-library-p...
1•NaOH•1h ago•0 comments

Stay Niche

https://srid.ca/niche
1•wslh•1h ago•0 comments

Ask HN: How to get a Digg code? Can someone that works at Digg share thanks

1•babuloseo•1h ago•2 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...
1•efromvt•1h ago•1 comments

Is AI coming for our jobs and wages? Past predictions offer some clues

https://www.rnz.co.nz/news/business/578397/is-ai-really-coming-for-our-jobs-and-wages-past-predic...
5•billybuckwheat•1h ago•0 comments

Old fishing nets from France become vital against Russian drones in Ukraine

https://www.theguardian.com/world/2025/nov/08/old-fishing-nets-vital-protection-against-russian-d...
5•gnabgib•1h ago•0 comments

The Key Lesson I Learned After Nearly a Decade in Crypto

https://olshansky.substack.com/p/the-key-lesson-i-learned-after-nearly
1•Olshansky•1h ago•0 comments

Swift community meetup talks filmed in spatial video optimized for visionOS

https://vimeo.com/1062898354
1•Austin_Conlon•1h ago•0 comments

Giant DNA discovered hiding in your mouth

https://www.u-tokyo.ac.jp/focus/en/press/z0508_00421.html
3•manmal•1h ago•0 comments

Leveraging LLMs to uncover the shifts transforming markets

https://afridi.io/2025-shifts/
1•afridi•1h ago•0 comments

What Did Men Do to Deserve This?

https://www.newyorker.com/culture/the-weekend-essay/what-did-men-do-to-deserve-this
3•haltingproblem•1h ago•0 comments

Show HN: Hikugen – minimalistic LLM-generated web scrapers for structured data

https://github.com/goncharom/hikugen
2•goncharom•1h ago•0 comments

Research challenges the vicious cycle between distress and conspiracy beliefs

https://theconversation.com/new-research-challenges-the-idea-of-a-vicious-cycle-between-psycholog...
4•PaulHoule•1h ago•0 comments

Experiments in Autonomous AI Development

https://kenforthewin.github.io/blog/posts/experiments-in-autonomous-dev/
1•kenforthewin•1h ago•0 comments