|
10 | 10 | ) |
11 | 11 | from .exceptions import ValidationError |
12 | 12 | from .models import DieselPrice, DieselStationsResponse, PriceAlert, Subscription, SubscriptionEvent |
13 | | -from .resource_validators import VALID_OPERATORS, format_date |
| 13 | +from .resource_validators import VALID_OPERATORS, format_date, normalize_api_number |
14 | 14 | from .resources._futures_slug import normalize_futures_slug |
15 | 15 | from .resources.subscriptions import SubscriptionEventsPage |
16 | 16 |
|
@@ -773,6 +773,135 @@ async def basin(self, name: str) -> Dict[str, Any]: |
773 | 773 | return response |
774 | 774 |
|
775 | 775 |
|
| 776 | +class AsyncWellProductionResource: |
| 777 | + """Async resource for US well production data (beta). |
| 778 | +
|
| 779 | + Mirror of ``oilpriceapi.resources.well_production.WellProductionResource``. |
| 780 | + """ |
| 781 | + |
| 782 | + def __init__(self, client): |
| 783 | + self.client = client |
| 784 | + |
| 785 | + async def summary(self) -> Dict[str, Any]: |
| 786 | + response = await self.client.request(method="GET", path="/v1/well-production") |
| 787 | + if "data" in response: |
| 788 | + return response["data"] |
| 789 | + return response |
| 790 | + |
| 791 | + async def states(self, period: Optional[str] = None, **params) -> Dict[str, Any]: |
| 792 | + if period is not None: |
| 793 | + params["period"] = period |
| 794 | + response = await self.client.request( |
| 795 | + method="GET", path="/v1/well-production/states", params=params |
| 796 | + ) |
| 797 | + if "data" in response: |
| 798 | + return response["data"] |
| 799 | + return response |
| 800 | + |
| 801 | + async def state( |
| 802 | + self, |
| 803 | + code: str, |
| 804 | + start_date: Optional[str] = None, |
| 805 | + end_date: Optional[str] = None, |
| 806 | + **params, |
| 807 | + ) -> Dict[str, Any]: |
| 808 | + if start_date is not None: |
| 809 | + params["start_date"] = start_date |
| 810 | + if end_date is not None: |
| 811 | + params["end_date"] = end_date |
| 812 | + response = await self.client.request( |
| 813 | + method="GET", path=f"/v1/well-production/states/{code}", params=params |
| 814 | + ) |
| 815 | + if "data" in response: |
| 816 | + return response["data"] |
| 817 | + return response |
| 818 | + |
| 819 | + async def well(self, api_number: str) -> Dict[str, Any]: |
| 820 | + normalized = normalize_api_number(api_number) |
| 821 | + response = await self.client.request( |
| 822 | + method="GET", path=f"/v1/well-production/wells/{normalized}" |
| 823 | + ) |
| 824 | + if "data" in response: |
| 825 | + return response["data"] |
| 826 | + return response |
| 827 | + |
| 828 | + async def top_producers( |
| 829 | + self, |
| 830 | + state_code: str = "TX", |
| 831 | + limit: int = 20, |
| 832 | + months: Optional[int] = None, |
| 833 | + **params, |
| 834 | + ) -> Dict[str, Any]: |
| 835 | + params["state_code"] = state_code |
| 836 | + params["limit"] = limit |
| 837 | + if months is not None: |
| 838 | + params["months"] = months |
| 839 | + response = await self.client.request( |
| 840 | + method="GET", path="/v1/well-production/top-producers", params=params |
| 841 | + ) |
| 842 | + if "data" in response: |
| 843 | + return response["data"] |
| 844 | + return response |
| 845 | + |
| 846 | + async def cycle_time( |
| 847 | + self, |
| 848 | + state: Optional[str] = None, |
| 849 | + start_date: Optional[str] = None, |
| 850 | + end_date: Optional[str] = None, |
| 851 | + operator: Optional[str] = None, |
| 852 | + formation: Optional[str] = None, |
| 853 | + lat: Optional[float] = None, |
| 854 | + lng: Optional[float] = None, |
| 855 | + radius_miles: Optional[float] = None, |
| 856 | + **params, |
| 857 | + ) -> Dict[str, Any]: |
| 858 | + filters = { |
| 859 | + "state": state, |
| 860 | + "start_date": start_date, |
| 861 | + "end_date": end_date, |
| 862 | + "operator": operator, |
| 863 | + "formation": formation, |
| 864 | + "lat": lat, |
| 865 | + "lng": lng, |
| 866 | + "radius_miles": radius_miles, |
| 867 | + } |
| 868 | + params.update({k: v for k, v in filters.items() if v is not None}) |
| 869 | + response = await self.client.request( |
| 870 | + method="GET", path="/v1/well-production/cycle-time", params=params |
| 871 | + ) |
| 872 | + if "data" in response: |
| 873 | + return response["data"] |
| 874 | + return response |
| 875 | + |
| 876 | + async def cycle_time_cohorts( |
| 877 | + self, |
| 878 | + state: Optional[str] = None, |
| 879 | + start_date: Optional[str] = None, |
| 880 | + end_date: Optional[str] = None, |
| 881 | + lat: Optional[float] = None, |
| 882 | + lng: Optional[float] = None, |
| 883 | + radius_miles: Optional[float] = None, |
| 884 | + group_by: Optional[str] = None, |
| 885 | + **params, |
| 886 | + ) -> Dict[str, Any]: |
| 887 | + filters = { |
| 888 | + "state": state, |
| 889 | + "start_date": start_date, |
| 890 | + "end_date": end_date, |
| 891 | + "lat": lat, |
| 892 | + "lng": lng, |
| 893 | + "radius_miles": radius_miles, |
| 894 | + "group_by": group_by, |
| 895 | + } |
| 896 | + params.update({k: v for k, v in filters.items() if v is not None}) |
| 897 | + response = await self.client.request( |
| 898 | + method="GET", path="/v1/well-production/cycle-time/cohorts", params=params |
| 899 | + ) |
| 900 | + if "data" in response: |
| 901 | + return response["data"] |
| 902 | + return response |
| 903 | + |
| 904 | + |
776 | 905 | # EI sub-resources |
777 | 906 |
|
778 | 907 | class AsyncEIRigCountsResource: |
|
0 commit comments