This paper contributes to the study of rank-metric codes from an algebraic and combinatorial point of view. We introduce q-polymatroids, the q-analogue of polymatroids, and develop their basic properties. We associate a pair of q-polymatroids to a rank-metric codes and show that several invariants and structural properties of the code, such as generalized weights, the property of being MRD or an optimal anticode, and duality, are captured by the associated combinatorial object.We start by establishing the notation and the definitions used throughout the paper.Notation 1.1. In the sequel, we fix integers n, m ≥ 2 and a prime power q. For an integer t, we let [t] := {1, ..., t}. We denote by F q the finite field with q elements. The space of n × m matrices with entries in F q is denoted by Mat. Up to transposition, we assume without loss of generality that n ≤ m. We let Mat(J, c) = {M ∈ Mat | colsp(M ) ⊆ J} and Mat(J, r) = {M ∈ Mat | rowsp(M ) ⊆ J}.Throughout the paper, we only consider linear codes. All dimensions are computed over F q , unless otherwise stated.