Skip to content

Commit 3cd15f0

Browse files
feat(api): api update
1 parent bcb729d commit 3cd15f0

56 files changed

Lines changed: 1785 additions & 3920 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
name: CI
22
on:
33
push:
4-
branches-ignore:
5-
- 'generated'
6-
- 'codegen/**'
7-
- 'integrated/**'
8-
- 'stl-preview-head/**'
9-
- 'stl-preview-base/**'
4+
branches:
5+
- '**'
6+
- '!integrated/**'
7+
- '!stl-preview-head/**'
8+
- '!stl-preview-base/**'
9+
- '!generated'
10+
- '!codegen/**'
11+
- 'codegen/stl/**'
1012
pull_request:
1113
branches-ignore:
1214
- 'stl-preview-head/**'
@@ -17,7 +19,7 @@ jobs:
1719
timeout-minutes: 10
1820
name: lint
1921
runs-on: ${{ github.repository == 'stainless-sdks/brapi-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
20-
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
22+
if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata')
2123
steps:
2224
- uses: actions/checkout@v6
2325

@@ -36,7 +38,7 @@ jobs:
3638
run: ./scripts/lint
3739

3840
build:
39-
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
41+
if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata')
4042
timeout-minutes: 10
4143
name: build
4244
permissions:
@@ -61,14 +63,18 @@ jobs:
6163
run: rye build
6264

6365
- name: Get GitHub OIDC Token
64-
if: github.repository == 'stainless-sdks/brapi-python'
66+
if: |-
67+
github.repository == 'stainless-sdks/brapi-python' &&
68+
!startsWith(github.ref, 'refs/heads/stl/')
6569
id: github-oidc
6670
uses: actions/github-script@v8
6771
with:
6872
script: core.setOutput('github_token', await core.getIDToken());
6973

7074
- name: Upload tarball
71-
if: github.repository == 'stainless-sdks/brapi-python'
75+
if: |-
76+
github.repository == 'stainless-sdks/brapi-python' &&
77+
!startsWith(github.ref, 'refs/heads/stl/')
7278
env:
7379
URL: https://pkg.stainless.com/s
7480
AUTH: ${{ steps.github-oidc.outputs.github_token }}

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.prism.log
2+
.stdy.log
23
_dev
34

45
__pycache__

‎.stats.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 11
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/alisson%2Fbrapi-1e2cbfa512cbc93a24e96be3befafd915d8e48fd046d625f6374525b0c135753.yml
3-
openapi_spec_hash: c2bcb76a765ec4725c2c22be89be8a81
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/alisson%2Fbrapi-19f807c15a2482f7cf7c1dfdc4e008daf730c16a513cea7d3d1a63c4c9bcc05b.yml
3+
openapi_spec_hash: 1370c6eb457d8332148785e64e33c695
44
config_hash: 6f10a67950f65bf850612b59838ad03b

‎README.md‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ pip install brapi
2525
The full API of this library can be found in [api.md](api.md).
2626

2727
```python
28-
import os
2928
from brapi import Brapi
3029

3130
client = Brapi(
32-
api_key=os.environ.get("BRAPI_API_KEY"), # This is the default and can be omitted
31+
api_key="My API Key",
3332
# defaults to "production".
3433
environment="environment_1",
3534
)
@@ -40,22 +39,16 @@ quote = client.quote.retrieve(
4039
print(quote.requested_at)
4140
```
4241

43-
While you can provide an `api_key` keyword argument,
44-
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
45-
to add `BRAPI_API_KEY="My API Key"` to your `.env` file
46-
so that your API Key is not stored in source control.
47-
4842
## Async usage
4943

5044
Simply import `AsyncBrapi` instead of `Brapi` and use `await` with each API call:
5145

5246
```python
53-
import os
5447
import asyncio
5548
from brapi import AsyncBrapi
5649

5750
client = AsyncBrapi(
58-
api_key=os.environ.get("BRAPI_API_KEY"), # This is the default and can be omitted
51+
api_key="My API Key",
5952
# defaults to "production".
6053
environment="environment_1",
6154
)
@@ -87,15 +80,14 @@ pip install brapi[aiohttp]
8780
Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:
8881

8982
```python
90-
import os
9183
import asyncio
9284
from brapi import DefaultAioHttpClient
9385
from brapi import AsyncBrapi
9486

9587

9688
async def main() -> None:
9789
async with AsyncBrapi(
98-
api_key=os.environ.get("BRAPI_API_KEY"), # This is the default and can be omitted
90+
api_key="My API Key",
9991
http_client=DefaultAioHttpClient(),
10092
) as client:
10193
quote = await client.quote.retrieve(
@@ -129,7 +121,9 @@ All errors inherit from `brapi.APIError`.
129121
import brapi
130122
from brapi import Brapi
131123

132-
client = Brapi()
124+
client = Brapi(
125+
api_key="My API Key",
126+
)
133127

134128
try:
135129
client.quote.retrieve(
@@ -172,6 +166,7 @@ from brapi import Brapi
172166

173167
# Configure the default for all requests:
174168
client = Brapi(
169+
api_key="My API Key",
175170
# default is 2
176171
max_retries=0,
177172
)
@@ -192,12 +187,14 @@ from brapi import Brapi
192187

193188
# Configure the default for all requests:
194189
client = Brapi(
190+
api_key="My API Key",
195191
# 20 seconds (default is 1 minute)
196192
timeout=20.0,
197193
)
198194

199195
# More granular control:
200196
client = Brapi(
197+
api_key="My API Key",
201198
timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
202199
)
203200

@@ -244,7 +241,9 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
244241
```py
245242
from brapi import Brapi
246243

247-
client = Brapi()
244+
client = Brapi(
245+
api_key="My API Key",
246+
)
248247
response = client.quote.with_raw_response.retrieve(
249248
tickers="REPLACE_ME",
250249
)
@@ -323,6 +322,7 @@ import httpx
323322
from brapi import Brapi, DefaultHttpxClient
324323

325324
client = Brapi(
325+
api_key="My API Key",
326326
# Or use the `BRAPI_BASE_URL` env var
327327
base_url="http://my.test.server.example.com:8083",
328328
http_client=DefaultHttpxClient(
@@ -345,7 +345,9 @@ By default the library closes underlying HTTP connections whenever the client is
345345
```py
346346
from brapi import Brapi
347347

348-
with Brapi() as client:
348+
with Brapi(
349+
api_key="My API Key",
350+
) as client:
349351
# make requests here
350352
...
351353

‎api.md‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ Types:
55
```python
66
from brapi.types import (
77
BalanceSheetEntry,
8-
CashflowEntry,
9-
DefaultKeyStatisticsEntry,
108
FinancialDataEntry,
11-
IncomeStatementEntry,
12-
ValueAddedEntry,
139
QuoteRetrieveResponse,
1410
QuoteListResponse,
1511
)
@@ -71,7 +67,7 @@ from brapi.types.v2 import InflationRetrieveResponse, InflationListAvailableResp
7167
Methods:
7268

7369
- <code title="get /api/v2/inflation">client.v2.inflation.<a href="./src/brapi/resources/v2/inflation.py">retrieve</a>(\*\*<a href="src/brapi/types/v2/inflation_retrieve_params.py">params</a>) -> <a href="./src/brapi/types/v2/inflation_retrieve_response.py">InflationRetrieveResponse</a></code>
74-
- <code title="get /api/v2/inflation/available">client.v2.inflation.<a href="./src/brapi/resources/v2/inflation.py">list_available</a>(\*\*<a href="src/brapi/types/v2/inflation_list_available_params.py">params</a>) -> <a href="./src/brapi/types/v2/inflation_list_available_response.py">InflationListAvailableResponse</a></code>
70+
- <code title="get /api/v2/inflation/available">client.v2.inflation.<a href="./src/brapi/resources/v2/inflation.py">list_available</a>() -> <a href="./src/brapi/types/v2/inflation_list_available_response.py">InflationListAvailableResponse</a></code>
7571

7672
## PrimeRate
7773

@@ -84,4 +80,4 @@ from brapi.types.v2 import PrimeRateRetrieveResponse, PrimeRateListAvailableResp
8480
Methods:
8581

8682
- <code title="get /api/v2/prime-rate">client.v2.prime_rate.<a href="./src/brapi/resources/v2/prime_rate.py">retrieve</a>(\*\*<a href="src/brapi/types/v2/prime_rate_retrieve_params.py">params</a>) -> <a href="./src/brapi/types/v2/prime_rate_retrieve_response.py">PrimeRateRetrieveResponse</a></code>
87-
- <code title="get /api/v2/prime-rate/available">client.v2.prime_rate.<a href="./src/brapi/resources/v2/prime_rate.py">list_available</a>(\*\*<a href="src/brapi/types/v2/prime_rate_list_available_params.py">params</a>) -> <a href="./src/brapi/types/v2/prime_rate_list_available_response.py">PrimeRateListAvailableResponse</a></code>
83+
- <code title="get /api/v2/prime-rate/available">client.v2.prime_rate.<a href="./src/brapi/resources/v2/prime_rate.py">list_available</a>() -> <a href="./src/brapi/types/v2/prime_rate_list_available_response.py">PrimeRateListAvailableResponse</a></code>

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ authors = [
1111
dependencies = [
1212
"httpx>=0.23.0, <1",
1313
"pydantic>=1.9.0, <3",
14-
"typing-extensions>=4.10, <5",
14+
"typing-extensions>=4.14, <5",
1515
"anyio>=3.5.0, <5",
1616
"distro>=1.7.0, <2",
1717
"sniffio",

‎src/brapi/_client.py‎

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,19 @@ def __init__(
135135

136136
@cached_property
137137
def quote(self) -> QuoteResource:
138+
"""Consulte informações detalhadas sobre ações, BDRs, ETFs e índices da B3.
139+
140+
Obtenha preços em tempo real, dados fundamentalistas, históricos e dividendos.
141+
"""
138142
from .resources.quote import QuoteResource
139143

140144
return QuoteResource(self)
141145

142146
@cached_property
143147
def available(self) -> AvailableResource:
148+
"""
149+
Ferramentas auxiliares para descobrir ativos disponíveis e verificar a saúde da API.
150+
"""
144151
from .resources.available import AvailableResource
145152

146153
return AvailableResource(self)
@@ -164,12 +171,6 @@ def with_streaming_response(self) -> BrapiWithStreamedResponse:
164171
def qs(self) -> Querystring:
165172
return Querystring(array_format="comma")
166173

167-
@property
168-
@override
169-
def auth_headers(self) -> dict[str, str]:
170-
api_key = self.api_key
171-
return {"Authorization": f"Bearer {api_key}"}
172-
173174
@property
174175
@override
175176
def default_headers(self) -> dict[str, str | Omit]:
@@ -347,12 +348,19 @@ def __init__(
347348

348349
@cached_property
349350
def quote(self) -> AsyncQuoteResource:
351+
"""Consulte informações detalhadas sobre ações, BDRs, ETFs e índices da B3.
352+
353+
Obtenha preços em tempo real, dados fundamentalistas, históricos e dividendos.
354+
"""
350355
from .resources.quote import AsyncQuoteResource
351356

352357
return AsyncQuoteResource(self)
353358

354359
@cached_property
355360
def available(self) -> AsyncAvailableResource:
361+
"""
362+
Ferramentas auxiliares para descobrir ativos disponíveis e verificar a saúde da API.
363+
"""
356364
from .resources.available import AsyncAvailableResource
357365

358366
return AsyncAvailableResource(self)
@@ -376,12 +384,6 @@ def with_streaming_response(self) -> AsyncBrapiWithStreamedResponse:
376384
def qs(self) -> Querystring:
377385
return Querystring(array_format="comma")
378386

379-
@property
380-
@override
381-
def auth_headers(self) -> dict[str, str]:
382-
api_key = self.api_key
383-
return {"Authorization": f"Bearer {api_key}"}
384-
385387
@property
386388
@override
387389
def default_headers(self) -> dict[str, str | Omit]:
@@ -486,12 +488,19 @@ def __init__(self, client: Brapi) -> None:
486488

487489
@cached_property
488490
def quote(self) -> quote.QuoteResourceWithRawResponse:
491+
"""Consulte informações detalhadas sobre ações, BDRs, ETFs e índices da B3.
492+
493+
Obtenha preços em tempo real, dados fundamentalistas, históricos e dividendos.
494+
"""
489495
from .resources.quote import QuoteResourceWithRawResponse
490496

491497
return QuoteResourceWithRawResponse(self._client.quote)
492498

493499
@cached_property
494500
def available(self) -> available.AvailableResourceWithRawResponse:
501+
"""
502+
Ferramentas auxiliares para descobrir ativos disponíveis e verificar a saúde da API.
503+
"""
495504
from .resources.available import AvailableResourceWithRawResponse
496505

497506
return AvailableResourceWithRawResponse(self._client.available)
@@ -511,12 +520,19 @@ def __init__(self, client: AsyncBrapi) -> None:
511520

512521
@cached_property
513522
def quote(self) -> quote.AsyncQuoteResourceWithRawResponse:
523+
"""Consulte informações detalhadas sobre ações, BDRs, ETFs e índices da B3.
524+
525+
Obtenha preços em tempo real, dados fundamentalistas, históricos e dividendos.
526+
"""
514527
from .resources.quote import AsyncQuoteResourceWithRawResponse
515528

516529
return AsyncQuoteResourceWithRawResponse(self._client.quote)
517530

518531
@cached_property
519532
def available(self) -> available.AsyncAvailableResourceWithRawResponse:
533+
"""
534+
Ferramentas auxiliares para descobrir ativos disponíveis e verificar a saúde da API.
535+
"""
520536
from .resources.available import AsyncAvailableResourceWithRawResponse
521537

522538
return AsyncAvailableResourceWithRawResponse(self._client.available)
@@ -536,12 +552,19 @@ def __init__(self, client: Brapi) -> None:
536552

537553
@cached_property
538554
def quote(self) -> quote.QuoteResourceWithStreamingResponse:
555+
"""Consulte informações detalhadas sobre ações, BDRs, ETFs e índices da B3.
556+
557+
Obtenha preços em tempo real, dados fundamentalistas, históricos e dividendos.
558+
"""
539559
from .resources.quote import QuoteResourceWithStreamingResponse
540560

541561
return QuoteResourceWithStreamingResponse(self._client.quote)
542562

543563
@cached_property
544564
def available(self) -> available.AvailableResourceWithStreamingResponse:
565+
"""
566+
Ferramentas auxiliares para descobrir ativos disponíveis e verificar a saúde da API.
567+
"""
545568
from .resources.available import AvailableResourceWithStreamingResponse
546569

547570
return AvailableResourceWithStreamingResponse(self._client.available)
@@ -561,12 +584,19 @@ def __init__(self, client: AsyncBrapi) -> None:
561584

562585
@cached_property
563586
def quote(self) -> quote.AsyncQuoteResourceWithStreamingResponse:
587+
"""Consulte informações detalhadas sobre ações, BDRs, ETFs e índices da B3.
588+
589+
Obtenha preços em tempo real, dados fundamentalistas, históricos e dividendos.
590+
"""
564591
from .resources.quote import AsyncQuoteResourceWithStreamingResponse
565592

566593
return AsyncQuoteResourceWithStreamingResponse(self._client.quote)
567594

568595
@cached_property
569596
def available(self) -> available.AsyncAvailableResourceWithStreamingResponse:
597+
"""
598+
Ferramentas auxiliares para descobrir ativos disponíveis e verificar a saúde da API.
599+
"""
570600
from .resources.available import AsyncAvailableResourceWithStreamingResponse
571601

572602
return AsyncAvailableResourceWithStreamingResponse(self._client.available)

0 commit comments

Comments
 (0)