Skip to content
Python requirements.txt generic iterator parser for Nim
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.


  • Python requirements.txt generic iterator parser for Nim.
  • Python RECORDS file parser, is a custom header-less CSV file used by Python packages.
  • No Regex used in the making of this film!


for it in requirements("requirements.txt"):  ## requirements is string
  echo it

for it in requirements(open("requirements.txt")): ## requirements is File
  echo it

for it in requirements(newStringStream(staticRead("requirements.txt"))): ## requirements is StringStream
  echo it

1 Input argument can be filename: string | StringStream | File. Based from the official spec:


Yields 1 tuple per parsed line:

  • line Current line being parsed (42, etc).
  • editable Boolean whether this requirement is "editable".
  • specifier Boolean whether a version specifier is used ("flask>=1.5" is true, "flask" is false)
  • vcs Distributed version control system used ("git", "hg", etc).
  • protocol Network protocol for transports ("http", "https", "ssh", etc)
  • name Package name parsed ("pytest", etc).
  • version Package version string ("1.2.9", etc).
  • uri URL if this requirement of Uri type ("", etc).
  • extras Sequence of strings with a list of extras ("flask[extra1, extra2]" is @["extra1", "extra2"])
  • blanks Current count of comments, blank lines, empty lines, etc (42, etc).
  • private Current count of Private custom repositories (Not PYPI).
  • nested Current count of recursively Nested requirements.txt files (42, etc).

Example Output:

(line: 9, editable: false, specifier: true, vcs: "git", protocol: "https", version: "1.6.0", name: "numpy", url: "", blanks: 1, nested: 0, private: 0, extras: @["full", "pdf"])

If you need a seq of tuple use sequtils.toSeq. It uses Effects Tags ReadIOEffect, WriteIOEffect.


nimble install requirementstxt


$ nimble test

[Suite] Requirements.txt generic parser tests
  [OK] Big requirements.txt parsing
  [OK] Empty requirements.txt parsing
  [OK] Empty requirements.txt parsing 2
   Success: Execution finished
   Success: All tests passed

Test is using a big and complex requirements.txt.


  • runnableExamples included.
nim doc requirementstxt.nim

Supported DVCS

  • git
  • git+https
  • git+ssh
  • git+git
  • hg+http
  • hg+https
  • hg+static-http
  • hg+ssh
  • svn
  • svn+svn
  • svn+http
  • svn+https
  • svn+ssh
  • bzr+http
  • bzr+https
  • bzr+ssh
  • bzr+sftp
  • bzr+ftp
  • bzr+lp
  • No DVCS


  • None.


  • None.


Stars over time


  • Why a generic iterator ?.

Generic so you can use string or StringStream or File.

iterator because requirements.txt are meant to have 1 dependency per line.

If you are familiar with Python, Nim iterator is like Python generator, Nim tuple is like Python NamedTuple.

⬆️ ⬆️ ⬆️ ⬆️

You can’t perform that action at this time.