Battlefield Portal web-grpc
This npm and python package can be used to directly call the https://portal.battlefield.com/ api. we're making this public since you can read the javascript of the website and figure this out yourself easily anyway, but we want to make sure only 1 github repo has to be kept in sync with the api and the rest that uses it just has to update a package and a few code changes to still have it work.
https://www.npmjs.com/package/bfportal-grpc-bf6
https://pypi.org/project/bfportal_grpc_bf6/
Typescript usage example
import { createChannel, Metadata, createClientFactory } from "nice-grpc-web";
import { play, access_token } from "bfportal-grpc-bf6";
(async () => {
const accessToken = await getBf6GatewaySession({ sid: "", remid: "" });
const session = await access_token.getWebAccessToken(accessToken!);
const channel = createChannel("https://santiago-prod-wgw-envoy.ops.dice.se");
const client = createClientFactory().use((call, options) =>
call.next(call.request, {
...options,
metadata: Metadata(options.metadata)
.set('x-dice-tenancy', 'prod_default-prod_default-santiago-common')
.set('x-gateway-session-id', session.sessionId)
.set('x-grpc-web', '1')
}),
);
const webPlayClient = client.create(play.WebPlayDefinition, channel);
const response = await webPlayClient.getPlayElement({ id: "c7dff320-a543-11f0-8e01-a29ee389d262", includeDenied: true });
console.log(response.playElement?.name);
})()
Python usage example
from bfportal_grpc_bf6 import play_pb2, converter, access_token
import httpcore
async def main():
cookie = access_token.Cookie(sid="", remid="")
token = await access_token.getBf6GatewaySession(cookie)
res = await access_token.get_web_access_token(token)
session_id = res.get("sessionId", "")
serialized_msg = play_pb2.GetPlayElementRequest(
id=playground_id, includeDenied=True
).SerializeToString()
async with httpcore.AsyncConnectionPool(http2=True, keepalive_expiry=30) as session:
msg = converter.to_length_prefixed_msg(serialized_msg)
response = await session.request(
"POST",
"https://santiago-prod-wgw-envoy.ops.dice.se/santiago.web.play.WebPlay/getPlayElement",
headers={
"content-type": "application/grpc-web+proto",
"x-dice-tenancy": "prod_default-prod_default-santiago-common",
"x-gateway-session-id": session_id,
"x-grpc-web": "1",
"x-user-agent": "grpc-web-javascript/0.1",
},
content=msg,
)
serialized_message = converter.from_length_prefixed_msg(response.content)
message = play_pb2.PlayElementResponse()
message.ParseFromString(serialized_message)
print(message.playElement.name)
if __name__ == "__main__":
asyncio.run(main())
Building the proto translations
Build the typescript variant with with:
./node_modules/.bin/grpc_tools_node_protoc \
--plugin=protoc-gen-ts_proto=./node_modules/.bin/protoc-gen-ts_proto \
--ts_proto_out=./src/proto \
--ts_proto_opt=env=browser,outputServices=nice-grpc,outputServices=generic-definitions,outputJsonMethods=false,useExactTypes=false \
--proto_path=./proto \
./proto/authentication.proto ./proto/localization.proto ./proto/play.proto ./proto/reporting.proto
Building for python requires grpcio-tools, which can be installed with:
pip3 install grpcio-tools
And can be build with:
poetry run compile-proto
Python package used: https://github.com/romnn/proto-compile
Pushing your changes
Package versions can be made with npm run build and npm version patch git push --tags origin main to release.
for python poetry build.
Example library used for this project: https://github.com/tomchen/example-typescript-package
Metadata
Release files for bfportal_grpc_bf6 0.1.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bfportal_grpc_bf6-0.1.12.tar.gz | 32.5 kB | Without provenance | Details for bfportal_grpc_bf6-0.1.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bfportal_grpc_bf6-0.1.12-cp313-cp313-macosx_26_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 26.0+ ARM64 | Details for bfportal_grpc_bf6-0.1.12-cp313-cp313-macosx_26_0_arm64.whl |
Total release size: 71.9 kB
Release files / bfportal_grpc_bf6-0.1.12.tar.gz
| Download URL | bfportal_grpc_bf6-0.1.12.tar.gz |
|---|---|
| Size | 32.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
637b6628efad4d41859a0e3b7fd4906658195b04dfa9ddf60f72b3abb31273a4
|
|
BLAKE2b-256 checksum How to use checksums |
3f7159e184186e1df871785bdd41df358e116c06c2828fc891f8bdb031270fe0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.13.14 Darwin/25.5.0
|
Release files / bfportal_grpc_bf6-0.1.12-cp313-cp313-macosx_26_0_arm64.whl
| Download URL | bfportal_grpc_bf6-0.1.12-cp313-cp313-macosx_26_0_arm64.whl |
|---|---|
| Size | 39.3 kB |
| Tags | CPython 3.13 macOS 26.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
c0f8010d94b1f3faa88809df1d4359388ea9ed4d370e5c4fc5f6d445c08a4f73
|
|
BLAKE2b-256 checksum How to use checksums |
41617cc380c8bb354dc91537ca1527e81f8ed915f613fbdc89306d9cc4463df4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.13.14 Darwin/25.5.0
|
Security for bfportal_grpc_bf6 0.1.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.