Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
pycountries provides the ISO enums for the standards:
pycountries can be used natively with pydantic >= 1.5 and python >= 3.8. It makes really easy to use fastapi and other related libraries.
pip install pycountries
Examples show how to use pycountries with pydantic + fastapi, but you can use it with pydantic and any other libraries.
pip install fastapi
pip install pycountries
When you have all required libraries you can quickstart with this code:
from decimal import Decimal
from fastapi import FastAPI
from pycountries import Country, Currency, Language
from pydantic import BaseModel, model_validator
app = FastAPI()
class IndexRequest(BaseModel):
country: Country
currency: Currency
amount: Decimal
language: Language
@model_validator(mode="after")
def validate_amount(self) -> "IndexRequest":
# TODO: Keep in mind, you need to handle exceptions raised by clean_amount method,
# otherwise Internal Server Error will be raised.
self.amount = self.currency.clean_amount(self.amount)
return self
class IndexResponse(BaseModel):
amount: Decimal
@app.post("/")
async def root(data: IndexRequest):
return IndexResponse(**data.model_dump())
curl -X POST -H "Content-Type: application/json" -d '{"country":"US", "currency":"USD", "amount":"20.20", "language":"eng"}' http://127.0.0.1:8000
{"amount":"20.20"}
curl -X POST -H "Content-Type: application/json" -d '{"country":"US", "currency":"USD", "amount":"-20.20", "language":"eng"}' http://127.0.0.1:8000
Internal Server Error
I'm still not sure about the logic, if you have any ideas please create a task here.
The problem here is that calling code is not unique per country. For example, at least 3 countries have code +1: United States, Canada, Barbados. To determine the country we need to see a prefix - N numbers after country code. And, looks like these prefixes are quite dynamic, so should be managed accordingly.
For now logic is:
It is very useful if you want to show phone dynamically. See an example below for more info.
from pycountries import Phone
# Return first match with different types
Phone(1) # Phone.BB
Phone("1") # Phone.BB
Phone("+1") # Phone.BB
# Result has changed, because results with prefixes in priority right now.
Phone(1, prefix=3) # Phone.UM
Phone(1, prefix=32) # Phone.UM
# Exact match found!
Phone(1, prefix=325) # Phone.US
There is a great library pycountry, but it is incompatible with enums, for sure enums can be generated dynamically, but python does not work good with dynamic enums, for example, you can not inherit from enums, annotations will be broken, etc. pycountries solves these issues and more. Soon pycountries will be providing other ISO standards related to countries.
python3.12 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Distributed under the MIT License. See LICENSE.md for more information.
https://www.buymeacoffee.com/aivCoffee
Hi all,
How are you? Hope You've enjoyed the project.
There are my contacts:
Project Link: https://github.com/koldakov/pycountries
Best regards,
FAQs
List of existing countries and currencies
We found that pycountries demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.