Saravanan666/pypi-org huggingface dataset:
Package: pydantic-settings-file-envar
pydantic-settings-file-envarSupport for loadingpydantic-settingsfrom files, using the_FILEenvironment variable suffix pattern commonly used in container images,
especially official Docker images.If you have a setting calledfoo, by defaultpydantic-settingswill load it
from an environment variableFOO. Withpydantic-settings-file-envar, if an
environment variableFOO_FILE=/a/b/foois set, the secret's value will be
loaded from the file at/a/b/foo.Note that pydantic-settingshas built-in support for loading secrets from files,
so that may be all you need. It's different from the_FILEenvar pattern in
that it expects a specific directory to be specified, which contains
appropriately-named secret files.Install$pipinstallpydantic-settings-file-envarUsageTo use_FILEenvar settings, override thesettings_customise_sources()class
method of your settings class to include theFileSuffixEnvSettingsSourcethis
package provides:frompydantic_settings_file_envarimportFileSuffixEnvSettingsSource# ...classExampleSettings(BaseSettings):threshold:intlaunch_code:str@classmethoddefsettings_customise_sources(cls,settings_cls:Type[BaseSettings],init_settings:PydanticBaseSettingsSource,env_settings:PydanticBaseSettingsSource,dotenv_settings:PydanticBaseSettingsSource,file_secret_settings:PydanticBaseSettingsSource,)->Tuple[PydanticBaseSettingsSource,...]:# Adding FileSuffixEnvSettingsSource enables _FILE envarsreturn(init_settings,env_settings,FileSuffixEnvSettingsSource(settings_cls))If you place it after the defaultenv_settingssource,_FILEenvironment
variable will only be used if a regular environment variable is not set. Thepydantic-settings docs have more details on configuring settings sources.Example program & Docker imageThe./exampledir contains an example command-line program that
loads settings using regular or_FILEenvars.Try it like this:$cdexample$poetryinstall--withlocal$poetryshell$echo-nsecret-from-file>/tmp/secret$THRESHOLD=9000LAUNCH_CODE_FILE=/tmp/secretfile-envar-exampleLoaded settings: threshold=9000 launch_code='secret-from-file'Or the Docker image:$# build the example image$dockerbuildxbakeexample[+] Building 5.2s (12/12) FINISHED                                                                         ...=> => naming to docker.io/library/file-envar-example$echo-nsecret-from-file>/tmp/secret$dockercontainerrun--rm-v/tmp:/secrets-eTHRESHOLD=9000-eLAUNCH_CODE_FILE=/secrets/secretfile-envar-exampleLoaded settings: threshold=9000 launch_code='secret-from-file'DevelopingSeedocs/dev.md.
Package: pydantic-settings-yaml
pydantic-settings-yamlNote: 2.x needs Pydantic>2.0,<3.0. Install 1.x if you still need Pydantic 1.x.Yaml support for Pydantic settings. Load a yaml config file
as nested Pydantic models.Allows to usefile:xxxxplaceholders in the yaml config file
for secrets. A placeholder is replaced with the contents of the
file. Paths are relative to the 'secrets_dir' setting (see below).Usage$cat /config/config.yamldatabase: 
  password: <file:database_password>
  username: my_database_username$cat /secrets/database_passwordmy_secret_database_passwordPython code example:from pydantic import BaseModel
    from pydantic_settings_yaml import YamlBaseSettings
    from pydantic_settings import SettingsConfigDict

    class Database(BaseModel):
        username: str
        password: str


    class Settings(YamlBaseSettings):
        database: Database

        # configure paths to secrets directory and YAML config file
        model_config = SettingsConfigDict(
            secrets_dir="/secrets", yaml_file="/config/config.yaml")

    settings = Settings()

    assert settings.dict() == {
        "database": {
            "password": "my_secret_database_password", 
            "username": "my_database_username"
        }
    }
