There Are A Few Lower Level Options (My favorite is Glyph of Warding)
Before we get into the answer, let me point out that this question is complicated by several details. First, an unborn fetus is likely considered to have "total cover," and thus is not a valid target for many spells. Also, there is RAW support for the idea that in DnD, gender and sex may include other categories than "male and female." On page 121 of the PHB, it states:
You don't need to be confined to binary notions of sex and gender.
So depending on your DM, it's entirely possible that this question could be harder to answer than it initially appears. But there are options available to a clever player or DM which could at least give you hints at the sex of the anticipated new arrival.
Augury Is Viable, But Unclear
Naturally, spells like "Wish" or "Commune" could be good options (the pros and cons of these are mentioned in detail in other answers). But these spells require higher level casters which you might not have access to. If you're hoping to use the fewest resources possible and get some viable information, your best bet is likely the 2nd level spell Augury.
Augury is a Ritual spell, so provided you have access to a class with Ritual casting you will not even need to spend a spell slot. And since its target is "self," you won't have to worry about the fetus having total cover. There are two major limitations of Augury. First, you must inquire about a course of action you plan to take in the next 30 minutes. Second, you only get vague answers: essentially "good," "bad," "mixed," or "neither good nor bad."
You could take your chances with Augury, perhaps choosing the action under investigation to be "Buying a girl's blouse for when this baby is born." You could interpret a "good" result as saying you've correctly guessed the fetus's sex, and a "bad" result as saying you haven't. However, it's possible the DM will consider an atypically colored garment to be "neither good nor bad" for the purposes of the spell. And even if you get a "good' or "bad" result, it's worth noting that the DM doesn't have to tell you why a specific action yield that prediction in an Augury reading. You might get a result of "bad" based on buying a "girls'" outfit because the outfit is shoddily made, or the parents are allergic to the fabric. You wouldn't know whether or not the assumed sex of the wearer is related to Augury's outcome.
Glyph of Warding is likely your best bet
The spell Glyph of Warding's has an option to create a Spell Glyph. This will permit you to have a spell of your choosing be cast under specific circumstances, usually when a creature touches or approaches to within a certain distance of the Glyph. (NOTE: An errata clarified that this spell does not need to be harmful). According to Glyph of Warding's description (PHB, p. 246, bold added):
You can further refine the trigger so the spell activates only under certain circumstances or according to Physical Characteristics (such as height or weight), creature kind (for example, the ward could be set to affect Aberrations or drow), or Alignment.
You could set up a Glyph of Warding to cast a visible but harmless spell (such as Dancing Lights) if a humanoid male weighing less than 20 pounds was within 10 feet of the Glyph, then ask the pregnant mother to approach. According to the rules of Spell Glyph (ibid):
If the spell has a target, it Targets the creature that triggered the glyph. If the spell affects an area, the area is centered on that creature.
Since the fetus is behind total cover, it is essential that the spell stored in the Glyph does not have a target, or it will fail: again, Dancing Lights would be a valid example. You also do not have to worry about the area being "centered" on the fetus and thus hiding the effect within the womb, because the rules for casting spells with an area of effect state (PHB, p. 204):
If you place an area of effect at a point you can't see and an obstruction, such as a wall, is between you and that point, the point of origin comes into being on the near side of that obstruction.
Thus, the dancing lights will have an area of effect centered outside of the expectant mother, and will be visible. Note that the fetus was also not the "target" of the spell Glyph of Warding itself: it is merely the source of its activation. So as long as your DM considers the fetus to count as "a humanoid" in this setup, you will know whether or not the fetus's sex is male by whether or not this spell activates.
A few caveats: first, note that Glyph of Warding is not without costs. You'd need to spend at least a 3rd level spell slot, and also 200gp worth of powdered diamond which the spell would consume: a hefty cost at lower levels. Also, note that the Glyph would only be able to give binary answers in the form of activating or not: if you wanted to get a different outcome for a male or female fetus, you'd need to cast multiple instances of this spell with different triggers. And that may be a wise idea (in addition to letting you ascertain other details, such as the fetus's race), because if the spell does not activate, it is difficult to be sure why. For example, it might have activated because the spell does not consider an unborn fetus to be a "humanoid," or "male" yet (perhaps it has not developed enough to fit the definitions of either the spell would use). So the precise wording of the trigger may take some trial and error.
However, of your various options, Glyph of Warding is likely one of the best. It does not rely on the ability to predict the future, as it is assessing the present status of the fetus, and is capable of assessing the physical characteristics you're interested in.
A word about the future
A major advantage of Glyph of Warding is that it does not rely on abilities that predict the future. It would only be able to assess the current qualities of the fetus, and would not rely on what the future might hold.
That is significant, because in DnD neither sex nor gender is guaranteed to be fixed. Spells like True Polymorph and Wish allow any number of permanent changes to a creature's body, and even lower level spells like Alter Self might permit such changes temporarily.
I'm partly pointing these things out to clarify why divination magic might be unreliable in this case. But I'm also pointing it out to urge you to consider the possibilities of the fetus's ultimate fate. I do not know why it is important to your game that you find out the current sex of this fetus: maybe there is a prophecy, or laws of inheritance and/or succession that you're concerned with, or other such weighty reasons. But I urge you to keep an open mind.
Speaking purely based on the rules of the game that we are all playing: whatever the fetus is, that is not necessarily what they will ultimately be.