Package: pydantic-shodan
pydantic-shodanPython 3 library containing Pydantic models for parsing and validatingShodan banners.AboutIt is based on theJSON schemaprovided by Shodan.Installationpipinstallpydantic-shodanExampleimportjsonfrompydantic_shodanimportBannerBANNER_JSON="""{"_shodan": {"id": "7383056c-d513-4b43-8734-b82d897888e6","options":{},"ptr": true,"module": "dns-udp","crawler": "9d8ac08f91f51fa9017965712c8fdabb4211dee4"},"hash": -553166942,"os": null,"opts": {"raw": "34ef818200010000000000000776657273696f6e0462696e640000100003"},"ip": 134744072,"isp": "Google","port": 53,"hostnames": ["dns.google"],"location": {"city": null,"region_code": null,"area_code": null,"longitude": -97.822,"country_code3": null,"country_name": "United States","postal_code": null,"dma_code": null,"country_code": "US","latitude": 37.751},"dns": {"resolver_hostname": null,"recursive": true,"resolver_id": null,"software": null},"timestamp": "2021-01-28T07:21:33.444507","domains": ["dns.google"],"org": "Google","data": "Recursion: enabled","asn": "AS15169","transport": "udp","ip_str": "8.8.8.8"}"""banner=Banner.parse_obj(json.loads(BANNER_JSON))
Package: pydantic-socket
pydantic_socket - Simple socket client and server withPydanticmodelsExamplesOutput examples are provided for simultaneous run of Server and Client examplesServerimportasyncioimportloggingimportpydantic_socketfrompydantic_socket.typesimportActionfrompydantic_socket.websocketimport(Server,ServerClient,)server=Server()classTestResponse(pydantic_socket.types.BaseModel):foo:int=1bar:str="bar"input:str|None=None# Register handler for certain action type@server.action_handler("hello")asyncdefhello_handler(s:Server,client:ServerClient,action:Action):logging.info(f"Hello,{action.payload.get('name','World')}!")# Will print:# INFO:root:Hello, pydantic_socket!asyncdeftest_handler(s:Server,client:ServerClient,action:Action):returnTestResponse(foo=1,bar="bar",input=action.payload.get('input'))# Another way to register handler for certain action typeserver.set_action_handler("test",test_handler)if__name__=='__main__':logging.basicConfig(level=logging.INFO)asyncio.run(server.run())Clientimportasyncioimportloggingimportpydanticfrompydantic_socket.typesimportActionfrompydantic_socket.websocketimportClientclient=Client("http://127.0.0.1:8080",auto_reconnect=False,client_id=1)classSomeActionInputPayload(pydantic.BaseModel):input:strasyncdefmain():# Establishing connection to serverasyncio.create_task(client.run())# Wait some time until connection is doneawaitasyncio.sleep(2)# Send actionawaitclient.send(Action(type='hello',payload={"name":"pydantic_socket"}))# Send and wait for responseresponse=awaitclient.request(Action(type='test',payload={"input":"Some Input"}))logging.info(f"Payload is:{response.payload}")# Will print:# INFO:root:Payload is: {'foo': 1, 'bar': 'bar', 'input': 'Some Input'}awaitclient.close()if__name__=='__main__':logging.basicConfig(level=logging.INFO)asyncio.run(main())LICENSEThis project is licensed under the terms of the MIT license.
Package: pydantic-spark
pydantic-sparkThis library can convert a pydantic class to a spark schema or generate python code from a spark schema.Installpipinstallpydantic-sparkPydantic class to spark schemaimportjsonfromtypingimportOptionalfrompydantic_spark.baseimportSparkBaseclassTestModel(SparkBase):key1:strkey2:intkey2:Optional[str]schema_dict:dict=TestModel.spark_schema()print(json.dumps(schema_dict))Coerce typePydantic-spark provides acoerce_typeoption that allows type coercion.
When applied to a field, pydantic-spark converts the column's data type to the specified coercion type.importjsonfrompydanticimportFieldfrompydantic_spark.baseimportSparkBase,CoerceTypeclassTestModel(SparkBase):key1:str=Field(extra_json_schema={"coerce_type":CoerceType.integer})schema_dict:dict=TestModel.spark_schema()print(json.dumps(schema_dict))Install for developersInstall packageRequirement: Poetry 1.*poetryinstallRun unit testspytest
coveragerun-mpytest# with coverage# or (depends on your local env)poetryrunpytest
poetryruncoveragerun-mpytest# with coverageRun lintingThe linting is checked in the github workflow. To fix and review issues run this:black.# Auto fix all issuesisort.# Auto fix all issuespflake.# Only display issues, fixing is manual
Package: pydantic-sqlalchemy
Pydantic-SQLAlchemyTools to generate Pydantic models from SQLAlchemy models.Still experimental.How to useQuick example:fromtypingimportListfrompydantic_sqlalchemyimportsqlalchemy_to_pydanticfromsqlalchemyimportColumn,ForeignKey,Integer,String,create_enginefromsqlalchemy.ext.declarativeimportdeclarative_basefromsqlalchemy.ormimportSession,relationship,sessionmakerBase=declarative_base()engine=create_engine("sqlite://",echo=True)classUser(Base):__tablename__="users"id=Column(Integer,primary_key=True)name=Column(String)fullname=Column(String)nickname=Column(String)addresses=relationship("Address",back_populates="user",cascade="all, delete, delete-orphan")classAddress(Base):__tablename__="addresses"id=Column(Integer,primary_key=True)email_address=Column(String,nullable=False)user_id=Column(Integer,ForeignKey("users.id"))user=relationship("User",back_populates="addresses")PydanticUser=sqlalchemy_to_pydantic(User)PydanticAddress=sqlalchemy_to_pydantic(Address)classPydanticUserWithAddresses(PydanticUser):addresses:List[PydanticAddress]=[]Base.metadata.create_all(engine)LocalSession=sessionmaker(bind=engine)db:Session=LocalSession()ed_user=User(name="ed",fullname="Ed Jones",nickname="edsnickname")address=Address(email_address="ed@example.com")address2=Address(email_address="eddy@example.com")ed_user.addresses=[address,address2]db.add(ed_user)db.commit()deftest_pydantic_sqlalchemy():user=db.query(User).first()pydantic_user=PydanticUser.from_orm(user)data=pydantic_user.dict()assertdata=={"fullname":"Ed Jones","id":1,"name":"ed","nickname":"edsnickname",}pydantic_user_with_addresses=PydanticUserWithAddresses.from_orm(user)data=pydantic_user_with_addresses.dict()assertdata=={"fullname":"Ed Jones","id":1,"name":"ed","nickname":"edsnickname","addresses":[{"email_address":"ed@example.com","id":1,"user_id":1},{"email_address":"eddy@example.com","id":2,"user_id":1},],}Release NotesLatest Changes0.0.9✨ Addpoetry-version-plugin, removeimportlib-metadatadependency. PR#32by@tiangolo.0.0.8.post1💚 Fix setting up Poetry for GitHub Action Publish. PR#23by@tiangolo.0.0.8⬆️ Upgradeimportlib-metadatato 3.0.0. PR#22by@tiangolo.👷 Add GitHub Action latest-changes. PR#20by@tiangolo.💚 Fix GitHub Actions Poetry setup. PR#21by@tiangolo.0.0.7Update requirements ofimportlib-metadatato support the latest version2.0.0. PR#11.0.0.6Add support for SQLAlchemy extended types likesqlalchemy-utc: UtcDateTime. PR#9.0.0.5Exclude columns before checking their Python types. PR#5by@ZachMyers3.0.0.4Do not include SQLAlchemy defaults in Pydantic models. PR#4.0.0.3Add support forexcludeto exclude columns from Pydantic model. PR#3.Add support for overriding the Pydanticconfig. PR#1by@pyropy.Add CI with GitHub Actions. PR#2.LicenseThis project is licensed under the terms of the MIT license.
Package: pydantic-sqlalchemy-2
Pydantic-SQLAlchemyTools to generate Pydantic models from SQLAlchemy models.Still experimental.How to useQuick example:fromtypingimportListfrompydantic_sqlalchemy_2importsqlalchemy_to_pydanticfromsqlalchemyimportColumn,ForeignKey,Integer,String,create_enginefromsqlalchemy.ext.declarativeimportdeclarative_basefromsqlalchemy.ormimportSession,relationship,sessionmakerBase=declarative_base()engine=create_engine("sqlite://",echo=True)classUser(Base):__tablename__="users"id=Column(Integer,primary_key=True)name=Column(String)fullname=Column(String)nickname=Column(String)addresses=relationship("Address",back_populates="user",cascade="all, delete, delete-orphan")classAddress(Base):__tablename__="addresses"id=Column(Integer,primary_key=True)email_address=Column(String,nullable=False)user_id=Column(Integer,ForeignKey("users.id"))user=relationship("User",back_populates="addresses")PydanticUser=sqlalchemy_to_pydantic(User)PydanticAddress=sqlalchemy_to_pydantic(Address)classPydanticUserWithAddresses(PydanticUser):addresses:List[PydanticAddress]=[]Base.metadata.create_all(engine)LocalSession=sessionmaker(bind=engine)db:Session=LocalSession()ed_user=User(name="ed",fullname="Ed Jones",nickname="edsnickname")address=Address(email_address="ed@example.com")address2=Address(email_address="eddy@example.com")ed_user.addresses=[address,address2]db.add(ed_user)db.commit()deftest_pydantic_sqlalchemy():user=db.query(User).first()pydantic_user=PydanticUser.from_orm(user)data=pydantic_user.dict()assertdata=={"fullname":"Ed Jones","id":1,"name":"ed","nickname":"edsnickname",}pydantic_user_with_addresses=PydanticUserWithAddresses.from_orm(user)data=pydantic_user_with_addresses.dict()assertdata=={"fullname":"Ed Jones","id":1,"name":"ed","nickname":"edsnickname","addresses":[{"email_address":"ed@example.com","id":1,"user_id":1},{"email_address":"eddy@example.com","id":2,"user_id":1},],}Release NotesLatest Changes0.0.2Versioning fix (sqlalchemy >= 2.0.0)0.0.1Forked fromtiangolo/pydantic-sqlalchemyAdded support for SQLAlchemy 2.0LicenseThis project is licensed under the terms of the MIT license.
Package: pydantic-sqs
pydantic-sqsConvert your pydantic models to and from AWS SQS messages.Main DependenciesPython +3.7pydanticaiobotocoreGetting Startedfrompydantic_sqsimportSQSModel,SQSQueuefrompydanticimportFieldimportasynciofrompprintimportpprintimportosclassThisModel(SQSModel):foo:str=Field(...,description="Foo")classThatModel(SQSModel):bar:str=Field(...,description="bar")asyncdefmain():queue_kwargs={"queue_url":os.environ.get("SQS_QUEUE_URL"),"endpoint_url":os.environ.get("SQS_ENDPOINT_URL",None),"use_ssl":os.environ.get("SQS_USE_SSL","true").lower()=="true",}ifqueue_kwargs["endpoint_url"]isNone:delqueue_kwargs["endpoint_url"]queue=SQSQueue(**queue_kwargs)queue.register_model(ThisModel)queue.register_model(ThatModel)this_thing=ThisModel(foo="1234")that_thing=ThatModel(bar="5678")awaitthis_thing.to_sqs()awaitthat_thing.to_sqs()new_things=awaitqueue.from_sqs(max_messages=10,wait_time_seconds=90)pprint(new_things)forthinginnew_things:awaitthing.delete_from_queue()print("deleted all the messages we got from the queue")pprint(new_things)if__name__=="__main__":asyncio.run(main())ExamplesExamples are in theexamples/directory of this repo.InstallationInstall the packagepip install pydantic-sqsContributingContributions are very welcome.
To learn more, see theContributor GuideLicenseLicensed under theMIT License
Package: pydantic-ssm-settings
pydantic-ssm-settingsReplace Pydantic's builtinSecret Supportwith a configuration provider that loads parameters fromAWS Systems Manager Parameter Store. Parameters are loadedlazily, meaning that they are only requested from AWS if they are not provided viastandard field value priority(i.e. initialiser, environment variable, or via.envfile).UsageThe simplest way to use this module is to inhert your settingsConfigclass fromAwsSsmSourceConfig. This will overwrite thefile_secret_settingssettings sourcewith theAwsSsmSettingsSource. Provide a prefix to SSM parameters via the_secrets_dirinitialiser value or thesecrets_dirConfig value.frompydanticimportBaseSettingsfrompydantic_ssm_settingsimportAwsSsmSourceConfigclassWebserviceSettings(BaseSettings):some_val:stranother_val:intclassConfig(AwsSsmSourceConfig):...SimpleSettings(_secrets_dir='/prod/webservice')The above example will attempt to retreive values from/prod/webservice/some_valand/prod/webservice/another_valif not provided otherwise.
Package: pydantic-tes
pydantic-tesA collection ofpydanticmodels forGA4GH Task Execution Service.In addition to the models, this package contains a lightweight client for TES based
on them usingrequestsand utilities for working and testing it againstFunnel-
a the TES implementation.This Python project can be installed from PyPI usingpip.$ python3 -m venv .venv
$ . .venv/bin/activate
$ pip install pydantic-tesCheckoutpy-tesfor an alternative set of Python models and an API client based on the
more lightweightattrspackage.History0.1.5 (2022-10-06)Messed up 0.1.4 release, retrying.0.1.4 (2022-10-06)Further hacking around funnel responses to produce validating responses.0.1.3 (2022-10-05)Another attempt at publishing types.0.1.2 (2022-10-05)Add support for Python 3.6.Add py.typed to package.0.1.1 (2022-09-29)Fixes to project publication scripts and process.0.1.0 (2022-09-29)Inital version.
Package: pydantic-tools
pydantic-toolsA set of tools for pydantic(i18n, alias(comming soon), etc.)Installationpip install pydantic-toolsi18nA simple examplefrompydantic_toolsimporti18nclassTestModel(i18n.BaseModel_i18n):name:strage:intclassConfig:locale="zh_cn"test=TestModel()pydantic.error_wrappers.ValidationError:2validationerrorsforTestModelname确保该值不缺失(type=value_error.missing)age确保该值不缺失(type=value_error.missing)Config availablelocale: The locale of the model, default isNone, which means no translation enabled, and the default error message will be used. Usepython -m pydantic_tools.i18n -lto show all available locales.locale_strict: Whether to raise an error when the locale is not found, default isFalse.translations: If specified, the error messages will be translated according to the given dict instead of the locale config. The dict should be like{"value_error.missing": "Missing"}. One oflocaleandtranslationsshould be specified, do not set both of them.extra_translations: If specified, an extra dict will be merged into the default translations. The dict should be like{"value_error.missing": "some msg"}.Show all available localespython-mpydantic_tools.i18n-lShow all available translationspython-mpydantic_tools.i18n-taliasComming soon
Package: pydantic-to-pyarrow
pydantic-to-pyarrowpydantic-to-pyarrow is a library for Python to help with conversion
of pydantic models to pyarrow schemas.pydanticis a Python library
for data validation, applying type hints / annotations. It enables
the creation of easy or complex data validation rules.pyarrowis a Python library
for using Apache Arrow, a development platform for in-memory analytics. The library
also enables easy writing to parquet files.Why might you want to convert models to schemas? One scenario is for a data
processing pipeline:Import / extract the data from its sourceValidate the data using pydanticProcess the data in pyarrow / pandas / polarsStore the raw and / or processed data in parquet.The easiest approach for steps 3 and 4 above is to let pyarrow infer
the schema from the data. The most involved approach is to
specify the pyarrow schema separate from the pydantic model. In the middle, many
application could benefit from converting the pydantic model to a
pyarrow schema. This library aims to achieve that.Installationpipinstallpydantic-to-pyarrowConversion TableThe below conversions still run into the possibility of
overflows in the Pyarrow types. For example, in Python 3
theinttype is unbounded, whereas the pa.int64() type has a fixed
maximum. In most cases, this should not be an issue, but if you are
concerned about overflows, you should not use this library and
should manually specify the full schema.Python / PydanticPyarrowOverflowstrpa.string()Literal[strings]pa.dictionary(pa.int32(), pa.string())...intpa.int64() if no minimum constraint, pa.uint64() if minimum is zeroYes, at 2^63 (for signed) or 2^64 (for unsigned)Literal[ints]pa.int64()Yes, at 2^63floatpa.float64()Yesdecimal.Decimalpa.decimal128 ONLY if supplying max_digits and decimal_places for pydantic fieldYes...datetime.datepa.date32()datetime.timepa.time64("us")datetime.datetimepa.timestamp("ms", tz=None) ONLY if param allow_losing_tz=Truepydantic.types.NaiveDatetimepa.timestamp("ms", tz=None)pydantic.types.AwareDatetimepa.timestamp("ms", tz=None) ONLY if param allow_losing_tz=True..Optional[...]The pyarrow field is nullablePydantic Modelpa.struct()List[...]pa.list_(...)An ExamplefromtypingimportList,OptionalfrompydanticimportBaseModelfrompydantic_to_pyarrowimportget_pyarrow_schemaclassNestedModel(BaseModel):str_field:strclassMyModel(BaseModel):int_field:intopt_str_field:Optional[str]py310_opt_str_field:str|Nonenested:List[NestedModel]pa_schema=get_pyarrow_schema(MyModel)print(pa_schema)#> int_field: int64 not null#> opt_str_field: string#> py310_opt_str_field: string#> nested: list<item: struct<str_field: string not null>> not null#>   child 0, item: struct<str_field: string not null>#>       child 0, str_field: string not nullDevelopmentPrerequisites:Any Python 3.8 through 3.11poetryfor dependency managementgitmake
Package: pydantic-to-typescript
pydantic-to-typescriptA simple CLI tool for converting pydantic models into typescript interfaces. Useful for any scenario in which python and javascript applications are interacting, since it allows you to have a single source of truth for type definitions.This tool requires that you have the lovely json2ts CLI utility installed. Instructions can be found here:https://www.npmjs.com/package/json-schema-to-typescriptInstallation$pipinstallpydantic-to-typescriptCLIPropDescription‑‑modulename or filepath of the python module you would like to convert. All the pydantic models within it will be converted to typescript interfaces. Discoverable submodules will also be checked.‑‑outputname of the file the typescript definitions should be written to. Ex: './frontend/apiTypes.ts'‑‑excludename of a pydantic model which should be omitted from the resulting typescript definitions. This option can be defined multiple times, ex:--exclude Foo --exclude Barto exclude both the Foo and Bar models from the output.‑‑json2ts‑cmdoptional, the command used to invoke json2ts. The default is 'json2ts'. Specify this if you have it installed locally (ex: 'yarn json2ts') or if the exact path to the executable is required (ex: /myproject/node_modules/bin/json2ts)UsageDefine your pydantic models (ex: /backend/api.py):fromfastapiimportFastAPIfrompydanticimportBaseModelfromtypingimportList,Optionalapi=FastAPI()classLoginCredentials(BaseModel):username:strpassword:strclassProfile(BaseModel):username:strage:Optional[int]hobbies:List[str]classLoginResponseData(BaseModel):token:strprofile:Profile@api.post('/login/',response_model=LoginResponseData)deflogin(body:LoginCredentials):profile=Profile(**body.dict(),age=72,hobbies=['cats'])returnLoginResponseData(token='very-secure',profile=profile)Execute the command for converting these models into typescript definitions, via:$pydantic2ts--modulebackend.api--output./frontend/apiTypes.tsor:$pydantic2ts--module./backend/api.py--output./frontend/apiTypes.tsor:frompydantic2tsimportgenerate_typescript_defsgenerate_typescript_defs("backend.api","./frontend/apiTypes.ts")The models are now defined in typescript.../* tslint:disable *//**/* This file was automatically generated from pydantic models by running pydantic2ts./* Do not modify it by hand - just update the pydantic models and then re-run the script*/exportinterfaceLoginCredentials{username:string;password:string;}exportinterfaceLoginResponseData{token:string;profile:Profile;}exportinterfaceProfile{username:string;age?:number;hobbies:string[];}...and can be used in your typescript code with complete confidence.import{LoginCredentials,LoginResponseData}from"./apiTypes.ts";asyncfunctionlogin(credentials:LoginCredentials,resolve:(data:LoginResponseData)=>void,reject:(error:string)=>void){try{constresponse:Response=awaitfetch("/login/",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(credentials),});constdata:LoginResponseData=awaitresponse.json();resolve(data);}catch(error){reject(error.message);}}